PDA

View Full Version : timing like a stopwatch



robertpeach
- 14th August 2009, 09:44
hey,

to measure the frequency of a digital source, i would use interupts for each drops or rise to measure each half wave, how would i create a timer that would basically work like a stop watch?

so the interupt sends the program to a part where the timer is. and the timer times between each half wave and then resets to measure the next half wave... etc

thanks

Melanie
- 14th August 2009, 09:49
If your interrupt is at Zero-Cross, then it simply jumps to any of your TIMER registers, reads the current value and resets it to Zero ready for the next period. You've a shed-load of Timers to chose from in most PICs, and which one you use (8 or 16-bit) will depend on the frequency of your measured wave. You will have a few uS error (the time taken to jump to the interrupt and read the clock) which can be mitigated by how good your coding is... PICs with PWM module also have CCP... this is called a CAPTURE COMPARE MODULE which again (depending on your wave period) could be a better bet than starting/stopping Timer Registers yourself. Read all about it in your PICs Datasheet.

robertpeach
- 14th August 2009, 10:51
i have looked at the CCP which you described, on the pic im using (18f2431) it does include it, however im needing to measure 3 phases all simultaneously. this ccp only provides one pin to work with, the RC2/CCP1, and since I have 3 phases needing 3 ccp pins i can't see this method working? unlesss you can put them all through one pin? however that seems a bit unlikely since there would be no specific rises or drops...

thanks for the reply

robertpeach
- 14th August 2009, 13:28
ok ive realised i can just use the motion feedback module to get what i need haha it does absolutely everything for me if i give it one command... :)