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
How to change PWM frequency or duty cycle.
Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess
- 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.
I already enable, No anything else.
mculover
Code: Select all
#define USE_STM32_PWM1 FALSE
#define USE_STM32_PWM2 FALSE
#define USE_STM32_PWM3 FALSE
#define USE_STM32_PWM4 TRUE
mculover
- 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.
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
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.
Hi Giovanni,
I use call back to debug PWM4.
New PWMConfig
and function
On test, I receive continuous 'A' from USART.
But no PWM signal...
mculover
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
- 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.
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
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.
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
- 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.
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
Version 2.1.x are not affected.
ciao,
Giovanni
Who is online
Users browsing this forum: No registered users and 9 guests