Presentation is loading. Please wait.

Presentation is loading. Please wait.

MCO556 Timer System Exercise.

Similar presentations


Presentation on theme: "MCO556 Timer System Exercise."— Presentation transcript:

1 MCO556 Timer System Exercise

2 Timer System Exercise Using the HCS12 Timer System, generate a ~8 Hz overflow rate which will control the system loop timing. The Timer System must also be used to generate a 200 Hz square wave on PORT T pin 2. Calculate the Timer System parameters required to configure the system.

3 Timer System Diagram Prescaler Divide by 216 TOF in TFLG2 ~ 8 Hz
Bus Clock Fbus = 8 MHz Fct Fov DFF P TCNT Tcmp C2F in TFLG1 DFF Comparator PTT.2 Fsw = 200 Hz TC2 TFF

4 Prescale Calculation 1) Overflow rate is Fov = ~8 Hz
2) The TCNT counter divides its input clock (Fct) by 2^16 to generate Fov 3) TCNT clock frequency is Fct = 216 * Fov Fct = 2^16 * 8 Hz = ~ Hz 4) The 8 MHz Bus clock (Fbus) is divided by the prescaler (P) to generate Fct. Fbus / P = Fct P = Fbus / Fct P = 8MHz / Hz = 15.26 The nearest available prescale value is 16 = 24.

5 Actual TCNT Clock Tct = 1 / 0.5 MHz = 2 us
1) When using the prescale value of 16, the clock rate into the TCNT counter is Fct = Fbus / P Fct = 8 Mhz / 16 = 0.5 MHz 2) Clock period is Tct = 1 / Fct Tct = 1 / 0.5 MHz = 2 us

6 Compare Event Timing 1) Port T.2 generates a 200 Hz square wave. This requires using Timer channel 2 in Output Compare mode. 2) Square Wave period is Tsw = 1/ Fsw Tsw = 1 / 200 Hz = 5 ms 3) The compare period (Tcmp) is half the square wave period. Tcmp = 0.5 * 5 ms = 2.5 ms

7 Compare Event Interval
1) The Output Compare event occurs every 2.5 ms. This is equivalent to M cycles of the TCNT clock M = Tcmp / Tct M = 2.5 ms / 2 us = 1250

8 Timer Code #define PERIOD 1250
void TOC2open(void); // function prototype // initialization part of main TSCR1 = 0x80; // initialize the main Timer TSCR2 = 0x04; // prescale set to divide by 16 TOC2open(); // initialize Output Compare

9 Timer Channel Initialization
// output compare initialization for channel 2 void TOC2open(void) { TIOS |= 0x04; // output compare mode TCTL1 = 0; TCTL2 = 0x10; // toggle PTT.2 TIE |= 0x04; // enable interrupts TFLG1 = 0x04; // clear event TC2 = TCNT + PERIOD; }


Download ppt "MCO556 Timer System Exercise."

Similar presentations


Ads by Google