How to change PWM frequency or duty cycle.

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: How to change PWM frequency or duty cycle.

Postby Giovanni » Thu Jan 06, 2011 4:57 pm

The code should work regardless the STM32 model.

Anyway, I think I understood what happened, PWM4 is not enabled in mcuconf.h and because a small bug that code compiles without errors. Just enable the driver in the configuration file and everything should be fine.

I will open the bug on the tracker.

Giovanni

mculover
Posts: 26
Joined: Fri Dec 10, 2010 2:27 pm

Re: How to change PWM frequency or duty cycle.

Postby mculover » Thu Jan 06, 2011 5:57 pm

I already enable, No anything else.

Code: Select all

#define USE_STM32_PWM1              FALSE
#define USE_STM32_PWM2              FALSE
#define USE_STM32_PWM3              FALSE
#define USE_STM32_PWM4              TRUE



mculover

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: How to change PWM frequency or duty cycle.

Postby Giovanni » Thu Jan 06, 2011 6:34 pm

I tested also on an STM32F103RB, the driver works.

Is it possible that on your board PB6 and PB7 are driven by some external component? those pins are shared with the CAN_RX and CAN_TX pins so there could be the CAN bus driver attached there.
If so then try to use channels 0 and 1 instead of 2 and 3.

Giovanni

mculover
Posts: 26
Joined: Fri Dec 10, 2010 2:27 pm

Re: How to change PWM frequency or duty cycle.

Postby mculover » Sun Jan 09, 2011 2:46 pm

Hi Giovanni,

I use call back to debug PWM4.

New PWMConfig

Code: Select all

static PWMConfig pwmcfg = {
pwmpcb,
{
{PWM_OUTPUT_ACTIVE_HIGH, NULL},   // CH1
{PWM_OUTPUT_ACTIVE_HIGH, NULL},   // CH2
{PWM_OUTPUT_ACTIVE_HIGH, NULL},   // CH3
{PWM_OUTPUT_ACTIVE_HIGH, NULL}   // CH4
},
PWM_COMPUTE_PSC(STM32_TIMCLK1, 10000),    // 10KHz PWM clock frequency.
PWM_COMPUTE_ARR(10000, 1000000),       // PWM period 0.1S (in nS).
0};


and function

Code: Select all

static void pwmpcb(PWMDriver *pwmp) {

  (void)pwmp;

  sdPut(&SD1, 'A');
}


On test, I receive continuous 'A' from USART.
But no PWM signal...
:(

mculover

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: How to change PWM frequency or duty cycle.

Postby Giovanni » Sun Jan 09, 2011 5:15 pm

Hi,

That means that the PWM driver is working and generatig the callbacks but the output is not there for some reason, I can think of:
- Output not set to alternate for some reason (you can inspect the AFIO/GPIO registers with the debugger).
- Measuring the wrong pin.
- Pin shortcut because external components.
- Defective chip.

I will try to make even more tests with the driver but it already worked in my previous tests.

Just a note, you cannot use sdPut() or any other blocking call from callbacks or interrupt handlers, it would most likely crash the system after a while, when trying to block.

Giovanni

mculover
Posts: 26
Joined: Fri Dec 10, 2010 2:27 pm

Re: How to change PWM frequency or duty cycle.

Postby mculover » Mon Jan 10, 2011 9:49 am

Giovanni wrote:
Just a note, you cannot use sdPut() or any other blocking call from callbacks or interrupt handlers, it would most likely crash the system after a while, when trying to block.

Giovanni


Thanks you for suggestion.
mculover
:D

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: How to change PWM frequency or duty cycle.

Postby Giovanni » Mon Jan 10, 2011 5:11 pm

As I wrote in the PM, I found the problem, I will release a quick fix version 2.0.10 later today.

Version 2.1.x are not affected.

ciao,
Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 9 guests