Add PWM control functionality

This commit is contained in:
2025-04-20 17:30:52 +02:00
parent 1a517299a0
commit 804bb33064
5 changed files with 104 additions and 12 deletions

View File

@ -127,10 +127,10 @@ void Error_Handler(void);
#define D6_GPIO_Port GPIOB
#define PWM2_1_Pin GPIO_PIN_5
#define PWM2_1_GPIO_Port GPIOB
#define PWM3_2_Pin GPIO_PIN_6
#define PWM3_1_Pin GPIO_PIN_6
#define PWM3_1_GPIO_Port GPIOB
#define PWM3_2_Pin GPIO_PIN_7
#define PWM3_2_GPIO_Port GPIOB
#define PWM3_2B7_Pin GPIO_PIN_7
#define PWM3_2B7_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */

View File

@ -2,8 +2,8 @@
#define MAPPINGS_H
// CHOOSE ONE, comment the other or comment both and use -D SN_FRONT
#define SN_FRONT
//#define SN_REAR
//#define SN_FRONT
#define SN_REAR
#include <stdint.h>
#include "main.h"
@ -171,6 +171,35 @@ static can_pkt_t CAN_SIGNAL_MAP[NUM_TX_PKT] = {
}
};
#define CAN_PWM_DC_ID 0x0DC
#define CAN_PWM_CONF_ID 0x0DD
#endif
/* user needs
TIM_HandleTypeDef* PWM_TIM_MAP[3] = {&htim1, &htim4, &htim3};
*/
typedef enum {
PWM1 = 0, // TIM1
PWM3 = 1, // TIM4
PWM2 = 2, // TIM3
} pwm_tim_t; // Used as index for PWM_TIM_MAP
typedef struct {
uint8_t tim;
uint8_t ch;
} pwm_ch_t;
static pwm_ch_t PWM_CH_MAP[8] = {
{ .tim = PWM1, .ch = 0 }, // TIM1_CH1
{ .tim = PWM1, .ch = 1 }, // TIM1_CH2
{ .tim = PWM1, .ch = 2 }, // TIM1_CH3
{ .tim = PWM1, .ch = 3 }, // TIM1_CH4
{ .tim = PWM3, .ch = 0 }, // TIM4_CH1
{ .tim = PWM3, .ch = 1 }, // TIM4_CH2
{ .tim = PWM2, .ch = 1 }, // TIM3_CH2
{ .tim = PWM2, .ch = 3 } // TIM3_CH4
};
#endif