RoboDurden / Hoverboard-Firmware-Hack-Gen2.x

with different defines_2-x.h for different board layouts :-) Compiles with Keil version 6
GNU General Public License v3.0
73 stars 24 forks source link

Slave and Master 2.7 working. Buzzer on slave works and the slave is commanded by the master. #21

Closed WizzardDr closed 9 months ago

WizzardDr commented 9 months ago

I looked at the code to establish if the speed is mapped or if I get the full PWM resolution. It appears to be 1:1 which is good but I noticed HoverBoardGigaDevice/Src/bldc.c line 8 const int16_t pwm_res = 72000000 / 2 / PWM_FREQ; // = 2000 doesn't add up. It should say 2250 in the comment. Does this mean that the whole code should be running and clamping the speed an PWM values with a range of -1125 to 1125, rather than the -1000 to 1000?

RoboDurden commented 9 months ago

There is some uncertainty of the my mcu frequency. In older gd32f130 pdf it is 72 Mhz, in newer only 48 Mhz. The 2000 seem to relate to 64 Mhz. Indeed, the +-1250 end up in

timer_channel_output_pulse_value_config(TIMER_BLDC, TIMER_BLDC_CHANNEL_G, CLAMP(g + pwm_res / 2, 10, pwm_res-10));

Please simply check by changing to this in bldc:129

void SetPWM(int16_t setPwm)
{
    bldc_inputFilterPwm = MAP(CLAMP(setPwm, -1000, 1000),-1000, 1000, -1250, 1250);
}

First two rules: you do not ask questions - Tyler Durden :-)

RoboDurden commented 9 months ago

or

bldc_inputFilterPwm = CLAMP(1.25setPwm, -1250, 1250); // float int -> float (float)int = float float

WizzardDr commented 9 months ago

ATM I don't have the means to control the speed, so I am unable to test it for now.

Since "2000" came from math based on 48 Mhz and the top of the counter is actually directly defined from PWM_FREQ and 72 Mhz, in setup:266

timerBldc_paramter_struct.period                        = 72000000 / 2 / PWM_FREQ;

the top is indeed 2250.

I would rather keep the range of 2000 by PWM_FREQ to 18000 rather than mapping the value if and when I need to get 25% more power.

RoboDurden commented 9 months ago

Testing max speed is easy, will do so soon: speed = 3 * (ABS(( ((int32_t)steerCounter+100) % 400) - 200) - 100); 16 Khz is a standard somehow, and +-1000 also. But users always want max speed. First we need to confirm that 1250 indeed increases speed.