1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我配置timer1以允许我的代码每20mS运行一次有困难……我的主程序执行它的事情,然后检查PIR1、TMR1IF,等待Timer1到期……;按照Timer1所确定的,在20mS时间范围内循环;通过打开main_.bsf GPIO、PWM_BIT上的PWM输出开始;输出在bcf PIR1,TMR1IF;清除定时器1溢出标志bsf T1CON,TMR1ON;定时器使能调用a_子例程调用另一个调用和_a_.;等待20msframewait_20m***tfss PIR1,TMR1IF的结束;等待定时器1溢出标志goto wait_20msgoto main_loopI正在使用PICs内部振荡器,因此我想我可以设置定时器配置错误...;设置定时器1控制寄存器movlw b'00001000';u0xxxxxx:TMR1GE OFF: ux00xxxx:Prescaler 1:1;uxxx1xx:Enable LP振荡器;uxxxxxxxx1xx:Do Not Synchronise to External Clock;uxxxxxxxxxx0x:设置内部时钟(Fosc/4);uxxxxxxxxxxx0:Do No No Not启用Timer1 movwf T1CON;写到T1CON;设置Timer1 Timing Registers movlw 0x17;将定时器设置为20ms movwf TMR1H movlw 0xe4 movwf TMR1LI尚未确定TMR1H和TMR1L值应该是什么,虽然我只是将其连接到频率计上使其点亮,但我所能得到的是15Hz,即使我改变了这些价值,我也必须做一些愚蠢的事情。任何想法!
以上来自于百度翻译 以下为原文 I'm having trouble configuring Timer1 to allow my code to run every 20mS... My main program does its thing then inspects PIR1,TMR1IF to wait for Timer1 to expire..... ; This loops at a 20mS time-frame, as determined by Timer1 ; Start by turning the PWM output on main_loop bsf GPIO,PWM_BIT ;Output on bcf PIR1,TMR1IF ;Clear timer 1 overflow flag bsf T1CON,TMR1ON ;Timer enable call a_subroutine call another call and_a_third ; Wait for end of 20ms frame wait_20ms btfss PIR1,TMR1IF ;Wait timer 1 overflow flag goto wait_20ms goto main_loop I'm using the PICs internal oscillator, so I think I may have the Timer configuration wrong.... ;Set Timer 1 Control Register movlw b'00001000' ;u0xxxxxx : TMR1GE OFF : ;ux00xxxx : Prescaler 1:1 ;uxxx1xxx : Enable LP Oscillator ;uxxxx1xx : Do Not Synchronise to External Clock ;uxxxxx0x : Set internal clock (Fosc/4) ;uxxxxxx0 : Do Not Enable Timer1 movwf T1CON ;write to T1CON ;Set Timer 1 Timing Registers movlw 0x17 ;Set timer to 20ms movwf TMR1H movlw 0xe4 movwf TMR1L I have yet to determine what TMR1H and TMR1L values should be, thought I'd just hook it up to a frequency meter to get it spot-on, but all I can get is 15Hz, even when I change those values... I must be doing something daft.... any ideas ! |
|
相关推荐
5个回答
|
|
你用什么作为时钟源?您没有显示配置。你有一个LP外部振荡器选择为Time1。你的三个电话需要多长时间才能执行?这也将限制环路速度。
以上来自于百度翻译 以下为原文 What are you using as a clock source? You do not show your configuration. You have the LP external oscillator selected for TImer1. Also how long do your three calls require to execute? That will limit the loop speed also. |
|
|
|
我确实说过……“我用的是PICs内部振荡器,所以我认为我的定时器配置错了……”u CON._CP_OFF&_CPD_OFF&_WDT_OFF&_BODEN_OFF&_INTRC_OSC_NOCLKOUT&_MCLRE_OFFI,我想我可能对振荡器的选择和时钟源感到困惑…如果TMR1CS=0(Internal Osc,Fosc/4),那么我认为我不需要LP振荡器,至少这是Timer 1Block Diagram所建议的……我会关掉它,看看它是否有任何不同。子例程并不支持它,事实上我已经让他们尝试让这个20mS循环协同工作直截了当地
以上来自于百度翻译 以下为原文 I did say.... "I'm using the PICs internal oscillator, so I think I may have the Timer configuration wrong...." __CONFIG _CP_OFF & _CPD_OFF & _WDT_OFF & _BODEN_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF I think I may be being confused about the oscillator selection and the clock source.... If TMR1CS = 0 (Internal Osc, Fosc/4), then I don't think I need the LP oscillator, at least that's what the Timer 1 Block Diagram suggests.... I'll turn it off and see if it makes any difference. The subroutines don't hold it up, in fact I've REM'd them out to try to get this 20mS loop functioning correctly. |
|
|
|
每次通过主循环,在第一次之后,我都看不出你在哪里加载了定时器1寄存器,所以它在前一次溢出之后溢出65536计数。对于指令时钟=4MHz/4=1MHz,我得到:1MHz/65536=(大约)15.26Hz
以上来自于百度翻译 以下为原文 Hmmm... Each time through your main loop, after the first time, I don't see where you load the Timer 1 registers again, so it overflows 65536 counts after the previous overflow. With instruction clock = 4 MHz / 4 = 1 MHz, I get: 1 MHz / 65536 = (approximately) 15.26 Hz Regards, Dave |
|
|
|
啊,我从来没有意识到H寄存器会被计时器损坏。我也不知道定时器寄存器“时钟上升”到65535溢出。我已经将它们的预置移动到主回路,并计算出16位的预置为4MHz/4=1MHz100000(Hz)/50(Hz)=2000065536-20000=45536=B1E0H我的频率现在是49.3Hz-接近50Hz I nEDE,只是需要调整一下。谢谢你的洞察力…
以上来自于百度翻译 以下为原文 Ahhh - I never realised the H an L registers would be destroyed by the Timer working. Neither was I aware that the timer registers "clock up" to overflow at 65535. I have moved the presetting of them to the main loop, and calculated the 16-bit preset as 4MHz / 4 = 1 MHz 100000 (Hz)/ 50 (Hz) = 20000 65536 - 20000 = 45536 = B1E0H My frequency is now 49.3 Hz - getting close to the 50 Hz I need, just needs a tweak. Thanks for the insight ... |
|
|
|
注意,H和L寄存器是定时器。这就是计数。12F675是一个非常简单的芯片。有新的8引脚PICS的价格差不多,还有很多内置的外围设备,包括可以自动重装的计时器。
以上来自于百度翻译 以下为原文 Note, the H and L registers ARE the timer. That is what is counting. The 12F675 is a pretty simple chip. There are newer 8-pin PICs for about the same price with a lot more built-in peripherals, including timers which can self reload. |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
777浏览 1评论
666浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
595浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
676浏览 0评论
576浏览 0评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 03:02 , Processed in 1.460982 second(s), Total 86, Slave 70 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号