Page 2 of 2

Re: How to change PWM frequency or duty cycle.

Posted: Thu Jan 06, 2011 4:57 pm
by Giovanni
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

Re: How to change PWM frequency or duty cycle.

Posted: Thu Jan 06, 2011 5:57 pm
by mculover
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

Re: How to change PWM frequency or duty cycle.

Posted: Thu Jan 06, 2011 6:34 pm
by Giovanni
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

Re: How to change PWM frequency or duty cycle.

Posted: Sun Jan 09, 2011 2:46 pm
by mculover
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

Re: How to change PWM frequency or duty cycle.

Posted: Sun Jan 09, 2011 5:15 pm
by Giovanni
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

Re: How to change PWM frequency or duty cycle.

Posted: Mon Jan 10, 2011 9:49 am
by mculover
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

Re: How to change PWM frequency or duty cycle.

Posted: Mon Jan 10, 2011 5:11 pm
by Giovanni
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