Pulse Measurement CCP & ECCP both using single Timer
Posted: Thu Apr 24, 2025 1:46 pm
Hi Guys,
measuring a Pulse with a PIC. Using interrupts, Capture using CCP and ECCP and both use Timer 3.
My ISR reads the timer value accumalated between the interrupts.
Then resets both Timer 3 and the ECCP Timer register.
I can get either to work fine but not both.
I assume this is because, when one ISR resets Timer 3, it effects the count of the other.
So..Can I use a single Timer for counting two different periods from CCP and ECCP pins?
I expect to use other timers for other functions so dont want to waste timer resources if possible.
Any ideas? J.
measuring a Pulse with a PIC. Using interrupts, Capture using CCP and ECCP and both use Timer 3.
My ISR reads the timer value accumalated between the interrupts.
Then resets both Timer 3 and the ECCP Timer register.
I can get either to work fine but not both.
I assume this is because, when one ISR resets Timer 3, it effects the count of the other.
So..Can I use a single Timer for counting two different periods from CCP and ECCP pins?
I expect to use other timers for other functions so dont want to waste timer resources if possible.
Code: Select all
// Enter C code below this comment
PIE2bits.ECCP1IE = 0; // Stop CCP1 interrupts, to avoid false counts.
FCV_PULSE2_TMRLO = ECCPR1L;
FCV_PULSE2_TMRHI = ECCPR1H; //Read CCP1 Timer Value, Hi and Lo Bytes
//TMR3H = 0;
//TMR3L = 0;
ECCPR1H = 0;
ECCPR1H = 0;
PIE2bits.ECCP1IE = 1; // ReEnable the ECCP1 interrupts