-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
please join and help us :-) #1
Comments
OK I could try to set it up and we could test by pulling this pin high. |
Still tidying up. I have removed the i2c beginning (that you got when forking my repo) and uploaded the final i2c test code here: https://github.com/RoboDurden/GD32_I2C_Slave Things like With the simple motor mode i guess position control would be nice to have next. @Candas1 , maybe try not to quote a full response to keep this issue as short as possible. It will grow vastly anyway :-) |
To be honest, I didn't mean to fork your repository and take over. |
It is an honor for me that you did fork my code witht the little CIO class and my debug macros. |
Unfortunately, my first gen2.0 burned with your code :-/That can happen :-)Maybe i should have enabled this emergency stop first ? Now both mosfet of the green phase have a short over all three pins. and the low-side mosfet of the middle phase blue has a short from sorce to drain but gate still isolated. Now i need to unsolder the mosfet and find replacements. With these analog gate drivers i can only test the low-side without a new mosfet built in because the high-side needs to low-side and the bldc connected to generate the +14V gate voltage for the high side. I guess the driver class should have a protected mode that ensures that no low-side and high-side open at the same time ? Maybe some kind of dry run would be nice were the 6 gate driver pins are mapped to something like the 5 leds ? I did compile and run the C8 enviroment. But in the past it made no differece for the board to upload a c6 or c8 binary. As i mentioned, i am embarking on a 1-2 week journey tomorrow, so i guess i will not proceed a lot today but start packing. |
That's exactly what I want to prevent. |
Deadtime prevents both sides from opening at the same time. In Eferu's firmware I had experimented with something like that , it helped me while debugging but I am not sure if it's meant to prevent issues. I will check with Rob if he has experience about that |
Yes i was unsure if first debugging was a good idea. But then i decided that sooner or later i would want to debug anyway. |
I have not yet looked into the driver code. But it would be good if it had a save mode where it simply checks that no mosfet is turned on when the opposite low/high side is still on. Does the driver class blindly sets gates to high without checking that ? |
It's not working like that. I made sure this code runs with conservative values and is not triggering CC mode of my power supply. |
I tested the board without the 2 mosfet of phase green but then both mosfet of blue burned. Don't know if your firmware was still active. i think i am done for today. Is it possible to add a debug interrupt that logs digital reads the gate output while the pwm interrupt is doing its work ? |
An yes, i should have used the little 3A constant courrent power supply i have here in my train station: https://www.aliexpress.com/item/4000549476335.html |
Yes that's the reason why. |
@RoboDurden when building the code in Candas repository, by mistake I used the wrong SimpleFOC and ended up using the STM32-specific code for SimpleFOC (GD32 elsewhere). Platformio takes some time to upload the libraries referenced by Platformio.ini and if you start compiling too quickly after downloading it, it might pick up the wrong library and use the STM32 code for SimpleFOC A way to test which code is used, is to put a breakpoint in the file gd32_mcu.cpp.c, in the _configure6PWM() function and see if it gets called. Or adding a debug print in that function The MOSFET pins are driven directly by the timer outputs and if the timer is properly programmed, it should never set both high at the same time. Unless there is a stray piece of code that redefines the GPIO pins along the way. As soon as my boards arrive, I can safely test this as well, using a logic analyzer to ensure that the complementary pins are never high at the same time |
As i did step into all new setup functions i did see the new gd32_mcu.cpp.c code from Candas1 :-) My one board is done. after unsoldering the next pair, i can power the board with that simple CC power supply and the 5V and 3.3V cascade is working. But the MCU does not respond to the ST-Link anymore. So the the mcu on board seems to be broken. But i have tested the second board with my gen2.x firmware and my Split_Hoverboard_SimpleFOC from which you did fork. I am used to blow up things :-) |
The safest way to understand what happened is to use a Bluepill with a GD32, attach a logic analyzer to the 6 outputs and set a trigger that triggers if the complementary outputs are both high. Then let it run in all conditions. If there is a stray GPIO code, it will catch it. With a logic analyzer or scope, it's also possible to see if the deadtime is too small for the MOSFETs used. With an insufficient deadtime (and a battery capable of hundreds of amps), it's possible to overheat MOSFETs. Which is also why having a power supply with current limiter is a good idea, as we have just been reminded :) If the timer is properly programmed, the MOSFETs are "protected in hardware", so to speak, and no bug can cause issues. Alas, the way the code works, it's not possible to set a timer to work without actual outputs from GPIOs, so I can't see a way to test the code and prevent the GPIOs connected to the MOSFETs to be driven... |
I added here some calculations, that can be useful. The current deadtime in the gd32 driver(60 clock cycles) is actually same as what simpleFOC is using by default (2% of the PWM cycle). 1250ns is plenty. Eferu's deadtime is only 750ns. In the past I had managed to blow all the mosfets of a splitboard in one go, I had set a target value in debug mode, the value was too high and there was no ramp. But in this repository the target is really low. Still I need to add a ramp/filter. |
@Candas1 looking at the code, the deadtime set function is commented out. That's the one we discussed over email, using the STM32 macros to set the non-linear value in the register So it looks as if at the moment there is no deadtime in the timer, which would explain the problems.... I think I sent you the snippet of code to replicate that STM32 function (but could not test it yet) |
No no it's there but it's a macro. |
Oh, I see... you are using 60, which as you say it's 1250 ns. Would be worth double checking with an oscilloscope (I can do it, as soon as I have my boards) The math is pretty complicated, given that it depends on the clock divider (0, 256 or 512), the CPU clock, and the register has a non-linear effect on the actual deadtime. I did send you the STM macro with all the needed definitions to make it work, let me find it and copy it here
And, yes, it's rather horrible :) I didn't take the time to unravel all those macros, just found a way to make them work. Incidentally, can't use it as is in the future due to the STM IP, but for now it's probably ok EDIT: as a memo to myself to fix this, here is the relevant portion from the GD32 manual |
Yes this is definitely in the todo list, the current value was just to get it to work, and it should be correct. Max from Arduino-gd32 was asking here if there are expectable functions missing. |
Hi guys, regarding size optimization, I really encourage you to use bloaty. It's an outstanding tool. |
Hi, I tried debugging today, and even if I don't add any breakpoint and just run the code, my power supply definitely goes to CC mode. This is not happening when just flashing the firmware. |
Great news :-) |
I did small changes to this repo and to the arduino-foc one. |
Just a quick update: I received my Aliexpress order and managed to successfully do a brain transplant: I now have a working GD32F130C8 Bluepill. I have just checked that STLink can see and program it., not tried any actual code yet. |
motor still stuttering and spinning very poorly after a few seconds: https://youtu.be/2OGnwagtY-U It is the same stuttering that made my boad 1 burn after a stutter right followed by a stutter left ! @Candas1 , i did not fork your fork but cloned it with my Windows Github Desktop. But you can quickly remove the i2c stuff in main.cpp yourself anyway :-) After that video i tried all three combinations of
But no change in motor behavior. So it seems to be a timing issue ? It is very convenient to have my Gen2.x firmware opened with Keil so i can simply hit F8 to very quickly stop the stuttering and reflash the 2.0_master_test binary (which does nothing when the onoff button is permanently switched on). Now i wonder why your motor is not stuttering. Greetings from Germany. @robcazzaro is in the California time zone. what is your time zone Candas ? And is Candas your first name ?? |
That's not stuttering, that's the sensor alignment. My motor runs the same, I need to play around with the different modes. Pull requests work only if you fork the repo. I am from France, I am leaving close to Germany and Switzerland actually. [EDIT] I also removed the I2C code now |
Maybe i or you should post my video to the simpleFOC community and someone with BLDCDriver6PWM will quickly identify the poor spinning ? |
in
You can also search and delete the two lines with And the two uart return to sender stuff:
and
:-) |
I need to experiment more. |
Unless I did something seriously wrong, I would recommend to stop using this code on a board connected to a power supply and with MOSFETs attached. I just opened #4 as a work item for myself. I'm done for the day today, will work on this tomorrow. In order to test the PWM code, I used the PWM6 standalone driver example (below). CH1 is connected to the H output, CH2 to the L output. On the pins outputting 0, I see this. i.e. both MOSFETs ON at the same time (minus some spikes every ~38usec) On the pins outputting 1 and 3 respectively, I see As you can see, the same spikes every ~38usec, which cause the MOSFETs to conduct at the same time (every now and then). Also, the pin assignment seems wrong (G and B are inverted, so what should have been the 0 output was on the B pins instead, PA9 and PB14) With the STM32 Bluepill and the same code, everything is as expected (0, 1 and 3 in order)
|
Thank you @robcazzaro very much. I first try to understand the stm32 outputs: The upper image are hi-side (yellow) and lo-side (blue) mosfets conected to phase B, Then in about the first 30% of the full cycle i see a "negative" current flowing from phase G to B through the coils inside the motor (hi-side of B is on and lo-side of G is on). But how does that correlate to These three float values could also be negative, resulting in "opposite" current flow ? As i have not read the simpleFOC code, for me it is still a black box :-/ |
I think this is what @robcazzaro used. |
@Candas1 , your photo is with the simple `driver.setPwm(1, 0, 3); test code ? |
So 3.0/12.0 = 25% duty cycle on phase A, |
This was to show that it's not happening with the repository code. |
You provide a voltage for each phase, that simpleFOC translates to a duty cycle between 0 and 1. (voltage / supply_voltage) |
Thanks Candas, now I understand :-) |
Yes, you're setting a pwm duty cycle/voltage, but the important one is the line to line voltage, that's when the current flows. If you are interested, I like this intro. |
The sensor alignment is weird, the motor would sometimes spin smoothly, sometimes poorly. |
Just a quick update here that I solved most of the timer/PWM issues and things should work better #4 (comment). But a PWM value of 0 (i.e. a phase temporarily at 0V) still results in a wrong output, so it's still unsafe |
@robcazzaro, I shared my comments and will check this evening what can be improved. When I come back I will be able to experiment with those boards that are using a STM32F103: |
@Candas1 i do not really understand why you have removed the C6 enviroment as it should still fit in the 32 kB flash:
A usable Split_Hoverboard_SimpleFOC seems to be in reach and as we have the pin definitions of one C6 and one K6 board, i would like to do my best to support them. The X6 mcu only has 4 general timers(16-bit) instead of 5. Is that the problem ?? P.S. If you have a grilfriend with you on holidays, you should put this simpleFOC project on halt for the next two weeks ! |
@RoboDurden, Platformio is weird and having a dual C8 C6 setup makes everything harder now. Once we have the C8 working, making a C6 version is going to be super-easy. No point in having extra complexity now |
Hi @Candas1 , @robcazzaro i guess the candas fork should now be the place of activity and indeed the old RoboDurden/Hoverboard-Firmware-Hack-Gen2.x#11 needs seconds to load on my mobile data plan.
I can probe PB12 with a dso to see if it offers analog or digital input. But according to your spreadsheet
https://docs.google.com/spreadsheets/d/15msbDAIMxC2rIkq8Au8vf82ub1qEaS67Lc1cFb86Jpc/edit#gid=0
"sed on some of the boards as overcurrent trigger when the dc current is high enough to turn a transistor ON. Should disable PW"
i need to find that transistor and see if i can verify an analog input there while putting a hand on the motor with my gen2.x firmware running.
But according to the 2.0 schemtaics, PB12 is functional:
![current measure pb12 gen2 0](https://private-user-images.githubusercontent.com/12238841/246036546-9d0925b3-05ac-4481-8c83-b6d022d530cf.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MjgwMTQsIm5iZiI6MTczOTUyNzcxNCwicGF0aCI6Ii8xMjIzODg0MS8yNDYwMzY1NDYtOWQwOTI1YjMtMDVhYy00NDgxLThjODMtYjZkMDIyZDUzMGNmLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDEwMDgzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgwMjIxZWRmNTI3MWYzM2VlYjQ1YjY3ZDcyMDk1ZThjZTY1YTQ4MzhkYzcyMTg3NzhjMzA5OTMzMWY2ZjQxN2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.2_r2zrQ5WMzCifnOmuguU0j4ABOC-mlD_YDJjFJiKw0)
With the mosfet only driven by the shunt voltage, it should open slowely and indeed produce some analog value on PB12 when some strong current reaches the the gate threshold.
I checked the photos of the various layouts. Only 2.1 and 2.5 have a C6 mcu. The others have a C8 with doubled flash and ram = 64 kB flash and 8 kB ram. (2.2 has K8 which only has less pins)
So to get all features running i think for now it is okay to compile with the C8 enviroment :-)
The text was updated successfully, but these errors were encountered: