目录
配置
调试配置
时钟配置

定时器配置
预分频系数7200-1,自动重装载系数2000-1。
代码
steering.h
#ifndef __steering_H__
#define __steering_H__
void pwm_control_Steering(int a,float pwm);
void steering_init();
#endif
steering.c
#include "steering.h"
#include "tim.h"
float temp;
void steering_init(){
HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_3);
HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_4);
}
void pwm_control_Steering(int a,float pwm){
if(pwm>=0&&pwm<=180){
temp=pwm*200.0f/180.0f+50.0f;
if(a==1){
__HAL_TIM_SetCompare(&htim2, TIM_CHANNEL_1,(int)temp);
}
if(a==2){
__HAL_TIM_SetCompare(&htim2, TIM_CHANNEL_2,(int)temp);
}
if(a==3){
__HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3,(int)temp);
}
if(a==4){
__HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_4,(int)temp);
}
}
}