Skip to content
Snippets Groups Projects
Commit f7b093e3 authored by Baptiste Toussaint's avatar Baptiste Toussaint
Browse files

Pwm

parent 9e5e7748
No related branches found
No related tags found
No related merge requests found
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment