/* * This program drives the speaker on the Wytec EduBase board * at 440 Hz using TPM0_CH4 in PWM mode. The speaker is connected * to PTC8. */ #include "MKL25Z4.H" int main (void) { SIM->SCGC5 |= 0x0800; /* enable clock to Port C */ PORTC->PCR[8] = 0x0300; /* PTC8 used by TPM0 */ SIM->SCGC6 |= 0x1000000u; /* enable clock to TPM0 */ SIM->SOPT2 |= 0x01000000; /* use MCGFLLCLK as timer counter clock */ TPM0->SC = 0; /* disable timer */ TPM0->CONTROLS[4].CnSC = 0x20 | 0x08; /* edge-aligned, pulse high */ TPM0->MOD = 5956; /* Set up modulo register for 440Hz */ TPM0->CONTROLS[4].CnV = 2978; /* Set up channel value for 50% dutycycle */ TPM0->SC = 0x0C; /* enable TPM0 with prescaler /16 */ while (1) { } }