Page 1 of 1

STM32F4--How to start PWM12/TIM12?

Posted: Wed Jan 17, 2018 1:54 pm
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?

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

Posted: Wed Jan 17, 2018 1:57 pm
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

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

Posted: Fri Jan 19, 2018 9:14 am
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.

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

Posted: Fri Jan 19, 2018 10:25 am
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

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

Posted: Sat Jan 20, 2018 9:56 pm
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

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

Posted: Thu Jan 25, 2018 9:12 am
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.