STM32F4--How to start PWM12/TIM12? Topic is solved

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

Moderator: RoccoMarco

Post Reply
Sakamato
Posts: 3
Joined: Thu Jan 11, 2018 2:04 pm

STM32F4--How to start PWM12/TIM12?

Post by Sakamato »

Hi,

I'm trying to output PWM wave from a port using TIM12. Previously I succeeded in doing so on a port using TIM8, by the following code(or sth. like that):

Code: Select all

PWMConfig pwm8cfg = {
        100000,   /* 1MHz PWM clock frequency.   */
        1000,      /* Initial PWM period 1ms.       */
        NULL,
        {
                {PWM_OUTPUT_ACTIVE_HIGH, NULL},
                {PWM_OUTPUT_ACTIVE_HIGH, NULL},
                {PWM_OUTPUT_ACTIVE_HIGH, NULL},
                {PWM_OUTPUT_ACTIVE_HIGH, NULL}
        },
        0,
        0
};

pwmStart(&PWMD8,&pwm8cfg);
pwmEnableChannel(&PWMD8, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD8, 1100));


But I got trouble when trying to achieve the goal by replacing all PWMD8 with PWMD12, and pwm8cfg with pwm12cfg(which disabled the 3rd and 4th channel, nothing else changed).

Btw: I added this in the pwm_lld.h file:

Code: Select all

#if STM32_PWM_USE_TIM12 && !defined(__DOXYGEN__)
extern PWMDriver PWMD12;
#endif

since there's smilar code for other pwm drivers above.

Note: the graph on the oscilloscope of the output of PWM12 is like quite messy, at least not PWM waves.

Could you help me with it?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4--How to start PWM12/TIM12?

Post by Giovanni »

Hi,

Not all timers are supported in all drivers, the change you made is not sufficient, just look for the STM32_PWM_USE_TIMxx macros in pwm_lld.c and pwm_lld.h files, that will reveal all places where changes are necessary.

Giovanni
Sakamato
Posts: 3
Joined: Thu Jan 11, 2018 2:04 pm

Re: STM32F4--How to start PWM12/TIM12?

Post by Sakamato »

Giovanni wrote:Hi,

Not all timers are supported in all drivers, the change you made is not sufficient, just look for the STM32_PWM_USE_TIMxx macros in pwm_lld.c and pwm_lld.h files, that will reveal all places where changes are necessary.

Giovanni


Thanks for the reply but I still don't know what to configure. The code in pwm_lld.c seems to support TIM12 as other timers, and the code in pwm_lld.h relating to timers are mostly error handlers, after configuring them things didn't turn out to be better.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4--How to start PWM12/TIM12?

Post by Giovanni »

Hi,

Sakamato wrote:Thanks for the reply but I still don't know what to configure. The code in pwm_lld.c seems to support TIM12 as other timers, and the code in pwm_lld.h relating to timers are mostly error handlers, after configuring them things didn't turn out to be better.


It is not matter of configuring the driver, the driver supports only timers 1, 2, 3, 4, 5, 8 and 9. You need to add code to support TIM12.

I don't know what you changed in the driver nor how you are testing the changes so I am not in position to tell you what it wrong.

Giovanni
robert_o
Posts: 53
Joined: Fri Feb 17, 2017 11:25 pm
Has thanked: 1 time
Been thanked: 6 times

Re: STM32F4--How to start PWM12/TIM12?

Post by robert_o »

You could check out my project. http://www.chibios.com/forum/viewtopic.php?f=8&t=4341.
I added TIM14 PWM. You can take a look what i changed.
best regards, Robert
Sakamato
Posts: 3
Joined: Thu Jan 11, 2018 2:04 pm

Re: STM32F4--How to start PWM12/TIM12?

Post by Sakamato »

Giovanni wrote:Hi,

Sakamato wrote:Thanks for the reply but I still don't know what to configure. The code in pwm_lld.c seems to support TIM12 as other timers, and the code in pwm_lld.h relating to timers are mostly error handlers, after configuring them things didn't turn out to be better.


It is not matter of configuring the driver, the driver supports only timers 1, 2, 3, 4, 5, 8 and 9. You need to add code to support TIM12.

I don't know what you changed in the driver nor how you are testing the changes so I am not in position to tell you what it wrong.

Giovanni


Oh, I figured it out by adding the code, thanks.
Post Reply