Page 1 of 1

PWM Clock and Period

Posted: Fri Jun 03, 2011 10:00 am
by Microman171
Hey,

I've managed to get serial and the like working with ChibiOS on my STM32103. Next on the list is PWM, and I am stuck again.

Looking at the example, there is a macro "PWM_COMPUTE_PSC(STM32_TIMCLK1, 10000)". I can not find this documented, which makes me think it might be a deprecated method of working out the PWM clock.

My hardware oscillator is at 8MHz, making the system clock 72MHz after the prescaler with the default options. Apart from that, I have no idea what the frequency of the clock on Timer2 is. This will be used to control an ESC, so I need a 20ms period and a 1 - 2ms duty cycle.

I have definitely got the PWM working, as I am watching the output on the scope.


Cheers,

MM

Re: PWM Clock and Period

Posted: Fri Jun 03, 2011 10:20 am
by Giovanni
Hi,

That macro is not deprecated in 2.2.x, it has been removed in 2.3.x because the configuration structure changed (it is simpler now).

It is a macro specific of the STM32 PWM implementation so you wont find it in the general documentation, you have to access the STM32 HAL Reference Manual of version 2.2.x.

Anyway this is the documentation snippet in the source code (remember what you read in the manuals is always also in the source):

Code: Select all

/**
 * @brief   PWM clock prescaler initialization utility.
 * @note    The real clock value is rounded to the lower valid value, please
 *          make sure that the source clock frequency is a multiple of the
 *          requested PWM clock frequency.
 * @note    The calculated value must fit into an unsigned 16 bits integer.
 *
 * @param[in] clksrc    clock source frequency, depending on the target timer
 *                      cell it can be one of:
 *                      - STM32_TIMCLK1
 *                      - STM32_TIMCLK2
 *                      .
 *                      Please refer to the STM32 HAL driver documentation
 *                      and/or the STM32 Reference Manual for the right clock
 *                      source.
 * @param[in] pwmclk    PWM clock frequency in cycles
 * @return              The value to be stored in the @p pc_psc field of the
 *                      @p PWMConfig structure.
 */


STM32_TIMCLK1 must be used for timers 2, 3, 4, 5, 6, 7, 12, 13, 14 else STM32_TIMCLK2.

Giovanni

Re: PWM Clock and Period

Posted: Fri Jun 03, 2011 11:19 pm
by Microman171
Hey Giovanni,

Thank you very much for the help. By showing me where to find the macros, I was able to get exactly what I wanted!


Cheers,

MM