| ??? 03/08/00 19:50 Read: times |
#1726 - RE: Timer 0 to get frequency |
Hi Bill,
Your program works OK but measure method is not enough precise. The problem is that you make loop in 5 machine cycles (2.5 us for 24 MHz oscillator) when you wait the start and end of the measure period. So theoretically you can get error in 5 us for measure 10 kHz (100 us period) or 5 percents. You got (10140-9896)*100/10000 = 2.5 percents. Good result! What did you wish else? Well to solve problem you can use several periods of the signal to reduce measure error like in AN426.PDF. Be careful, I have just now seen AN426 and found out logical mistake there. Instead of using this fragment ORG 00000H SJMP START ;RESET VECTOR ORG 0000BH ;TIMER/COUNTER INTERRUPT ROUTINE TIMER0: INC R3 ;INCREMENT R3 (3rd BYTE OF TIMER) MOV A,#008H ;TEST FOR TIME OUT (R3 > 08) SUBB A,R3 ;IF R3 > 08, CARRY IS SET RETI you can use following (for several periods) TIMER0: DJNZ R3,NOEND CLR TR0 NOEND: RETI Don't forget remainder in TH0 & TL0. I hope it helps you a little. Please email me the result. Bye, George |
| 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 |



