PIC极限应用

2020-02-09 09:30发布

在一个小项目里面,用PIC16F913来主控,用来记录N个脉冲的时间,时间精确到10us,看了下资料,晶振可以最高20M     20M/4分频可以到5M。但是看了下第定时器的中断,软件模拟了下,进中断和出中断就要3.XX个US,如果加上脉冲捕获进中断的时间,一起的误差会不会超出10US的范畴???(思路是:一边捕获脉冲。一边开个5US的定时器片,一直累加。当脉冲捕获到N值时,关定时器。看定时了多少个5US)  刚接错PIC,不知道这样可行不?高手路过,喵喵。。。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
26条回答
millwood0
2020-02-11 22:19
here is an example of how you would execute it.

the mcu in question is running on 4Mhz internal RC (1us timer clicks). it is measuring the pulse width of a 100Khz pulse train (5us pulse width) and storing the number of internal clock ticks during the time T1G has gone low into count.

in this case, count = 5 is the right answer.

because of phase differences between the incoming pulse and the clock, you may have 1 or up to 2 ticks' errors. so to be very accurate, you have to increase the internal clock speed.

the limitation here is the length of the pulse. as tmr1 is a 16-bit timer, the max pulse length is 64K clock ticks. you can solve that by having an interrupt on tmr1 overflow and use a software counter to make the timer a 48-bit timer (16-bit hardware timer + 32-bit software timer).



(原文件名:12F675 Gated TMR1.PNG)

the same concept can also be easily implemented on any mcu with a gated timer, like the 8051.

一周热门 更多>