完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
各位早上好。
我试图弄清楚如何定期切换给定频率的数字输出引脚。系统时钟配置内部振荡器,因此应为16 MHz。 我设置了一个预分频器为101的定时器,所以,如果我理解正确,它应该每100个旋钮计数1。 现在,例如,我试图切换一个20英寸的引脚。如果我理解正确,16 MHz,应该是每秒16000000个时钟周期。如果我每100计数1,那么计时器应该是每秒160000。 20毫秒是1/50秒,因此1600000/50 = 3200。 在我的代码中,我在无限循环中执行各种类型的操作。当我必须评估是否通过20毫秒时,我验证STM计数器。如果从之前传递3200计数,我改变输出。 实现的控件是这样的: ULONG ulNow = STM.CNT.R; ulElapsedtime = ulNow - ulWaveTimer; if(ulElapsedTime> = 3200) /* 时间飞逝。更改输出和重置计时器。 * / 事实是,似乎从一个检查和其他检查通过了太多的时钟周期,所以获得的频率不是我想要的,而是更少。 是否有更智能的方法来实现以所需频率变化的输出? 我编写的C代码和编译后获得的机器指令数之间有一些固定的关系吗? 谢谢, 伊万 #时钟周期定时器 以上来自于谷歌翻译 以下为原文 Good morning to everyone. I am trying to figure out how to toggle periodically a digital output pin with a given frequency. The system clock is configure the internal oscillator, so it should be 16 MHz. I set a timer with a prescaler of 101, so, if I understand correctly, it should count 1 every 100 cock tick. Now, for example, I am trying to toggle a pin evry 20 ms. If I understand correctly, 16 MHz, should be 16000000 clock cycles per second. If I count 1 every 100, the timer should be 160000 every second. 20 ms is 1/50 seconds, so 1600000/50 = 3200. In my code, I execute various type of operation in an infinite cycle. When I have to evaluate if 20 ms are passed, I verify the STM counter. If 3200 counts are passed from before, I change the output. The control implemented is something like this: ULONG ulNow = STM.CNT.R; ulElapsedTime = ulNow - ulWaveTimer; if (ulElapsedTime >= 3200) /* Time passed. Change output and reset timers. */ The fact is that It seems that from one check and the others pass too many clock cycles, so the frequency obtained is not what I desire, but less. Is there a more smart way to implement an output that change with a desired frequency? There is some fixed relation between the C code I write and the number of machine instructions that I obtain after compilation? Thank you, Ivan #clock-cycles-timer |
|
相关推荐
5个回答
|
|
你好伊万,
对不起,我迟到了。 你解决了问题吗? 你用的是哪种设备? 关于STM,如果你使用EL, 以所需频率实现输出的智能方法是更改CMP寄存器 CMP以hexa设置为3200 比较通道n的值。如果STM_CCRn [CEN]位置1且STM_CMPn寄存器匹配 在STM_CNT寄存器中,产生一个通道中断请求,并且STM_CIRn [CIF]位置1。 并处理相关的矢量编号 30 0x01E0 16匹配通道0 STM_0 STM_1 31 0x01F0 16在通道1 STM_0 STM_1上匹配 32 0x0200 16匹配通道2 STM_0 STM_1 33 0x0210 16在通道3 STM_0 STM_1上匹配 最好的祝福 二万 以上来自于谷歌翻译 以下为原文 Hello Ivan , Sorry , for my late answer. Have you solved your issue ? Which device do you use ? About STM, if you use EL, The smart way to implement an output at the desired frequency is to change the CMP register CMP set to 3200 in hexa Compare value for channel n. If the STM_CCRn[CEN] bit is set and the STM_CMPn register matches the STM_CNT register, a channel interrupt request is generated and the STM_CIRn[CIF] bit is set. and handle the associated vector number 30 0x01E0 16 Match on channel 0 STM_0 STM_1 31 0x01F0 16 Match on channel 1 STM_0 STM_1 32 0x0200 16 Match on channel 2 STM_0 STM_1 33 0x0210 16 Match on channel 3 STM_0 STM_1 Best regards Erwan |
|
|
|
你好,Erwan,
最后,我解决了在主循环中多次调用我的函数的问题。问题是我通过显示器管理引起的微观和强制等待完成了一些复杂的计算。 有多个调用可确保在定时器匹配某个值时捕获,因此相应地更改输出引脚值。 我还发现我可以使用FlexPWM生成具有所需特征的波。 感谢你的回答。我会尝试你的解决方案,并决定什么是我工作的应用程序的最佳选择。 以上来自于谷歌翻译 以下为原文 Hello Erwan, In the end I solved calling my function multiple times in a main cycle. The problem was that I had some complex calculations done by the micro and forced waits caused by the management of a display. Having multiple calls ensures that I catch when the timer matches a certain value and so change the output pin value accordingly. I also discovered that I can use the FlexPWM to generate waves with desired characteristics. Thanks for the answer. I will try your solution and decide what is best for the application on which I am working. |
|
|
|
你好伊万
我建议你使用MCO主时钟输出 https://stm32f4-discovery.net/2014/10/library-40-output-clocks-stm32f4/ https://stackoverflow.com/questions/46139283/stm32-output-mco-configuration https://community.st.com/0D50X00009XkXbeSAF 注意:原始帖子包含大量线程对话,只能迁移到第9级 以上来自于谷歌翻译 以下为原文 hallo ivan i recomendet to you to use the MCO master clock output https://stm32f4-discovery.net/2014/10/library-40-output-clocks-stm32f4/ https://stackoverflow.com/questions/46139283/stm32-output-mco-configuration https://community.st.com/0D50X00009XkXbeSAF Note: the original post contained a large number of threaded conversations and was only able to be migrated to the 9th level |
|
|
|
|
|
|
|
是的,它是SPC5系列
所有文件都在这里: http://www.st.com/en/automotive-microcontrollers/spc56el70l5.html 最好的祝福 Erwab 以上来自于谷歌翻译 以下为原文 Yes , it is SPC5 Family All the documents are located here : http://www.st.com/en/automotive-microcontrollers/spc56el70l5.html Best regards Erwab |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2725 浏览 1 评论
3237 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1807 浏览 1 评论
3646 浏览 6 评论
6034 浏览 21 评论
1337浏览 4评论
197浏览 3评论
对H747I-DISCO写程序时将CN2的st-link复用为usart1,再次烧录时无法检测到stlink怎么解决?
350浏览 2评论
STM32G474RE芯片只是串口发个数据就发烫严重是怎么回事?
442浏览 2评论
STM32处理增量式编码器Z信号如何判断中断是正转的还是反向转的?
273浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 21:22 , Processed in 1.262321 second(s), Total 85, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号