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
89 stars 29 forks source link

Gen2.4.2 (ex2.8.1) #59

Open AILIFE4798 opened 9 months ago

AILIFE4798 commented 9 months ago

IMG_20240201_215601 IMG_20240201_215624 MCU:MM32SPIN05PFOP(32K) Gate driver: uni u3116s Voltage:5V!!!

No optical sensors is on this board It is pin compatible with Layout 2.8

RoboDurden commented 9 months ago

Yes either test with 12V from master. Or if the slave has complete dcdc converter, try 3.3V on the Rx or tx line.

And do not test with the battery. Only 1-2 A constant current power supply. The original hoverboard charger also works.

AILIFE4798 commented 9 months ago

Sort of, while the motor does turn, there is a high pitch, loud, whine/buzz when attempting to move. How do you know if you need to invert the low side?

if the motor move at all you do not want to invert low side if you set it wrong it cause short circuit turning on low and high side mosfet

it is totaly normal to have high pitch noise that is from the pwm even with foc it will persist use the constspeed to make motor start up easier

AILIFE4798 commented 9 months ago

my board also have 12 v marked on the serial line, but its actually 13.8v acording to the buck converter datasheet the tx and rx line is 5v, but have a series resistor so you can connect it to esp directly

AILIFE4798 commented 9 months ago

Yes either test with 12V from master. Or if the slave has complete dcdc converter, try 3.3V on the Rx or tx line.

And do not test with the battery. Only 1-2 A constant current power supply. The original hoverboard charger also works.

mm32 board usualy come with 0.5a charger those wont work

RoboDurden commented 9 months ago

I do not remember a high frequency noise with the gd32f130 hoverboards.

AILIFE4798 commented 9 months ago

because gd pwm frequency is above audible range

RoboDurden commented 9 months ago
setup.c

timerBldc_paramter_struct.period = 72000000 / 2 / PWM_FREQ;

config.h:
#define PWM_FREQ 16000     // PWM frequency in Hz
AILIFE4798 commented 9 months ago

mine is half (4096)

GRROWL911 commented 9 months ago

@AILIFE4798 Just curious, millis++ is in void ADC1_COMP_IRQHandler(void) and in the void SysTick_Handler(void), was this on purpose? The reason I ask is if you set #define SYSCLK_FREQ_XXMHz 96000000, the and use a Delay_MS( 2000 ) it takes about 26 seconds, and I am trying to sort that out.

AILIFE4798 commented 9 months ago

yes idk why the systick is not accurate thats why millis++ is in adc handler because even with delay 1 my pid loop cannot react fast enough

AILIFE4798 commented 9 months ago

@GRROWL911 have you got serial working because someone else also have the layout2.8 cannot get serial to work

GRROWL911 commented 9 months ago

Have not looked at serial yet.

@GRROWL911 https://github.com/GRROWL911 have you got serial working

because someone else also have the layout2.8 cannot get serial to work

AILIFE4798 commented 9 months ago

he already have working serial now so your should also do

GRROWL911 commented 9 months ago

For the TaoTao 2130 version, have managed to completely stop the high pitch noise, the motor is nearly silent when running at about 100 rpm.

Changes:

//#define SYSCLK_HSI_24MHz 24000000 //#define SYSCLK_HSI_36MHz 36000000 //#define SYSCLK_HSI_48MHz 48000000 //#define SYSCLK_HSI_XXMHz 96000000 None of them work, when debugging the startup, you will find they all fail and revert to the default. Any HSI attempts simply hang. Board runs at about 8MHz, and SysTick is very close to accurate.

For smooth motor running on my board:

volatile u32 hall_sensors_time = 0; // in 10 us increments unsigned int get_hall_sensors_us (void) { return hall_sensors_time * 10; // multiply by 10 to get in us }

void updateMotorRPM() { rpm = USPerMinute / (get_hall_sensors_us() * WINDINGS); }

That's all that is working for now, no switch/hold, no adc, no uart, speed control untested, just wanted to get this smooth.

if the motor move at all you do not want to invert low side if you set it wrong it cause short circuit turning on low and high side mosfet

it is totaly normal to have high pitch noise that is from the pwm even with foc it will persist use the constspeed to make motor start up easier

GRROWL911 commented 9 months ago

Also changed:

    HALLTIM_Init(65535, 80); 

which gives 10 microsecond increments for the TIM2_IRQHandler increments which makes the rpm calculations correct.

use the constspeed to make motor start up easier

AILIFE4798 commented 9 months ago

TIM1_init(512, 0); is the one deciding the pwm frequency you trade resolution for frequency basicly i can add define to change the frequency

its good you got the systick to work correctly now ill be happy to implement fix to main

for me when hall commutation is handled in the tim2/3 irq handler the motor does not run smooth for some reason if you have made it work better ofcourse ill do it the way its supposed to

the reason hall timer is set up the way it is is because to prevent speed overflowing which idk how to solve so i just slow it down

finally a better programmer then me here helping with this mess i only gotten it working good enough and not perfect and already gone too ahead of my self trying foc i think i will have to wait for you to pull request because you can do it better

the other things ive all gotten to work ok adc works great but i may implement vcc wobble compensation self hold is too easy no way it can go wrong uart1 is working ok, only dma when receiving and not sending but handled in main loop anyways uart2 does not work for unknown reason latest firmware ive also got comparator working for emergency brake

AILIFE4798 commented 9 months ago

If you are going to create pr please reply so I'll not touch it from now

GRROWL911 commented 9 months ago

I have very little working, just the motor control. I cannot get the switch/hold working, nor ADC, have not tried the other parts, so I will not be posting anything until it works better. I also think my board and setup is enough different to yours that it will likely be another deviation. Also, I am a noob for ARM and a noob for GitHub, so I have no idea how to create a pr (what's a pr btw?). I was giving you my discoveries to help in your implementation.

If you are going to create pr please reply so I'll not touch it from now

RoboDurden commented 9 months ago

@GRROWL911 , it might help @AILIFE4798 if you fork his repo here (in order to contribute) and upload your changes to your fork. Then you can make a pr = pull request on your fork and AiLife will get a notification where he sees all your modifications in a nice list and can merge all your changes with a click on a button.

But AiLife can also first download your repo as a small zip file and quickly test your code with Keil.

AILIFE4798 commented 9 months ago

@GRROWL911 ok i will try to implement the fixes like you showed my self and test on my board if it worked better but in the future id imagine itll become more and more complicated a pr might still be required

if your switch and latch is not working it is hardware issue you traced the pin wrong(or the signal might be inverted) if you can upload high resolution picture with all the connector and capacitors blocking the tracks removed i can trace it for you

your adc does not work because it seems like your board is 3.3v and mine is 5v, you need to edit the VBAT_DIVIDER in pinout.h ive given formula to calculate it or you also traced the pins wrong because its not really trivial to trace these

AILIFE4798 commented 9 months ago

if you can please contact me on discord to discuss developement

GRROWL911 commented 9 months ago

The pin tracing is likely the problem. There are two voltage dividers that looked promising, however they may be for seeing the voltage going into the motor poles. The switch/hold ones still look correct, maybe they are inverted. @GRROWL911 ok i will try to implement the fixes like you showed my self and test on my board if it worked better but in the future id imagine itll become more and more complicated a pr might still be required if your switch and latch is not working it is hardware issue you traced the pin wrong(or the signal might be inverted) if you can upload high resolution picture with all the connector and capacitors blocking the tracks removed i can trace it for you your adc does not work because it seems like your board is 3.3v and mine is 5v, you need to edit the VBAT_DIVIDER in pinout.h ive given formula to calculate it or you also traced the pins wrong because its not really trivial to trace these

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

GRROWL911 commented 9 months ago

Newbie question, what is the discord? And how do I use it? if you can please contact me on discord to discuss developement

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

GRROWL911 commented 9 months ago

Will give it a try. @GRROWL911 , it might help @AILIFE4798 if you fork his repo here (in order to contribute) and upload your changes to your fork. Then you can make a pr = pull request on your fork and AiLife will get a notification where he sees all your modifications in a nice list and can merge all your changes with a click on a button. But AiLife can also first download your repo as a small zip file and quickly test your code with Keil.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

AILIFE4798 commented 9 months ago

the wire going to motor pole is not the current nor voltage those are phase current, on supported board its used to enable foc but your board is not capable of it so those are useless the vbat voltage divider is often near the battery connector but sometimes its not so i said its not trivial to trace if you do not know how this board works hardware side the currentDC is a thin track going to the current sens resistor the self hold most of the time is active high because of a reason when the board is switched off the ground is still connected so it will not float to activate the switch if its active low the board must switch the ground but that will interfere with the mosfet driver i will try your fixes later

AILIFE4798 commented 9 months ago

@GRROWL911 image

AILIFE4798 commented 9 months ago

u32 TIM_Pulse; ///< Specifies the pulse value to be loaded into the Capture Compare Register. so we should write 0 as it is the pwm value and we want default pwm to be disabled so the motor does not start uncontrollably

AILIFE4798 commented 9 months ago

as of the system clock, turns out im wrong the whole time, the example is using HSI the internal rc oscilator but it seems like the startup file is wrong because when debug i saw the code stuck at waiting for clock to finish configure so i changed it to HSE and it worked but thats because HSE is external oscilator and is not installed so the system is reverted back to LSI low speed internal rc oscilator image here is where the code stuck at and when i read the system viewer and datasheet (page40) there is no such register as RCC_CR_PLL so it just stuck there forever

GRROWL911 commented 9 months ago

Indeed that was my conclusion as well, and if you debug the HSE the startup fails and reverts like you saw. The default appears to be 8MHz, and everything seems to be working. All clock defines commented out.as of the system clock, turns out im wrong the whole time, the example is using HSI the internal rc oscilator but it seems like the startup file is wrong because when debug i saw the code stuck at waiting for clock to finish configure so i changed it to HSE and it worked but thats because HSE is external oscilator and is not installed so the system is reverted back to LSI low speed internal rc oscilator image.png (view on web) here is where the code stuck at and when i read the system viewer and datasheet (page40) there is no such register as RCC_CR_PLL so it just stuck there forever

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

AILIFE4798 commented 9 months ago

@GRROWL911 ive made changes and code updated 1.for the PWM frequency i have added option is pinout.h to change it(with auto compensation so you only need to command 1000~-1000 in pure pwm mode, RPM in constspeed mode), but increase the frequency decrease the performance significantly that it is not worth it at all, you shall try 8192 resolution its way better at same duty cycle 2.clock is using default now and millis++ removed from adc interrupt 3.hall sensor still in adc interrupt, because in HALLTIM interrupt motor does not run smooth 4.constspeed is now using accurate RPM

if you still have any hardware issue you can ask me im better at hardware then software

GRROWL911 commented 9 months ago

Better at software than hardware, but learning. Thanks for the Itot and B+ traces, the Chg and B+ were reversed but otherwise very helpful. Will look at your changes, thanks. 1.for the PWM frequency i have added option is pinout.h to change it(with auto compensation so you only need to command 1000~-1000 in pure pwm mode, RPM in constspeed mode), but increase the frequency decrease the performance significantly that it is not worth it at all, you shall try 8192 resolution its way better at same duty cycle 2.clock is using default now and millis++ removed from adc interrupt 3.hall sensor still in adc interrupt, because in HALLTIM interrupt motor does not run smooth 4.constspeed is now using accurate RPM if you still have any hardware issue you can ask me im better at hardware then software

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

GRROWL911 commented 9 months ago

Could you verify your Hall sensor connections. On this board, Hall A is pin 15, B is 14 and C is 13.

if you still have any hardware issue you can ask me im better at hardware then software

AILIFE4798 commented 9 months ago

its always easier to trace the board with multimeter then by looking at it preferably one with responsive beeper so you can quickly brush the 4 side of mcu to find the pin

my hall sensor connection is same as yours and it cannot be different because only those few pin is connected to tim2

GRROWL911 commented 9 months ago

Thanks, the multimeter route is the one I have been using, just still learning. I know the hall sensor connections are the same, however this board is reversed in order. A is C15, B is C14, and C is C13. Needed to use these for smooth running, however, maybe they just reverse the motor direction.

its always easier to trace the board with multimeter then by looking at it preferably one with responsive beeper so you can quickly brush the 4 side of mcu to find the pin

my hall sensor connection is same as yours and it cannot be different because only those few pin is connected to tim2

— Reply to this email directly, view it on GitHub https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/issues/59#issuecomment-1944760815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIFRBBHL7YOKFSQNZMA5BN3YTUYIBAVCNFSM6AAAAABCU6WQMCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBUG43DAOBRGU. You are receiving this because you were mentioned.

AILIFE4798 commented 9 months ago

they need to be the same, but you can also just reverse the phase wire color, so it does not mean anything, its just 6 tries to get it right

AILIFE4798 commented 9 months ago

If the default clock is 8mhz, the source of clock is hsi set to 48hz and divider is 1/6

GRROWL911 commented 9 months ago

Note: itotal = (double)ITOTAL_DIVIDER((uint16_t)ADC1->ITOTALADC2-itotaloffset)100;

should be something like:

            u16 adc = (uint16_t)ADC1->ITOTALADC2;
            itotal = adc > itotaloffset ? ITOTAL_DIVIDER * ( adc - itotaloffset ) * 100 : 0;

otherwise, if adc is ever lower that itotaloffset, itotal will overflow and return uint16_max

3.hall sensor still in adc interrupt, because in HALLTIM interrupt motor does not run smooth

AILIFE4798 commented 9 months ago

fixed and code updated i cannot fully understand the code above what does question mark mean but the itotal is signed int it should be alright without

AILIFE4798 commented 9 months ago

@GRROWL911 now i have sucessfully run my board at 72mhz and code updated, but now UART does not work(ofcourse it doesnt because baud rate is wrong now)

AILIFE4798 commented 9 months ago

the PWM frequency is increased 9 times for free without losing resolution

AILIFE4798 commented 9 months ago

and i have found a bug in the startup, so that the UART1 is using APB2 runs at sysclock , but UART2 is using APB1 and APB1 is set to half of sysclock so it does not work before

AILIFE4798 commented 9 months ago

and now the code brick spin06 they are probably not compatible like i thought

RoboDurden commented 9 months ago

So both your spin06 master and slave are now bricked :-/ Such things happen to me all the time :-) If you will need a seperate target vor spin06, then the board would also get a new layout number.

AILIFE4798 commented 9 months ago

i will use define in the system file the startup is only for 06 and to make 05 work i edited it then 06 does not work any more now i have added define so you can change it

AILIFE4798 commented 9 months ago

Ok now 72mhz clock working on both 05 and 06 Pwm frequency is much higher now there's not much noise at 8192 resolution UART1 works now there's another bug in hal_rcc library but I temporary fixed it UART2 still does not work who knows why

GRROWL911 commented 9 months ago

it works like an if/then/else, the if before the ?, the then after the question mark, the else after the :

Makes for an inline if/then/else

No, the two variables are unsigned, so when ITOTALADC2 - subtracted from itotaloffset, they are both unsigned. if ITOTALADC2 is less than itotaloffset, overflow will result. (uint16_t)ADC1->ITOTALADC2 static uint32_t itotaloffset=0;

fixed and code updated i cannot fully understand the code above what does question mark mean but the itotal is signed int it should be alright without

AILIFE4798 commented 9 months ago

i have now copy ITOTALADC2 to signed int but without the if..else it should be ok

AILIFE4798 commented 9 months ago

incase anyone still struggling to trace the pins @GRROWL911 @RoboDurden autodetect with self programming feature is online now the matching normal firmware that can read the programmed config is not yet finished but it will be in 2 day

RoboDurden commented 9 months ago

Great if it works :-)

Yet I do not really see that your autodetect.c is easier to understand than mine.

You at least could have adopted structs instead of uint32_t pins[33][3]; And way too many numbers in switch cases instead of enumerates or defines.

But if you stay committed to your firmware we are happy to have you with us :-)

As i still have no mm32 test setup nearby I would love to see a video demonstration. How do you detect the selfHold pin ?

AILIFE4798 commented 9 months ago

i know my firmware is not easy to understand but i dont think you need to understand autodetect i did try my best to make it better but its all i can get i will make the main one easier to and now the testrotate is handled in autodetect it can also be removed from main so less defines clutter