First page Back Continue Last page Graphics
Interrupt Service Routine (continued)
- //------------------------------------------------
- // do on last sample of a 60hz cycle ...
- //------------------------------------------------
- if (tick20Count >= 40)
- {
- //------------------------------------------------
- // compute & save filtered Vp-p value
- // lowpass filter Vp-p (average with prior average)
- // in an int array for current breaker number
- //
- // expect inputs centered upon ~512
- // 40 samples of 512 make an input metric of 20,480
- // metric must be at least HALF this or assume
- // there is no transducer board on this input
- //------------------------------------------------
- if (metric > 10000)
- AdcValues[breakerNumber] = (AdcValues[breakerNumber] + max_sample - min_sample)/2;
- else
- AdcValues[breakerNumber] = 0;
- //------------------------------------------------
- // toggle a digital output at end of 60hz cycle pair
- //------------------------------------------------
- LATB0 ^= 1;
- We already used tick20Count to determine if we’re in the 2nd 60Hz cycle for min/max determination.
- Here, we’ll test tick20Count again … when it’s reached 40 we’re done with this measurement. Everything within this conditional branch is to be performed on a completed sample.
- We accumulate A/D samples of an input in a variable named “metric”. If we’re selecting an interface address that doesn’t enable a physical interface module, then “metric” won’t have accumulated to an expected value of at least 20,480.
- If we don’t see at least 10,000, then zero out the value.
- Presuming “metric” is above minimum, AVERAGE the new measurement (max_sample – min_sample) with the prior AdcValue. Averaging is simply a low pass filter to smooth out measurement fluctuation.
- LATB0 is toggled merely to observe the 60Hz interrupt service cycles on an unused PIC output for diagnostic purposes.