完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
tify;text-indent: 40px;">大家好,
我想使用TIM1及其PWM输入模式来获得STM8S003上测量信号的占空比和频率。但我对测量值存在不确定性。 代码片段 void initialization(){ //系统时钟: CLK_CKDIVR_HSIDIV = 3; // fMASTER = fHSI / 8 = 16/8 = 2MHz CLK_CKDIVR_CPUDIV = 0; // fCPU = fMASTER = 2 MHz CLK_PCKENR1_TIM1 = 1; //定时器1 TIM1_PSCRH = 0x00; TIM1_PSCRL = 0x01; // fTIM1 = fMASTER /(TIM1_PSCR + 1)= 1 MHz TIM1_CR1_UDIS = 0; TIM1_CR1_ARPE = 1; TIM1_IER_CC1IE = 1; TIM1_IER_CC2IE = 1; //值根据RM0016参考手册,p。设置。 169 PWM输入信号测量 - 程序 TIM1_CCMR1_CC1S = 1; TIM1_CCER1_CC1P = 0; TIM1_CCMR2_CC2S = 2; TIM1_CCER1_CC2P = 1; TIM1_SMCR_TS = 5; TIM1_SMCR_SMS = 4; TIM1_CCER1_CC1E = 1; TIM1_CCER1_CC2E = 1; TIM1_CR1_CEN = 1; //启动计时器 } @interrupt void PWM_vIsrHandleTimer1CaptureEvent(void)// irq12 { if(TIM1_SR1_UIF){ TIM1_SR1_UIF = 0; //永远不会发生 } if(TIM1_SR1_CC1IF){ TIM1_SR1_CC1IF = 0; //从TIM1_CCR1L读取应该这样做 dutyCycleInTicks =(TIM1_CCR1H 以下为原文 Hello all, I want to use TIM1 and its PWM input mode to obtain duty cycle and frequency of measured signal on STM8S003. But I have uncertainty about measured value. Snippets of code void initialization () { //System Clocks: CLK_CKDIVR_HSIDIV = 3; // fMASTER = fHSI / 8 = 16/8 = 2MHz CLK_CKDIVR_CPUDIV = 0; // fCPU = fMASTER = 2 MHz CLK_PCKENR1_TIM1 = 1; //Timer1 TIM1_PSCRH = 0x00; TIM1_PSCRL = 0x01; // fTIM1 = fMASTER / (TIM1_PSCR + 1) = 1 MHz TIM1_CR1_UDIS = 0; TIM1_CR1_ARPE = 1; TIM1_IER_CC1IE = 1; TIM1_IER_CC2IE = 1; // Values are set according to RM0016 Reference manual, p. 169 PWM input signal measurement - Procedure TIM1_CCMR1_CC1S = 1; TIM1_CCER1_CC1P = 0; TIM1_CCMR2_CC2S = 2; TIM1_CCER1_CC2P = 1; TIM1_SMCR_TS = 5; TIM1_SMCR_SMS = 4; TIM1_CCER1_CC1E = 1; TIM1_CCER1_CC2E = 1; TIM1_CR1_CEN = 1; //start The Timer } @interrupt void PWM_vIsrHandleTimer1CaptureEvent(void) // irq12 { if(TIM1_SR1_UIF) { TIM1_SR1_UIF = 0; // never occur } if(TIM1_SR1_CC1IF) { TIM1_SR1_CC1IF = 0; // read from TIM1_CCR1L should do this dutyCycleInTicks = (TIM1_CCR1H << 8) & 0xFF00; dutyCycleInTicks |= (TIM1_CCR1L & 0xFF); } if(TIM1_SR1_CC2IF) { TIM1_SR1_CC2IF = 0; periodInTicks = (TIM1_CCR2H << 8) & 0xFF00; periodInTicks |= (TIM1_CCR2L & 0xFF); } Is it sufficient to use only this functions (+enable interrupt and etc) or something I am missing in work with Timers (reseting counter or?). Problem is why values are not related to input clock to TIM1. If I change TIM1_PSCRx prescaler or CLK_CKDIVR_HSIDIV (input clock to Tim1 peripheral), measured numbers are stilt the same. Generated PWM attached to TIM1_CH1 pin can vary in frequency, but value of TIM1_CCR1 is still same (4000), and TIM1_CCR2 is OK - change depends on duty cycle (for 50% it is 2000)... What am I missing? Thanks, Regards #pwm-stm8 |
|
相关推荐
1个回答
|
|
这个问题有什么联系吗?
https://my.st.com/public/STe2ecommunities/mcu/Lists/stm81/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fstm81%2FSTM8S003%20BUG%20IN%20TIMER(not%20confirmed)& ; FolderCTID = 0x01200200770978C69A1141439FE559EB459D7580001E3853D9DB932A46A3FE4CD15CAB46FB&安培; currentviews = 86 以上来自于谷歌翻译 以下为原文 Is there any connection to this issue? https://my.st.com/public/STe2ecommunities/mcu/Lists/stm81/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fstm81%2FSTM8S003%20BUG%20IN%20TIMER(not%20confirmed)&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580001E3853D9DB932A46A3FE4CD15CAB46FB¤tviews=86 |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2655 浏览 1 评论
3216 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1790 浏览 1 评论
3619 浏览 6 评论
5997 浏览 21 评论
946浏览 4评论
1319浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
591浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1309浏览 3评论
1369浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-30 00:49 , Processed in 1.402515 second(s), Total 75, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号