i figured out how to enable PWM with TIM4 and the LED-Pins but i cannot find examples for using TIM1.
Iam using chibios 2.4.2
MOT1_PWM is a define for 9 (so PE9) and MOT2_PWM for 11 ( PE11)
the other stuff shouldn't matter.
according to the datasheet i need to set PAL_MODE_ALTERNATE to AF1 to get TIM1_CH1 and TIM1_CH2 working.
This is what i have so far. I know that dutyCycle is commented out, i have set it manually a few lines above and it is correct.
Don't have any PWM output on PE9 or PE11. Same code worked with TIM4 and the onboard LEDs. Everything is okay according to the datasheet?!
Code: Select all
*snip*
#define HAL_USE_PWM TRUE
*snip*
/*
* PWM driver system settings.
*/
#define STM32_PWM_USE_ADVANCED TRUE
#define STM32_PWM_USE_TIM1 TRUE
#define STM32_PWM_USE_TIM2 FALSE
#define STM32_PWM_USE_TIM3 FALSE
#define STM32_PWM_USE_TIM4 FALSE
#define STM32_PWM_USE_TIM5 FALSE
#define STM32_PWM_USE_TIM8 FALSE
#define STM32_PWM_TIM1_IRQ_PRIORITY 7
#define STM32_PWM_TIM2_IRQ_PRIORITY 7
#define STM32_PWM_TIM3_IRQ_PRIORITY 7
#define STM32_PWM_TIM4_IRQ_PRIORITY 7
#define STM32_PWM_TIM5_IRQ_PRIORITY 7
#define STM32_PWM_TIM8_IRQ_PRIORITY 7
*snip*
Code: Select all
static PWMConfig pwmcfgHardwareAbstraction = {
8000000, /* 8Mhz PWM clock frequency. */
US2ST(20), /* PWM period 20us */
NULL, /* Callback function */
{
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, // channel 1
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, // channel 2
{PWM_OUTPUT_DISABLED, NULL}, // channel 3
{PWM_OUTPUT_DISABLED, NULL} // channel 4
},
/* HW dependent part.*/
0
#ifdef STM32_PWM_USE_ADVANCED
,0 // only needed if STM32_PWM_USE_ADVANCED is defined
#endif
};
and
Code: Select all
/*
* Initializes the PWM driver 1, routes the TIM1 outputs to the motor bridge.
Alternate function mapping AF1 to set PE9 and PE11 to TIM1_CH1 and TIM1_CH2 output.
*/
pwmStart(&PWMD1, &pwmcfgHardwareAbstraction);
palSetPadMode(GPIOE, MOT1_PWM, PAL_MODE_ALTERNATE(1)); /* PE9 - MOT1_PWM */
palSetPadMode(GPIOE, MOT2_PWM, PAL_MODE_ALTERNATE(1)); /* PE11 - MOT2_PWM */
/*
Initializes the RNVN2 pins
*/
palSetPadMode(GPIOE, MOT1_IN1, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOE, MOT1_IN2, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOE, MOT2_IN1, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOE, MOT2_IN2, PAL_MODE_OUTPUT_PUSHPULL);
while (TRUE) {
/* Block the thread until we receive a message */
//PIDBalanceThread = chMsgWait();
//dutyCycle = (dutyCycleStruct*) chMsgGet(PIDBalanceThread);
setRNVN2Pins(dutyCycle->left, MOT1);
setRNVN2Pins(dutyCycle->right, MOT2);
pwmEnableChannelI(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, dutyCycle->left));
pwmEnableChannelI(&PWMD1, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, dutyCycle->right));
chThdSleepMilliseconds(500);
}