Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • polystar/robomaster/controle/bsp
1 result
Show changes
Commits on Source (1)
  • Nathan Girard's avatar
    · 10054d4e
    Nathan Girard authored
    Ajout PWM
    10054d4e
#include "tim.h"
#include "bsp_pwm.h"
void PWM_init(void){
/* Open 4 sets of PWM waves respectively */
/**TIM2 GPIO Configuration
PA8 ------> TIM2_CH1
PA9 ------> TIM2_CH2
PA10 ------> TIM2_CH3
PA11 ------> TIM2_CH4
*/
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_3);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_4);
}
void PWM_SetDuty(TIM_HandleTypeDef *tim,uint32_t tim_channel,float duty){
switch(tim_channel){
case TIM_CHANNEL_1: tim->Instance->CCR1 = (PWM_RESOLUTION*duty) - 1;break;
case TIM_CHANNEL_2: tim->Instance->CCR2 = (PWM_RESOLUTION*duty) - 1;break;
case TIM_CHANNEL_3: tim->Instance->CCR3 = (PWM_RESOLUTION*duty) - 1;break;
case TIM_CHANNEL_4: tim->Instance->CCR4 = (PWM_RESOLUTION*duty) - 1;break;
}
}
#ifndef __BSP_PWM
#define __BSP_PWM
#include "main.h"
void PWM_SetDuty(TIM_HandleTypeDef *tim,uint32_t tim_channel,float duty);
void PWM_init(void);
#endif