how to write pwm logic for MC9S08PA4 microcontroller.i want to control led driver dim pin intensity using this microcontroller..if any sample code is available for this
You can use the following code to set the FTM2 (I use the pt60 )
FTM2_MOD = 8000; // PWM frequency is about 1 KHz8000
// Configure channel 0 to PWM mode (center aligned high-true pulses)
FTM2_C0SC = FTM2_C0SC_ELSB_MASK | FTM2_C0SC_MSB_MASK;
FTM2_C0V = 4000; // channel 0 set to 50%
// FTM clock = BUSCLK = 8MHz, Overflow Interrupt Enabled,
FTM2_SC = FTM2_SC_CLKS0_MASK | FTM2_SC_TOIE_MASK;
interrupt VectorNumber_Vftm2ovf void FTM2ovfISR (void)
{
//Clear interrupt flag
(void)FTM2_SC;
FTM2_SC_TOF = 0;
counts--;
if (!counts)
{
if (!up_down) //up counting
{
FTM2_C0V += 80;
if (FTM2_C0V == 3920)
{
up_down = 1;
}
//when reaching 99%, change to down counting
}
else
{
FTM2_C0V -= 80;
if (FTM2_C0V == 80)
{
up_down = 0;
}
//when reaching 1%, change to up counting
}
counts = OVF_COUNTS;
}
PORT_PTGD_PTGD1 ^= 1;
}
I hope this will help you.
regards
Vicente Gomez