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

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

Moderators: barthess, RoccoMarco

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

STM32F4--How to start PWM12/TIM12?

Postby Sakamato » Wed Jan 17, 2018 1:54 pm

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: 10829
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 321 times
Been thanked: 269 times
Contact:

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

Postby Giovanni » Wed Jan 17, 2018 1:57 pm

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?

Postby Sakamato » Fri Jan 19, 2018 9:14 am

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: 10829
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 321 times
Been thanked: 269 times
Contact:

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

Postby Giovanni » Fri Jan 19, 2018 10:25 am

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: 35
Joined: Fri Feb 17, 2017 11:25 pm
Has thanked: 1 time
Been thanked: 4 times

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

Postby robert_o » Sat Jan 20, 2018 9:56 pm

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?

Postby Sakamato » Thu Jan 25, 2018 9:12 am

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.


Return to “STM32 Support”

Who is online

Users browsing this forum: Google [Bot] and 3 guests