Skip to content

Commit bdc9591

Browse files
committed
FEAT esp32 change the pwm rnage and stm32 driver speration header file
1 parent b7c7136 commit bdc9591

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

src/drivers/hardware_specific/esp32_driver_mcpwm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#define _MCPWM_FREQ 160e6f
1919

2020
// preferred pwm resolution default
21-
#define _PWM_RES_DEF 2048
21+
#define _PWM_RES_DEF 4096
2222
// min resolution
23-
#define _PWM_RES_MIN 1500
23+
#define _PWM_RES_MIN 3000
2424
// max resolution
25-
#define _PWM_RES_MAX 3000
25+
#define _PWM_RES_MAX 8000
2626
// pwm frequency
2727
#define _PWM_FREQUENCY 25000 // default
2828
#define _PWM_FREQUENCY_MAX 50000 // mqx

src/drivers/hardware_specific/stm32_mcu.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11

22
#include "../hardware_api.h"
3+
#include "stm32_mcu.h"
34

45
#if defined(_STM32_DEF_)
5-
// default pwm parameters
6-
#define _PWM_RESOLUTION 12 // 12bit
7-
#define _PWM_RANGE 4095.0 // 2^12 -1 = 4095
8-
#define _PWM_FREQUENCY 25000 // 25khz
9-
#define _PWM_FREQUENCY_MAX 50000 // 50khz
10-
11-
// 6pwm parameters
12-
#define _HARDWARE_6PWM 1
13-
#define _SOFTWARE_6PWM 0
14-
#define _ERROR_6PWM -1
15-
16-
17-
18-
typedef struct STM32DriverParams {
19-
HardwareTimer* timers[6];
20-
uint32_t channels[6];
21-
long pwm_frequency;
22-
float dead_zone;
23-
uint8_t interface_type;
24-
} STM32DriverParams;
25-
26-
27-
286

297

308
// setting pwm to hardware pin - instead analogWrite()
@@ -185,12 +163,10 @@ STM32DriverParams* _initHardware6PWMInterface(long PWM_freq, float dead_zone, in
185163
LL_TIM_OC_SetDeadTime(HT->getHandle()->Instance, dead_time); // deadtime is non linear!
186164
LL_TIM_CC_EnableChannel(HT->getHandle()->Instance, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH1N | LL_TIM_CHANNEL_CH2 | LL_TIM_CHANNEL_CH2N | LL_TIM_CHANNEL_CH3 | LL_TIM_CHANNEL_CH3N);
187165

188-
// Set Trigger out for DMA transfer
189-
LL_TIM_SetTriggerOutput(HT->getHandle()->Instance, LL_TIM_TRGO_UPDATE);
190-
191166
HT->pause();
192167
HT->refresh();
193168

169+
// maybe should be removed I am not sure if its necessary for BG431
194170
// adjust the initial timer state such that the trigger for DMA transfer aligns with the pwm peaks instead of throughs.
195171
HT->getHandle()->Instance->CR1 |= TIM_CR1_DIR;
196172
HT->getHandle()->Instance->CNT = TIM1->ARR;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef STM32_DRIVER_MCU_DEF
2+
#define STM32_DRIVER_MCU_DEF
3+
#include "../hardware_api.h"
4+
5+
#if defined(_STM32_DEF_)
6+
7+
// default pwm parameters
8+
#define _PWM_RESOLUTION 12 // 12bit
9+
#define _PWM_RANGE 4095.0 // 2^12 -1 = 4095
10+
#define _PWM_FREQUENCY 25000 // 25khz
11+
#define _PWM_FREQUENCY_MAX 50000 // 50khz
12+
13+
// 6pwm parameters
14+
#define _HARDWARE_6PWM 1
15+
#define _SOFTWARE_6PWM 0
16+
#define _ERROR_6PWM -1
17+
18+
19+
typedef struct STM32DriverParams {
20+
HardwareTimer* timers[6] = {NULL};
21+
uint32_t channels[6];
22+
long pwm_frequency;
23+
float dead_zone;
24+
uint8_t interface_type;
25+
} STM32DriverParams;
26+
27+
#endif
28+
#endif

0 commit comments

Comments
 (0)