Pages

2011-05-05

Microchip PIC: Usting Timer 1 in Capture Mode

The hardware and software in this memo comprise an engine control monitor and alarm. The purpose is to monitor the tachometer signals from an engine. If the period pf the pulses drop below 1ms, the engine is running too fast and a red LED lights up for alarm.

We relies on the capture interrupt event to do all of the work. Following are the steps its is executing:
  • Read capture signal and store the result as end_time. CCP_I is a CCS PIC compiler variable that is provided as way to read the 16-bits capture register;
  • Using end_time a a previously stored beginning Timer 1 count (start_time), the actual period of was is calculated in timer ticks. The Timer 1 overflow interrupt value is used to account for any counter overflow that may have taken place during the measurement period. The calculation for the number of tick is:
Pulse_ticks = overflow_count*0x10000-start_time+end_time
  •  Comparing the actual pulse_ticks to 2500 to see if the engine is running too fast. The limit is when actual time of the waveform's periode is less than 1ms, inditcating a high engine spped problem. The 2500 limit was calculated this way:
1ms/(1/(4 MHz/4)) = 2500
  • Adjusting the output LED according to the current reading;
  • Finally, saving end_time for the current pulse as start_time for the newt pulse and clearing the overflow_count for the next pulse calculation.
Source code example:

No comments:

Post a Comment