Page 1 of 1

Can not get PWM working on STM32F303xx

Posted: Wed Aug 21, 2019 3:06 pm
by gclarkii
Greetings,

I must be brain dead... I can not seem to get PWM working on either the 303RE or 303K8 nucleo boards.
In both cases I copied the demo project, confirmed that the tests worked and then copied what I believe is the minimal amount of code from the PWM testhal projects.

Here is the two areas of code I copied,

static PWMConfig pwmcfg = {
100000, /* 10kHz PWM clock frequency. */
5000, /* Initial PWM period ??. */
NULL,
{
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_DISABLED, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_DISABLED, NULL}
},
0,
0
};

and
palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2));
pwmStart(&PWMD3, &pwmcfg);
pwmEnableChannel(&PWMD3, 3, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, 1000));

I've verified that I am using the proper pins for the timer/channel. I've changed freq, period, duty cycle, timer and channel.
I just get nothing out.

What am I forgetting?

Thanks

Re: Can not get PWM working on STM32F303xx

Posted: Wed Aug 21, 2019 4:07 pm
by Giovanni
The channel number:

Code: Select all

 * @param[in] channel   PWM channel identifier (0...channels-1)


Giovanni

Re: Can not get PWM working on STM32F303xx

Posted: Wed Aug 21, 2019 4:20 pm
by gclarkii
Not seeing the problem...

pwmEnableChannel(&PWMD3,  3, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, 5000));
This is the channel number, right?


I've tried turning on all channels in the config, and again, nothing.

Re: Can not get PWM working on STM32F303xx

Posted: Wed Aug 21, 2019 5:01 pm
by gclarkii
Thank you, got it working. Now I can't get it to go past about 800Khz. I would really like 4 or 6Mhz.

Re: Can not get PWM working on STM32F303xx

Posted: Wed Aug 21, 2019 6:33 pm
by Giovanni
Hi,

You need to select a frequency in the configuration structure that can be obtained using an integer division from the timer input clock and it should work.

Consider that the timer has a 16 bits prescaler, you need to select parameters compatible with the underlying HW and clock settings.

Make sure to enable assertions in chconf.h, those should catch invalid settings.

Giovanni