OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Electric Motors and Controllers

OpenSource firmware BMSBattery S/Kunteng KT controllers STM8

Postby casainho » Tue Apr 25, 2017 8:37 pm

I would like develop a OpenSource firmware for the EBike controllers. Why I am looking to this? because I want to use a well know controller that it is easy to repair/mod/adapt for my specific projects. I will develop the firmware for it, as OpenSource and I would like to share with others that have the same needs. My mission similar to the Tesla (https://www.tesla.com/blog/mission-tesla): "to accelerate the advent of sustainable transport" and innovation on personal light electric vehicles.

The idea is to find a cheap and widely available EBike controller that can be programmable. I am developing (since 2 years ago) firmware for the controllers of electric unicyles and they use the microcontroller STM32F103, that is very cheap and popular - the board is also cheap and widely available on market, comming from China. By the way, the hoverboards controllers use the same STM32F103 microcontroller.

For EBikes, seems a good candidate are the most recent BMSBattery controllers that does sinewave - S06S: https://bmsbattery.com/ebike-kit/546-s0 ... e-kit.html
This controllers use the STM8S105xx, that is easy to program. There are OpenSource tools for it and on EBay we can find, for instance, development board with price as low as $3!!

I am keeping my notes/documentation here: https://opensourceebikefirmware.bitbuck ... oject.html

Image
Attachments
Screenshot from 2017-05-08 12-50-08.jpg
Last edited by casainho on Wed Jun 21, 2017 10:41 am, edited 8 times in total. View post history.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource EBike firmware (STM8S microcontrollers)

Postby casainho » Wed Apr 26, 2017 9:39 am

I updated the documentation notes file and seems that S06S controller continually output by UART serial port the information that is presented on the LCD controller. Also the LCD controller sends back some configurations to the S06S controller. I bet we can just connect a UART Bluetooth serial module instead of the LCD controller and make a simple Android to control the S06S controller!!

Thanks to the guy that documented the S06S LCD communications protocol:

Screenshot from 2017-04-26 15-35-05.png
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource EBike firmware (STM8S microcontrollers)

Postby casainho » Sun Apr 30, 2017 12:37 pm

I did install the SDCC compiler for STM8 and I prepared the main.c and gpio.c files, they build correctly but I do not have yet a board to test.
I also have the OpenOCD scripts that will let me flash and debug the firmware.
I did commit the code to: https://github.com/OpenSource-EBike-fir ... s_firmware

I also updated the notes file with more information, mainly about how to install the development and attached some datasheets and application notes about motor control with STM8. This notes file about now about 80MBytes and can be found here: https://github.com/OpenSource-EBike-fir ... EE_xml.ctd
Image
Attachments
Screenshot from 2017-04-30 18-34-52.png
(173.4 KiB) Downloaded 49 times
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource EBike firmware (STM8S microcontrollers)

Postby casainho » Mon May 08, 2017 4:02 am

I received the cheap dev board with STM8 and started to put the development tools together. Finally I just run the printf() example I found on github. So for now I was able to compile C code, debug it (breakpoints, step run, see/change variables in real time, inspect/write memory) and send strings over UART serial -- like original BMSBaterry S series controller do when communicating the S LCDs.

The firmware sources are here: https://github.com/OpenSource-EBike-fir ... s_firmware

Debug STM8 using STlinkV2, OpenOCD and Eclipse:
Image

The printf() output over UART serial:
Image
Attachments
z01.png
(227.12 KiB) Downloaded 44 times
z02.png
z02.png (47.27 KiB) Viewed 2598 times
Last edited by casainho on Mon May 08, 2017 4:04 am, edited 1 time in total. View post history.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource EBike firmware (STM8S microcontrollers)

Postby casainho » Mon May 08, 2017 4:09 am

On the last days I also finished a robust version of the firmware for FOC motor control of electric unicycles, that should also run on the hoverboards since they use the same microcontroller and IMU ics. I will use this firmware as a base for the EBike controllers.

The firmware was feature yesterday on the popular news site HACKADAY: http://hackaday.com/2017/05/07/open-sou ... verboards/

Video showing the firmware in action, controlling a motor using FOC. The motor is a direct drive one:
Last edited by casainho on Mon May 08, 2017 4:10 am, edited 1 time in total. View post history.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource EBike firmware (STM8S microcontrollers)

Postby casainho » Mon May 08, 2017 6:53 am

Finally found a way to have the documentation on the note taking software CherryTree but also have it on github as HTML page, this means google should be able to index it and users will found all the documentation when searching for it, like the main keyworks.

My workflow will be like this: keep improving the CherryTree notes file and commit the source file to github - anyone can submit an improvement/pull request to that file. At the same time, export from CherryTree to HTML and commit also to github, the output will be an update HTML page on the link: https://opensource-ebike-firmware.githu ... o--01.html

Screenshot from 2017-05-08 12-50-08.jpg
Last edited by casainho on Mon May 08, 2017 6:54 am, edited 1 time in total. View post history.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource EBike firmware (STM8S microcontrollers)

Postby casainho » Thu May 18, 2017 11:07 am

Today I received the BMSBattery S06S controllers and I was able to program and debug a first firmware that sends some strings over the wires that goes to the LCD :-)

I am updating my notes/documentation for this project here: https://opensourceebikefirmware.bitbuck ... oject.html

2017-05-18 16.40.11.resized.jpg

2017-05-18 16.42.07.resized.jpg

01.png
(106.27 KiB) Downloaded 37 times

02.png

03.png
03.png (153.44 KiB) Viewed 2466 times
Last edited by casainho on Thu May 18, 2017 11:09 am, edited 1 time in total. View post history.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: BMSBattery OpenSource EBike firmware - STM8 microcontrol

Postby izeman » Fri May 19, 2017 4:43 am

that's awesome work and i follow it closely. do you think there are more powerful controllers that may use your software (when it's done) as well? 250w is so super tiny ... ;)
User avatar
izeman
10 GW
10 GW
 
Posts: 4401
Joined: Tue Jun 21, 2011 8:25 am
Location: vienna, austria

Re: BMSBattery OpenSource EBike firmware - STM8 microcontrol

Postby casainho » Fri May 19, 2017 5:07 am

izeman wrote:that's awesome work and i follow it closely. do you think there are more powerful controllers that may use your software (when it's done) as well? 250w is so super tiny ... ;)

Thank you for your feedback!! This forum misses a "like" button.

All the S series controllers from BMSBattery, the ones with 6 and 12 mosfets. Seems the more powerful they have is: "S12SN 72V1KW 40A Torque Simulation Sine Wave Controller".

This controller seems to be developed by http://www.szktdz.com/en/. Potential for this firmware work or be ported easily for every controller done with STM8S. Seems that GreenEBikeKit also sells the same controllers under different name.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: BMSBattery OpenSource EBike firmware - STM8 microcontrol

Postby d8veh » Sat May 20, 2017 6:54 am

izeman wrote:that's awesome work and i follow it closely. do you think there are more powerful controllers that may use your software (when it's done) as well? 250w is so super tiny ... ;)


All the S-series controllers from BMSBattery and probably all the modern KT controllers.
d8veh
100 GW
100 GW
 
Posts: 5258
Joined: Fri Dec 10, 2010 10:45 am
Location: Telford

Re: BMSBattery OpenSource EBike firmware - STM8 microcontrol

Postby casainho » Sat May 20, 2017 2:14 pm

d8veh wrote:
izeman wrote:that's awesome work and i follow it closely. do you think there are more powerful controllers that may use your software (when it's done) as well? 250w is so super tiny ... ;)


All the S-series controllers from BMSBattery and probably all the modern KT controllers.

Hi d8veh. I found a lot of your messages helping, since some years ago, on this forum and others -- many respect for you. Really happy that you following this thread.

Can you please point a webshop for that KT controllers? I am listing here the alternative controllers with STM8: https://opensourceebikefirmware.bitbuck ... llers.html

I updated the documentation (https://opensourceebikefirmware.bitbuck ... oject.html) and here is the news:

New information I have:

STM8S105C6T6
• pin 2: resistor 2200R and a capacitor to GND. This pin goes to blue wire of undocumented connector with 2 wires (blue and black(GND))
• pin 3: resistor 2200R and a capacitor to GND. Resistor 10k to VCC. This pin goes to a header pin that is not wired
• pin 10: through one resistor, goes to BRAKE wire
• pin 15: ?? goes to a big diode..
• pin 16: goes to pin 7 LM358 (shunt current)
• pin 17: goes to pin output of ACS711 (phase B current)

Components:
• LM317 (voltage regulator): outputs 14.8V for the mosfet drivers
• 78L05 (voltage regulator): outputs 5V for the VCC
• LM358 (dual op-amp):
◇ pin7: outputs a value from shunt current (motor total current)
▪ 1.63V when motor is stopped (zero current)
◇ pin1: always at 5V. Seems it is not used and is connected to 5V with a resistor
• ACS711 (hall effect current sensor):
◇ output pin goes through a resistor (and a capacitor to ground) to pin STM8S105C6T6 pin 17 PB5/AIN5. This measures a motor phase B current (green phase wire)
▪ 2.5V when motor is stopped (zero current)
◇ fault pin is not used and is connected with a resistor to 5V

Possible motor control scheme
his cheap controllers are a 2nd generation. The first generation like BMSBAttery KU63 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 2nd generation controllers, costs only 22€ but added a current sensor ACS712 in ne 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 that is keep the motor rotating using the less energy possible (that will also result in more silent motor) -- 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.

Explanation example of AN-8201 FCM8201 Three-Phase Sine-Wave BLDC Motor Controller document:

At 2., the middle HA is where motor flux is and the I phase current must be at 90º after, but as seen, there is a delta teta added to the point of 90º (that point is at end of positive value of HA).
At 3., the motor phase voltage (that we control) we advance delta teta and the result is the phase current will now be at 90º of middle HA (flux) -- this is the point where the motor will have more torque per amp used, the most efficient point:
234.png
234.png (117.29 KiB) Viewed 2370 times
Last edited by casainho on Sat May 20, 2017 2:17 pm, edited 1 time in total. View post history.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby machado88 » Sun May 21, 2017 5:00 am

Hummm... For sure looks a good controller for 22 bucks. But it is a bit far from FOC.
Yes, by maintaining rotor wingdings orthogonal to the stator field you get maximum Torque production.
However, what this enhanced controller does is that it is always trying to apply a correction to fix the angle issue that the controller itself created (confusing, right?).

FOC starts with the separation of two basics things: Magnetic Flux and Torque. So, FOC already has a pretty good estimation of the angle at any given moment (not only to maintain at 90, but to change that when doing Field-Weakening)
If you do not have those two vectors, you are basically in speed control. Some are more fancy them others, but they are still Speed controllers.

Correction: The angle estimation is unknown at standstill (if sensorless). We have to use some other fancy stuff to go around the motor startup.
Last edited by machado88 on Sun May 21, 2017 5:02 am, edited 1 time in total. View post history.
LegStrong - Open-Source HW/SW controller (FOC + Bluetooth)
https://endless-sphere.com/forums/viewtopic.php?f=2&t=88285
User avatar
machado88
1 mW
1 mW
 
Posts: 15
Joined: Sun Aug 30, 2015 4:10 pm
Location: Portugal

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby casainho » Sun May 21, 2017 8:05 pm

Hackaday, the popular website for Hacking news, did a quick reference to this project: http://hackaday.com/2017/05/21/hackaday ... y-21-2017/
Is not 100% correct but I think is ok and the readers can always follow the link to here and get the full information.

Image
Attachments
0zz.png
(25.98 KiB) Downloaded 26 times
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby casainho » Tue May 23, 2017 8:39 am

I finish the code that reads the hall sensors signals - using a pin change interrupt. The firmware is here: https://github.com/OpenSource-EBike-fir ... s_firmware

#define EXTI_PORTE_IRQHANDLER 7
void EXTI_PORTE_IRQHandler(void) __interrupt(EXTI_PORTE_IRQHANDLER)
{
unsigned char hall_sensors = 0;

// read hall sensors signal pins and mask other pins
hall_sensors = (GPIO_ReadInputData (HALL_SENSORS__PORT) & (HALL_SENSORS_MASK)); // sequence: 1; 3; 2; 6; 4; 5

printf("%d\n", hall_sensors);
}

int main()
{
uart_init ();
hall_sensor_init ();
enableInterrupts ();

while (1) ;
}
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby casainho » Tue May 23, 2017 8:58 am

I did finish taking the information about pin connections to STM8 so I can start writing the firmware. I also documented the PWM signals including the dead time, please see here:

https://opensourceebikefirmware.bitbuck ... gnals.html

---
I got one S06P controller today and compared to S06S controller:

The S06P controller don't do sine wave motor control but just 6 steps. When compared to the S06S controller:
• don't have the phase current sensor (the place is on the board but is empty)
• have a secondary board that connects to the same pins as hall sensors:
◇ have a STM8S003F3P6 (with available header to be programmed)
◇ have an LM339
◇ I would say this board does BEMF signal output to simulate the hall sensors signal, just like on the KU63 controller circuit

See the pictures here: https://opensourceebikefirmware.bitbuck ... -S06P.html
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby casainho » Wed May 24, 2017 10:18 am

Got the ADC (pooling for now) working, reading throttle value.
Also got PWM working (PWM symetric to come) and duty_cycle value is defined by throttle value:

Code: Select all
int main()
{
  //set clock at the max 16MHz
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

  gpio_init ();
  brake_init ();

  // hold here while brake is pressed -- this is a protection for development
  while (!brake_is_set()) ;

  uart_init ();
  hall_sensor_init ();
  pwm_init ();
  adc_init ();
  enableInterrupts();

  while (1)
  {
    static uint16_t adc_value;
    adc_value = adc_read_throttle ();
    pwm_set_duty_cycle_channel1 (adc_value);
    pwm_set_duty_cycle_channel2 (adc_value);
    pwm_set_duty_cycle_channel3 (adc_value);
  }
}


Next I need to put PWM working symmetric and adding the dead-time. Then I will have all the tools to run the motor:
- hall sensors working
- PWM working
- throttle working
Last edited by casainho on Wed May 24, 2017 10:20 am, edited 1 time in total. View post history.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby Steu851 » Wed May 24, 2017 10:27 am

Good work! Thank you!
Please don't forget PAS sensor, trottle is not legal in Europe.


Sent usingTapatalk
Steu851
1 mW
1 mW
 
Posts: 12
Joined: Mon Nov 07, 2016 10:52 am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby casainho » Wed May 24, 2017 10:41 am

Steu851 wrote:Good work! Thank you!
Please don't forget PAS sensor, trottle is not legal in Europe.

It is far to be finished, as for be with the same quality as original firmware, I need to look at phase sensor current and find a way to adapt it to be synchronize with rotor position (hall sensors signal).

I don't use PAS, maybe you can help if you say what could be the algorithm for PAS. I know that PAS is connected to a digital only input pin to the STM8, so firmware will only be able to read it as being ON or OFF state.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby Steu851 » Wed May 24, 2017 11:21 am

PAS a hall sensor, used to know if pedals are tuning, one feature not present in the original firmware nice to have is to enable trottle only if pedals are tuning, always, not only when starting, we are used to call this feature 'gas legalizer'.
All legal ebike here doesn't have trottle at all, we can choose motor assistance only from display.
I apologize for my bad english.

Sent usingTapatalk
Steu851
1 mW
1 mW
 
Posts: 12
Joined: Mon Nov 07, 2016 10:52 am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby casainho » Fri May 26, 2017 7:41 am

Got the motor running!! But for now just as 6 steps (the same as KU63, JUxx controllers), just like the original firmware does when starts the motor and run it at very low speeds, before commutate to sinewave.
As you can see on the video, throttle and brake works. I didn't implement any current control yet, I think I will leave that to the end of the project while I am running with a lab power supply.

Project documentation here: https://opensourceebikefirmware.bitbuck ... oject.html

Firmware sources: https://github.com/OpenSource-EBike-fir ... s_firmware



The code as of today:

Code: Select all
int main()
{
  //set clock at the max 16MHz
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

  gpio_init ();
  brake_init ();
  while (brake_is_set()) ; // hold here while brake is pressed -- this is a protection for development
  uart_init ();
  hall_sensor_init ();
  pwm_init ();
  adc_init ();
  enableInterrupts();

  hall_sensors_read_and_action (); // needed to start the motor

  while (1)
  {
    static uint16_t adc_value;
    adc_value = adc_read_throttle ();
    adc_value = map (adc_value, ADC_THROTTLE_MIN_VALUE, ADC_THROTTLE_MAX_VALUE, 0, 1023);
    pwm_value = adc_value;

    pwm_set_duty_cycle_channel1 (pwm_value);
    pwm_set_duty_cycle_channel2 (pwm_value);
    pwm_set_duty_cycle_channel3 (pwm_value);
  }
}

// HALL SENSORS signal
void EXTI_PORTE_IRQHandler(void) __interrupt(EXTI_PORTE_IRQHANDLER)
{
  hall_sensors_read_and_action ();
}

void hall_sensors_read_and_action (void)
{
  unsigned char hall_sensors = 0;

  // read hall sensors signal pins and mask other pins
  hall_sensors = (GPIO_ReadInputData (HALL_SENSORS__PORT) & (HALL_SENSORS_MASK));

  switch (hall_sensors)
  {
    case 3:
      pwm_phase_a_enable_pwm ();
      pwm_phase_b_disable ();
      pwm_phase_c_enable_low ();

    break;

    case 1:
      pwm_phase_a_enable_pwm ();
      pwm_phase_b_enable_low ();
      pwm_phase_c_disable ();
    break;

    case 5:
      pwm_phase_a_disable ();
      pwm_phase_b_enable_low ();
      pwm_phase_c_enable_pwm ();
    break;

    case 4:
      pwm_phase_a_enable_low ();
      pwm_phase_b_disable ();
      pwm_phase_c_enable_pwm ();
    break;

    case 6:
      pwm_phase_a_enable_low ();
      pwm_phase_b_enable_pwm ();
      pwm_phase_c_disable ();
    break;

    case 2:
      pwm_phase_a_disable ();
      pwm_phase_b_enable_pwm ();
      pwm_phase_c_enable_low ();
    break;

    default:
    return;
    break;
  }
}
Last edited by casainho on Fri May 26, 2017 7:43 am, edited 1 time in total. View post history.
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby Steu851 » Fri May 26, 2017 8:12 am

Awsome

Sent usingTapatalk
Steu851
1 mW
1 mW
 
Posts: 12
Joined: Mon Nov 07, 2016 10:52 am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby casainho » Fri Jun 02, 2017 12:42 am

While trying to run the motor with a more advanced control scheme that original firmware does (a scheme that is used with FOC motor control) I found some issues that I tough could be because of motor and started this thread: viewtopic.php?f=2&t=88651

The questions are: why the original firmware of S06S (sinewave) controller makes the motor rotating with more noise, takes more current and the power supply voltage increases when a more simple way to run the motor with 6 steps (my OpenSource firmware) make less noise, uses less current and the power supply voltage don't change as expected????
And another way to control that I am trying with my OpenSource firmware, that is even more advanced than sinewave, gives even much more noise, takes much more current and increases much more the power supply voltage!!

I have some clues. The mosfet drivers are called "inverter" and as on DC-DC converters, the inverter can boost the voltage make it much more bigger than input voltage. The 6 steps uses PWM ON and the low side mosfets are always ON/OFF with no PWM. The other modes like sinewave have PWM in low side mosfets... I think the issue is a wrong dead time between high side mosfets and low side, that short circuit the motor windings or mosfets a bit and that will boost the voltage (thanks also to the capacitors on the board) but also asks more current from the power supply and will make the noise on the motor.

I will try to play with the dead time configuration on the firmware/microcontroller but I don't know what are the limitations of the board/mosfet drivers...

I already measured the dead time of original firmware:
Image

Image

More info here: https://opensourceebikefirmware.bitbuck ... gnals.html
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby KingQueenWong » Fri Jun 02, 2017 8:24 am

20170602149641074759316a7b2dfc4.jpg


How many wires should be connected?My motor failed to rotate. :(
Last edited by KingQueenWong on Fri Jun 02, 2017 8:40 am, edited 3 times in total. View post history.
User avatar
KingQueenWong
10 mW
10 mW
 
Posts: 26
Joined: Sun Dec 18, 2016 7:07 am

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby casainho » Fri Jun 02, 2017 8:33 am

KingQueenWong wrote:How many wires should be connected?My motor failed to rotate. :(

Hi KingQueenWong!! Nice to see you here also!!!

Can you please elaborate a bit more so I can help you?? Like: do you have the same S06S controller? which motor are you using? where you able to flash the firmware??
Developer of OpenSource firmware for EBike BMSBattery S series / Kunteng KT motor controllers:
https://opensourceebikefirmware.bitbucket.io/

Electric Unicycle developer of OpenSource technology:
- 3D printed plastic shell
- simplified schematic of MicroWorks 30B4 board
- firmware for MicroWorks 30B4 board
- Android app for MicroWorks 30B4 board
casainho
1 kW
1 kW
 
Posts: 490
Joined: Mon Feb 14, 2011 2:43 pm

Re: OpenSource firmware BMSBattery Sxxx motor controllers ST

Postby KingQueenWong » Fri Jun 02, 2017 8:49 am

Motor: Q100 rear driving E-bike Hub Motor
Voltage:24V
Power:350W
RPM:328
Hall sensor and sensorless Waterproof

Controller:
S06S 250W Torque Simulation Sine Wave Controller

You can enlarge the pictrue for more connected wires detail.
User avatar
KingQueenWong
10 mW
10 mW
 
Posts: 26
Joined: Sun Dec 18, 2016 7:07 am

Next

Return to Motor Technology

Who is online

Users browsing this forum: stancecoke and 7 guests