Can not get PWM working on STM32F303xx

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
gclarkii
Posts: 24
Joined: Wed Mar 01, 2017 7:38 pm
Has thanked: 1 time
Been thanked: 2 times

Can not get PWM working on STM32F303xx

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Can not get PWM working on STM32F303xx

Post by Giovanni »

The channel number:

Code: Select all

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


Giovanni
gclarkii
Posts: 24
Joined: Wed Mar 01, 2017 7:38 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Can not get PWM working on STM32F303xx

Post 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.
gclarkii
Posts: 24
Joined: Wed Mar 01, 2017 7:38 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Can not get PWM working on STM32F303xx

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Can not get PWM working on STM32F303xx

Post 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
Post Reply