Hello,
I am having some problem with generating 2 PWM. I have one working just fine and would like to get another one (not necessarily synchronized) at the same time. The output of my first pwm on port B6 is good, but my second pwm output on port B7 is just noise.
I’m pretty sure I’m missing something since I’m new in µC programming…
Thanks for letting me know what’s wrong here:
void pwm0_init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB6_M0PWM0);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
}
void pwm1_init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB7_M0PWM1);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);
PWMGenConfigure(PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
}
void pwm0_start(unsigned long frequence, unsigned long duty_cycle)
{
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ROM_SysCtlClockGet() / frequence);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, (PWMGenPeriodGet(PWM0_BASE, PWM_OUT_0) * duty_cycle) / 100);
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}
void pwm1_start(unsigned long frequence, unsigned long duty_cycle)
{
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, ROM_SysCtlClockGet() / frequence);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_0, (PWMGenPeriodGet(PWM1_BASE, PWM_OUT_0) * duty_cycle) / 100);
PWMOutputState(PWM1_BASE, PWM_OUT_0_BIT, true);
PWMGenEnable(PWM1_BASE, PWM_GEN_1);
}
Thank you for your answers,
Florent