| ??? 03/09/00 07:24 Read: times |
#1731 - RE: Timer 0 to get frequency |
Bill,
> Hello Peter, you really have a great webb site. Lots of good information. thank you. > The original routine came from Signitics app note AN426. I modified the code Where can I find AN426 ? > some but the requirement is the same; determine the freq. of an input signal; > in my case 5Hz to 14000Hz. The problem is that the timer values vary so much > that at 10000hz it may be 9940 or 10020. I'm using , timer 0. I If I understand the code right, you count only a single period. And you check the input with 2 jump instructions, which give you an inaccuracy of 4 cycles (= 4µs at 12MHz crystal). To get lower inaccuracy you must use an interrupt. E.g. activate an 1 to 0 transition interrupt and execute IDLE. So during idle the micro do nothing else, than waiting for interrupts. And so the interrupt was served after exact the same count of cycles on the 1. (to start T0) and the 2. (to stop T0) transition. This reduce the the inaccuracy down to 1 cycle (= 1µs). Please watch, that the T0 interrupt also leave IDLE. Solution: set a bit, only in your input signal interrupt and reenter IDLE as long as this bit was not set. Further increasing of accuracy can be done by counting more than only 1 period. This can be done with an external divider or timer T1 in the counter reload mode. E.g. load TH1 with -10 give you an interrupt every 10 periods. Since you want a wide input range, you should better use a variable preload value for high accuracy and short measuring time. E.g. f > 1000Hz: -100 100Hz > f <= 1000Hz: -10 f <= 100Hz: -1 Its simple to do it depending from the previous measuring. See also my DVM example: http://www.specs.de/~danni/appl/hard/dvm/dvm.htm Peter |
| Topic | Author | Date |
| Timer 0 to get frequency | 01/01/70 00:00 | |
| RE: Timer 0 to get frequency | 01/01/70 00:00 | |
RE: Timer 0 to get frequency | 01/01/70 00:00 |



