![Freescale Semiconductor QE128 Quick Reference User Manual Download Page 105](http://html1.mh-extra.com/html/freescale-semiconductor/qe128/qe128_quick-reference-user-manual_2330661105.webp)
Generating PWM Signals Using Timer/Pulse-Width Modulator (TPM) Module for the QE Microcontrollers
QE128 Quick Reference User Guide, Rev. 1.0
Freescale Semiconductor
12-3
This is the main function, above are the described called finctions, and all the interrupts are enabled. The
TPM interrupt can than be detected. Within the endless loop the PWM output value is displayed in the
PTE0.
void main(void) {
MCU_Init(); // Function that initializes the MCU
GPIO_Init(); // Function that initializes the Ports of the MCU
TPM_Init(); // Function that initializes the TPM module
EnableInterrupts; // enable interrupts
for(;;) {
PTED_PTED0 = PTBD_PTBD5; // PTB5 is the PWM output, so this output is
// display in the PTE0 (This is made only for didactic purposes)
} // loop forever
// please make sure that you never leave this function
}
NOTE
This is the TPM service routine. Every time a TPM interrupt is detected, the
PWM duty cycle is incremented by 1. When the value of the register reaches
0x00F0 the compare value is reset to one.
void interrupt VectorNumber_Vtpm1ch1 TPM_ISR(void) {
// TPM interrupt vector number = 5 (S08)
// TPM interrupt vector number = 67 (V1)
TPM1C1SC_CH1F; // Clear TPM flags
TPM1C1SC_CH1F = 0; // Two-step flag acknowledgement
if (TPM1C1V <= 0x00F0){ // If the maximum value of the duty cycle is not reached
+; // Increment de duty cycle by 1
PTED_PTED0 = PTBD_PTBD5; // PTB5 is the PWM output, so this output is display in the LED1
}
else {
TPM1C1V = 0x0001; // Reset the value of duty cycle to 1
}
}