Jump to content
jayjay23

Firmware

Recommended Posts

Posted (edited)

I am being learning how the others do, in a cheap way!!

I was able to program the microcontroller STM8 on the same day the EBike motor controllers arrived - although not relevant for EUC, I think is interesting this knowledge for motor control. This cheap controllers are a 2nd generation. The first one did only 6 step and had a shunt to measure motor total current, so no FOC nor current in phase +90º with rotor that is one of the main objectives of FOC -- the same as 1st generation EUC controllers!!

The 2nd generation, costs only 22€ but added a current sensor ACS712 in one phase. Now the wave forms are sinusoidal and I think they look at the phase current to make it in +90º in phase with rotor, achieving the most important objective of FOC and keep the motor rotating using the less energy possible -- amazing for a controller that came inside a metal box and water prof and just by 22€. It uses hall sensors only for track motor rotor position. The microcontroller STM8 is 8 bits, have 32kb flash memory, no multiplications/divisions hardware, no DMA and runs at 16MHz. In contrast, the MW 30B4 board STM32 is 32 bits, have 128kb flash memory, has multiplications/divisions hardware, has DMA and runs at 72MHz - and the board includes 2 phase current sensors, and because of this more power can do FOC.

Some pictures:

Programming and debug cable connected to SWIM - using the same cable STLinkV2 I use on MW 30B4 board:

29-1.png

The first code was a printf, to the wires that connect to external LCD for the EBike:

29-2.png

29-4.png

29-5.png

 

 

Edited by electric_vehicle_lover
  • Upvote 2

Share this post


Link to post
Share on other sites

Hi,i find two generics EUC controllers board which are not very expensive in Taobao.

The first one:

Link:https://item.taobao.com/item.htm?spm=a230r.1.14.75.6XNyi3&id=529511401695&ns=1&abbucket=6#detail

11.thumb.jpg.130eeb28eb5c51b99e310ba452946d2d.jpg

The second one:

Link:https://item.taobao.com/item.htm?spm=2013.1.20141003.3.I10tSU&scm=1007.10011.70203.100200300000004&id=529591376117&pvid=2c5cc2b7-8915-46ff-a983-72d9fad2ffc2

22.jpg.ffc294d8d53f6a29ffbaf2ffb3ba25bc.jpg

The two board's scheme are similar to MicroWorks-30B4.They cost about 40 USD.Boards looks very well,so i just really want to buy one.

 

  • Upvote 2

Share this post


Link to post
Share on other sites
1 hour ago, lizardmech said:

They show part of their FOC code here, it's sensorless with hall sensor startup. Conventional SVM and clark/park transforms.

https://world.taobao.com/item/531928634884.htm?fromSite=main&spm=a312a.7700824.w4004-14846006895.18.36MAJg

Looks like they offer gotway clone and firewheel clone.

Or Gotway also cloned 

Share this post


Link to post
Share on other sites
Posted (edited)

@electric_vehicle_lover  Do you know the China's "The NXp Cup National University Students Intelligent Car Race"? The balance group of this competition can help you a lot.Particularly the balance Group's control algorithm is very similar to balance EUC.I can share the original firmware to your E-mail.Futhermore,i have some documents and videos about the balance group's control algorithm,but all documents are wrote in chinese language.I think that it's not easy to read it for you.

 

Edited by KingQueenWong
  • Upvote 2

Share this post


Link to post
Share on other sites
Posted (edited)
12 hours ago, KingQueenWong said:

The second one:

Link:https://item.taobao.com/item.htm?spm=2013.1.20141003.3.I10tSU&scm=1007.10011.70203.100200300000004&id=529591376117&pvid=2c5cc2b7-8915-46ff-a983-72d9fad2ffc2

22.jpg.ffc294d8d53f6a29ffbaf2ffb3ba25bc.jpg

The two board's scheme are similar to MicroWorks-30B4.They cost about 40 USD.Boards looks very well,so i just really want to buy one.

This is actually (a clone of?) the Firewheel mainboard (apparently without the secondary board that handles front- & backlights, battery display and voice messages). I've traced most of the mainboard here (I think it's missing just a few unused connectors and the gyro/accelerometer chip, will get to finish it eventually): http://forum.electricunicycle.org/topic/7152-firewheel-pcb-tracing/

Interestingly, the translated page says:

If the customer needs to customize the program, we can also provide the entire code.

If you need to buy a control board or to further develop or source code related issues, please contact customer service!

 

Edited by esaj
  • Upvote 1

Share this post


Link to post
Share on other sites
19 hours ago, KingQueenWong said:

Hi,i find two generics EUC controllers board which are not very expensive in Taobao.

The two board's scheme are similar to MicroWorks-30B4.They cost about 40 USD.Boards looks very well,so i just really want to buy one.

I am curious for the first one and prices are good to. I wish I could find a shop in EN, maybe that company have a website in EN? can you please look at it? Could this guys be like MicroWorks?

However I don't have time to look at so much boards I have now...

18 hours ago, lizardmech said:

They show part of their FOC code here, it's sensorless with hall sensor startup. Conventional SVM and clark/park transforms.

https://world.taobao.com/item/531928634884.htm?fromSite=main&spm=a312a.7700824.w4004-14846006895.18.36MAJg

Looks like they offer gotway clone and firewheel clone.

Great findings!! I saved this information, gives a lot of clues.

Share this post


Link to post
Share on other sites
9 hours ago, KingQueenWong said:

@electric_vehicle_lover  Do you know the China's "The NXp Cup National University Students Intelligent Car Race"? The balance group of this competition can help you a lot.Particularly the balance Group's control algorithm is very similar to balance EUC.I can share the original firmware to your E-mail.Futhermore,i have some documents and videos about the balance group's control algorithm,but all documents are wrote in chinese language.I think that it's not easy to read it for you.

Thanks for the files!! I will put them on https://eggelectricunicycle.bitbucket.io/ under the Balance Controller section.
The PDF files seems very good, with the physics and math that I want to learn!! I will try to use google translate to understand the text. The illustrations are great!!
Are you Chinese??

Share this post


Link to post
Share on other sites
Posted (edited)
10 hours ago, KingQueenWong said:

@electric_vehicle_lover  Do you know the China's "The NXp Cup National University Students Intelligent Car Race"? The balance group of this competition can help you a lot.Particularly the balance Group's control algorithm is very similar to balance EUC.I can share the original firmware to your E-mail.Futhermore,i have some documents and videos about the balance group's control algorithm,but all documents are wrote in chinese language.I think that it's not easy to read it for you.

 

The code have all the comments in EN and was easy for me to find the balance control code!!!

On their Timer1 interrupt (Events.c) they call in sequence:

AngleCalculate();
AngleControl();        
MotorOutput(); // Output motor control voltage;

---

void AngleCalculate(void)
{
     float fDeltaValue;
     
     g_fGravityAngle = (VOLTAGE_GRAVITY - GRAVITY_OFFSET) * GRAVITY_ANGLE_RATIO;
     g_fGyroscopeAngleSpeed = (VOLTAGE_GYRO - GYROSCOPE_OFFSET) * GYROSCOPE_ANGLE_RATIO;
     
     g_fCarAngle = g_fGyroscopeAngleIntegral;
     fDeltaValue = (g_fGravityAngle - g_fCarAngle) / GRAVITY_ADJUST_TIME_CONSTANT;

     g_fGyroscopeAngleIntegral += (g_fGyroscopeAngleSpeed + fDeltaValue) / GYROSCOPE_ANGLE_SIGMA_FREQUENCY;
}
     
void AngleControl(void)
{
    float fValue;
     
     fValue = (CAR_ANGLE_SET - g_fCarAngle) * ANGLE_CONTROL_P +
              (CAR_ANGLE_SPEED_SET - g_fGyroscopeAngleSpeed) * ANGLE_CONTROL_D;
              
     if(fValue > ANGLE_CONTROL_OUT_MAX)        fValue = ANGLE_CONTROL_OUT_MAX;
     else if(fValue < ANGLE_CONTROL_OUT_MIN)    fValue = ANGLE_CONTROL_OUT_MIN;
     
     g_fAngleControlOut = fValue;
}

void MotorOutput(void)
{
    float fLeft, fRight;

    fLeft = g_fAngleControlOut - g_fSpeedControlOut - g_fDirectionControlOut;
    fRight = g_fAngleControlOut - g_fSpeedControlOut + g_fDirectionControlOut;
    
    if(fLeft > MOTOR_OUT_MAX)    fLeft = MOTOR_OUT_MAX;
    if(fLeft < MOTOR_OUT_MIN)    fLeft = MOTOR_OUT_MIN;
    if(fRight > MOTOR_OUT_MAX)    fRight = MOTOR_OUT_MAX;
    if(fRight < MOTOR_OUT_MIN)    fRight = MOTOR_OUT_MIN;
        
    g_fLeftMotorOut = fLeft;
    g_fRightMotorOut = fRight;
    MotorSpeedOut();
}

-------------------

This is the main equation for balance:

fValue = (CAR_ANGLE_SET - g_fCarAngle) * ANGLE_CONTROL_P + (CAR_ANGLE_SPEED_SET - g_fGyroscopeAngleSpeed) * ANGLE_CONTROL_D;

So is a PD controller!! in line what I saw written before on other places... well, maybe not a PD controller, maybe something with 2 inputs: angle and angle speed. That's why I want to learn the physics and math.

Edited by electric_vehicle_lover
  • Upvote 1

Share this post


Link to post
Share on other sites
Posted (edited)
6 minutes ago, KingQueenWong said:

@lectric_vehicle_lover  Yes,I am chinese.:DI took part in this competition in 2012.

I like that you are with us. A lot of technology coming from China and that sometimes I think I do not understand the culture. For instance, small ebikes are everywhere I live but they are not bicycles nor motorcycles... and we had to adapt to them and I think is a big thing in China that were imported to our cities. I wish small and cheap Chinese electric cars could also be adopted here.

Edited by electric_vehicle_lover

Share this post


Link to post
Share on other sites
Posted (edited)

I had a good surprise with the cheap 22€ EBike controllers from BMSBattery. This ones have only 1 sensor current in one phase + a shunt current sensor for total current and this is how it should work for put motor current at +90º of rotor flux:

- measure phase current (I-Uphase) and see if is +90º of rotor flux (rotor flux position is done with the HA hall sensor signal):

Screenshot_from_2017-05-22_21-38-09.png

There is an lag on the current of delta teta and so this need to be corrected, so next we advance PWM motor voltages (V-Uphase) in the value of delta teta and the current will then be at the desired timing:

Screenshot_from_2017-05-22_21-38-21.png

This way the controller does the most important objective of FOC that is keep motor current at +90º of rotor flux and so running at the most efficient way, spending the less energy possible.
I found they do also do Space Vector Modulation (SVM).

So, why this can be relevant for EUC?? Because this controllers are available to work in voltages from 24V, 36V, 48 and 72V and they can handle 40A -- 1KW at 72V. This means the MicroWorks 40A board with 12 mosfets should be almost equivalent in terms of power.
This cheap controllers can't do the balance control but they have serial port wires. Now that I can develop the firmware for them, I can try replicate the original firmware and adding code for receiving by serial port the command for the motor PWM, for it rotate with more or less power and in which direction -- just the same a user did an electric Skate using VESC for motor controller + Arduino for balance algorithm that sent the motor PWM to VESC using the serial port.

Idea for a EUC controller:

- (36€) motor controller: BMSBattery S12S controller of 60V (option to be 36V or up to 72V)
- (20€) balance controller: OMNIBUS F3 AIO Flight Controller that includes STM32F303 + IMU MPU6050 (this board is powered from the motor controller and sends to it the PWM value for the motor, using serial port)
- (3€) firmware programmer for both boards: STlinkV2

And to be safe, I think we can even use the EBike direct drive motor BMSBattery sells Q11 48V 1KW 370 RPMs. I just don't know the short wheel size that is possible to build with this motor.

So I will keep working on the firmware for this motor controllers, knowing that they may be a possibility for EUCs.
BMSBattery is selling since 2011 and they keep selling their first generation motor controllers since then, so, since 6 years ago. I think is a good bet to develop technology around their products. And I don't think EBike market will decrease like EUC market, I think it will keep growing.

Edited by electric_vehicle_lover

Share this post


Link to post
Share on other sites

Whats the point? It's $120 or so with shipping, I can easily build a board with a high end MCU and 40A support for that.

  • Upvote 2

Share this post


Link to post
Share on other sites
On 5/21/2017 at 9:56 PM, KingQueenWong said:

@electric_vehicle_lover  Do you know the China's "The NXp Cup National University Students Intelligent Car Race"? The balance group of this competition can help you a lot.Particularly the balance Group's control algorithm is very similar to balance EUC.I can share the original firmware to your E-mail.Futhermore,i have some documents and videos about the balance group's control algorithm,but all documents are wrote in chinese language.I think that it's not easy to read it for you.

 

Are there many freelance programmers in china? There's plenty of good programmers on english websites but none have balancing vehicle experience, are there any chinese websites where someone could be hired to help?

  • Upvote 1

Share this post


Link to post
Share on other sites
10 hours ago, lizardmech said:

Whats the point? It's $120 or so with shipping, I can easily build a board with a high end MCU and 40A support for that.

It is under 100€. But would be great if you could provide the same for $120, including the metal heat sink.

Share this post


Link to post
Share on other sites
1 hour ago, Carlos E Rodriguez said:

THANKS!!! being following Xenon John on Youtube but never found his website!!

On https://sites.google.com/site/onewheeledselfbalancing/Home/17-new-unicycle-project-2011 really nice to see the design with a EBike hub motor and that he had to use a DC motor. Since I know, he never used a brushless motor, always a DC motor. I think I am the world's first getting a brushless motor running for a balance thing (as OpenSource project).
Perfect all the information on his site!!!

Share this post


Link to post
Share on other sites
Posted (edited)

@lectric_vehicle_lover  I find this code:https://github.com/OpenSourceEvController/EV-AC-Controller

The control algorithm and the achitecture is good.There is a  lot of annotations in it. No need to use float operation,just use Q15(which is easy to implement).I think it can improve the control precision.I think that you can add a new branch to change your current firmware achitecture.

Edited by KingQueenWong

Share this post


Link to post
Share on other sites
3 hours ago, KingQueenWong said:

@lectric_vehicle_lover  I find this code:https://github.com/OpenSourceEvController/EV-AC-Controller

The control algorithm and the achitecture is good.There is a  lot of annotations in it. No need to use float operation,just use Q15(which is easy to implement).I think it can improve the control precision.I think that you can add a new branch to change your current firmware achitecture.

Not sure if weaker MCUs will handle that, appears to be running on a dspic, DSPs can do certain tasks very quickly even if their cpu is weak for general purpose tasks.

Share this post


Link to post
Share on other sites
Posted (edited)

About motor possible (not) using sensorless on EUC application

On 27/05/2017 at 11:11 AM, esaj said:

At low speeds, the wheels seem to use the hall-sensors. If you go mucking about with their placement or such, the software cannot run the motor correctly, and cannot balance. At higher speeds, it seems that the wheels start to use a "sensorless mode" to estimate the position and the speed of the motor, that's built into the software itself.

@esaj and others, I know I am being telling that EUC original firmware may be using sensorless after some speed and hall sensor just to start and be able to quick change direction. I also implemented only using hall sensors and no sensorless and it seems to be running well, at least for what I can understand, the motor does the same very low noise as original firmware.

Also, as we can see on chinese firmware for EUC: https://eggelectricunicycle.bitbucket.io/FOC--Chinese_controllers_code.html (see first line of FOC_Model()) they seem to use only hall sensor (no sensorless) and just the same way I do, estimate angle between each hall sensor pulse, that's why they integrate the electric angle.

To resume: I would say that firmware of EUC don't need sensorless to work (as like the original firmware). Maybe sometimes we are to picky with our selfs - chinese seems to simply and do it in a cheap way.

 

Edited by electric_vehicle_lover
  • Upvote 2

Share this post


Link to post
Share on other sites
10 hours ago, KingQueenWong said:

@lectric_vehicle_lover  I find this code:https://github.com/OpenSourceEvController/EV-AC-Controller

The control algorithm and the achitecture is good.There is a  lot of annotations in it. No need to use float operation,just use Q15(which is easy to implement).I think it can improve the control precision.I think that you can add a new branch to change your current firmware achitecture.

On my firmware I am using already Q15 with the use of the OpenSource qfplib-m3 library: https://www.quinapalus.com/qfplib-m3.html

Thanks!! The code seems for an AC induction motor which is not the same we are using, anyway they do FOC and the code really have some valuable comments!! I saved the link and code on my notes files.

They don't seem not using any encoder or hall sensors and the rotor position is calc here: ComputeRotorFluxAngle();

The project seems to be this one, for electronics and firmware for electric cars (nice project!! I own an electric car and maybe in future I will joint such project):

Revolt_color.jpg
http://ecomodder.com/wiki/index.php/Open_ReVolt

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×