MC9S08PA4VWJ

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC9S08PA4VWJ

371 Views
meghana_intern
Contributor I

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

Labels (1)
0 Kudos
1 Reply

281 Views
vicentegomez
NXP TechSupport
NXP TechSupport

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

0 Kudos