Darrel, in fact, the pulses will be coming from a sensor measuring Heart Rate, like an ECG signal, except that it will be run through a comparator so that I only pick-up the largest spike. Therefore, the signal will likely never have 50% duty cycle.
My plan is this...
1. Use Timer1 to count pulses (5,000 at 20MHz gives 1ms) starting at a pre-defined value, I think it works out to 60,535. In a tight loop I will check for the timer overflow bit, everytime this happens, I increment a variable as 1 ms and re-start the timer. This way I am counting milliseconds.
2. I will use RB0 as my interrupt signal (which is my pulse signal) and perform an interrupt routine that will calculate the heart rate based on the time (milliseconds from my variable above) between pulses. This routine will then reset my millisecond variable to check for the next time between pulses.
3. Another variable will check for 3 or 4 seconds to pass and then send the data via the built-in USART to a PC.
This is roughly how it should work. There are other issues that I need to look at, but that's easy. The hard part is keeping it accurate since at a heart rate of about 240 beats per minute (BPM), that's about 4 Hz, or 250ms between pulses. Therefore, in this range, a difference of 1 ms, is approximately 1 BPM. At lower heart rates, the resolution increases.
What do think??
BTW: I really appreciate the input so far.
Thanks,
Nick
Bookmarks