First page Back Continue Last page Graphics
Interrupt Service Routine (continued)
- //------------------------------------------------
- // keep the max & min samples during 2nd cycle
- //------------------------------------------------
- if (tick20Count >= 20)
- {
- if (Output > max_sample)
- max_sample = Output;
- if (Output < min_sample)
- min_sample = Output;
- }
- //------------------------------------------------
- // increment a count of 40 samples across
- // a pair of 60hz cycles (20 counts per cycle)
- // 20*1/1200 sec = 1/60 sec
- //------------------------------------------------
- tick20Count++;
- //------------------------------------------------
- // toggle a digital output each 60hz cycle
- //------------------------------------------------
- if (tick20Count == 20) LATB0 ^= 1;
- tick20Count is counting interrupts of each input. If we’re observing the 2nd 60 Hz cycle, observe (and save) max and min values of Output.
- Then, perform the actual increment of “tick20Count”
- LATB0 is toggled merely to observe the 60Hz interrupt service cycles on an unused PIC output for diagnostic purposes.