mirror of
https://github.com/rene-dev/stmbl.git
synced 2026-02-06 02:02:34 +08:00
use pwm res define
This commit is contained in:
@@ -7,8 +7,6 @@
|
||||
|
||||
#define DATABAUD 3000000 //baudrate used for communication
|
||||
|
||||
#define PWM_RES 4800
|
||||
|
||||
//data from f3 to f4
|
||||
#pragma pack(1)
|
||||
typedef struct {
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#define PWM_W TIM8->CCR1
|
||||
|
||||
#define PWM_DEADTIME 0
|
||||
#define PWM_RES 4800
|
||||
|
||||
//io board
|
||||
//#define USB_CONNECT_PIN GPIO_PIN_15
|
||||
//#define USB_CONNECT_PORT GPIOB
|
||||
|
||||
@@ -73,12 +73,12 @@ static void rt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst_
|
||||
|
||||
float udc = MAX(PIN(udc), 0.1);
|
||||
//convert voltages to PWM output compare values
|
||||
int32_t u = (int32_t)(CLAMP(PIN(u), 0.0, udc) / udc * 4800.0);
|
||||
int32_t v = (int32_t)(CLAMP(PIN(v), 0.0, udc) / udc * 4800.0);
|
||||
int32_t w = (int32_t)(CLAMP(PIN(w), 0.0, udc) / udc * 4800.0);
|
||||
int32_t u = (int32_t)(CLAMP(PIN(u), 0.0, udc) / udc * (float)(PWM_RES));
|
||||
int32_t v = (int32_t)(CLAMP(PIN(v), 0.0, udc) / udc * (float)(PWM_RES));
|
||||
int32_t w = (int32_t)(CLAMP(PIN(w), 0.0, udc) / udc * (float)(PWM_RES));
|
||||
//convert on and off times to PWM output compare values
|
||||
int32_t min_on = (int32_t)(4800.0 * 15000.0 * PIN(min_on) + 0.5);
|
||||
int32_t min_off = (int32_t)(4800.0 * 15000.0 * PIN(min_off) + 0.5);
|
||||
int32_t min_on = (int32_t)((float)(PWM_RES) * 15000.0 * PIN(min_on) + 0.5);
|
||||
int32_t min_off = (int32_t)((float)(PWM_RES) * 15000.0 * PIN(min_off) + 0.5);
|
||||
|
||||
if((u > 0 && u < min_on) || (v > 0 && v < min_on) || (w > 0 && w < min_on)) {
|
||||
u += min_on;
|
||||
@@ -86,20 +86,20 @@ static void rt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst_
|
||||
w += min_on;
|
||||
}
|
||||
|
||||
if((u > 4800 - min_off) || (v > 4800 - min_off) || (w > 4800 - min_off)) {
|
||||
if((u > PWM_RES - min_off) || (v > PWM_RES - min_off) || (w > PWM_RES - min_off)) {
|
||||
u -= min_off;
|
||||
v -= min_off;
|
||||
w -= min_off;
|
||||
}
|
||||
|
||||
#ifdef PWM_INVERT
|
||||
PWM_U = 4800 - CLAMP(u, 0, 4800 - min_off);
|
||||
PWM_V = 4800 - CLAMP(v, 0, 4800 - min_off);
|
||||
PWM_W = 4800 - CLAMP(w, 0, 4800 - min_off);
|
||||
PWM_U = PWM_RES - CLAMP(u, 0, PWM_RES - min_off);
|
||||
PWM_V = PWM_RES - CLAMP(v, 0, PWM_RES - min_off);
|
||||
PWM_W = PWM_RES - CLAMP(w, 0, PWM_RES - min_off);
|
||||
#else
|
||||
PWM_U = CLAMP(u, 0, 4800 - min_off);
|
||||
PWM_V = CLAMP(v, 0, 4800 - min_off);
|
||||
PWM_W = CLAMP(w, 0, 4800 - min_off);
|
||||
PWM_U = CLAMP(u, 0, PWM_RES - min_off);
|
||||
PWM_V = CLAMP(v, 0, PWM_RES - min_off);
|
||||
PWM_W = CLAMP(w, 0, PWM_RES - min_off);
|
||||
#endif
|
||||
|
||||
#ifdef HV_EN_PIN
|
||||
|
||||
@@ -38,7 +38,7 @@ void MX_TIM8_Init(void) {
|
||||
htim8.Instance = TIM8;
|
||||
htim8.Init.Prescaler = 0;
|
||||
htim8.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED3;
|
||||
htim8.Init.Period = 4800;
|
||||
htim8.Init.Period = PWM_RES;
|
||||
htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
#ifdef PWM_INVERT
|
||||
htim8.Init.RepetitionCounter = 1;
|
||||
|
||||
Reference in New Issue
Block a user