This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PWM generation

Hi all,

I am using TM4C1290 microcontroller for my one application and for it i want to generate PWM output to 1 - 50Khz.

I have set my system clock frequency to 60MHz. I have also generate 50khz from 6o mhz please find my code below.

Now, my problem is that when i want to generate 40Khz or other i have to set value in float otherwise it is not accurate but count could not be float.

So, Please provide suggestion.

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
ROM_PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_8);
ROM_GPIOPinConfigure(GPIO_PF0_M0PWM0);
ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);

//
// Configure the PWM generator for count down mode with immediate updates
// to the parameters.
//
ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

//
// Set the period. For a 4 KHz frequency, the period = 1/4000, or 0.25
// milliseconds. For a (60MHz/64) clock, this translates to 937.5 clock ticks.
// Use this value to set the period.
//
ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 150); //For 50KHz
//
// Set the pulse width of PWM0 for a 50% duty cycle.
//
ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 75);

//
// Start the timers in generator 0.
//
ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);

//
// Disable the outputs.
//
ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, false);