PWM config on STM32
Posted: Sun Jan 15, 2012 5:38 pm
Hi,
How to configure PWM driver on stm32 ?
I have tested the following code without success.
In halconf.h : HAL_USE_PWM TRUE
In mcuconf.h : STM32_PWM_USE_TIM2 TRUE
In my code
But no PWM ?
So how to properly configure and use PWM ?
Thanks
Cyrille
How to configure PWM driver on stm32 ?
I have tested the following code without success.
In halconf.h : HAL_USE_PWM TRUE
In mcuconf.h : STM32_PWM_USE_TIM2 TRUE
In my code
Code: Select all
//PWM
static PWMConfig pwmcfg = {
10000, /* Hz PWM clock frequency. */
US2ST(20), /* PWM period 20us. */
NULL,
{ {PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
{PWM_OUTPUT_ACTIVE_HIGH, NULL}
},
0,
0
};
...
//***********************************************//
// PWM Configuration //
//**********************************************//
pwmObjectInit(&PWMD2);
pwmStart(&PWMD2, &pwmcfg);
palSetPadMode(IOPORT1, 1, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(IOPORT1, 2, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(IOPORT1, 3, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(IOPORT2, 5, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
pwmEnableChannel(&PWMD2, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 5000));
pwmEnableChannel(&PWMD2, 1, 1000);
pwmEnableChannel(&PWMD2, 2, 1000);
pwmEnableChannel(&PWMD2, 3, 1000);
But no PWM ?
So how to properly configure and use PWM ?
Thanks
Cyrille