TSDZ2 mid drive with 860C, 850C or SW102 displays only -- Flexible OpenSource firmware (Casainho code only)

I did a release for V0.6. The issue of speed is corrected. I tested and the firmware works well as before.

I developed a new feature: now assist levels factor are configured on LCD3. We can also choose how many assist levels:

Code:
3: assist level
 0: number of assist levels: default value: 5. This is the number of available assist levels, max number is 9.
 1: assist level factor: this is the factor (for assist level 1) that is multiplied to the calculated human power that the rider does on the bicycle pedals and will scale the final motor assist level.
 x: assist level factor: factor for assist level x -- same as the previous and repeats for the next assist level.

2 things that are not working that we may look at them in the future:
1. watchdog time is not enabled, the code is commented on motor.c other way seems that the controllers is always resetting... it shouldn't, I don't know why...
2. eeprom_write_if_values_changed ()
// 2018.08.29:
// NOTE: the next code gives a problem with motor, when we exchange assist level on LCD3 and
// all the variables all written to EEPROM. As per datasheet, seems each byte takes ~6ms to be written
// I am not sure the issue is the amount of time...

Next I should focus on implementing walk assist level and the speed limit.Yes, I did read all the messages but I don't have time to answer to all of them. And I will be helping EndlessCadence at the speed limiter: https://github.com/OpenSource-EBike-firmware/TongSheng_TSDZ2_motor_controller_firmware/issues/14
 
I'm back from a quick test ride. Used the latest v0.6 firmware and added my implementation of the speed limiter. Speed on display is very stable and correct now, motor is running smooth (maybe a little jerk when moving from zero?) and speed limiting is working fine. Thanks to all who was helping me with this feature!

There is just one issue: I couldn't get the display to correctly persist my custom speed limit, once in a while or from a reboot it reverted back to 25 km/h! I'm using the latest display firmware.

I'll create a PR for the speed limiter.

Btw: can't seem to get the cadence above 100 RPM. I'm using the 36v motor setting.
 
EndlessCadence said:
I'm back from a quick test ride. Used the latest v0.6 firmware and added my implementation of the speed limiter. Speed on display is very stable and correct now, motor is running smooth (maybe a little jerk when moving from zero?) and speed limiting is working fine. Thanks to all who was helping me with this feature!

There is just one issue: I couldn't get the display to correctly persist my custom speed limit, once in a while or from a reboot it reverted back to 25 km/h! I'm using the latest display firmware.

I'll create a PR for the speed limiter.

Btw: can't seem to get the cadence above 100 RPM. I'm using the 36v motor setting.
I also just implemented speed limit, using the map() function that also create a ramp that decreases, here is my implementation:

Code:
  // calc max battery current
  ui16_max_battery_current = 0;
  if (configuration_variables.ui8_target_battery_max_power_div10 > 0)
  {
    // 1.6 = 1 / 0.625(each adc step for current)
    // 1.6 * 10 = 16
    ui16_max_battery_current = ((uint16_t) configuration_variables.ui8_target_battery_max_power_div10 * 16) / ui16_battery_voltage_filtered;
  }

  // now apply the speed limit
  ui16_max_battery_current = (uint8_t) (map ((uint32_t) ui16_wheel_speed_x10,
         (uint32_t) ((configuration_variables.ui8_wheel_max_speed * 10) - 20),
         (uint32_t) ((configuration_variables.ui8_wheel_max_speed * 10) + 20),
         (uint32_t) ui16_max_battery_current,
         (uint32_t) 0));

  // now let's limit the target battery current to battery max current (use min value of both)
  ui8_battery_target_current = ui8_min (ui8_battery_target_current, ui16_max_battery_current);
  // finally set the target battery current to the current controller
  ebike_app_set_target_adc_battery_max_current (ui8_battery_target_current);

Now I will try on the road.
 
EndlessCadence said:
I'm back from a quick test ride. Used the latest v0.6 firmware and added my implementation of the speed limiter. Speed on display is very stable and correct now, motor is running smooth (maybe a little jerk when moving from zero?) and speed limiting is working fine. Thanks to all who was helping me with this feature!

There is just one issue: I couldn't get the display to correctly persist my custom speed limit, once in a while or from a reboot it reverted back to 25 km/h! I'm using the latest display firmware.

I'll create a PR for the speed limiter.

Btw: can't seem to get the cadence above 100 RPM. I'm using the 36v motor setting.

If you like, I can test it.
Are the only changes in the Ebike.c?

Regards

Dirk
 
Dirkro said:
EndlessCadence said:
I'm back from a quick test ride. Used the latest v0.6 firmware and added my implementation of the speed limiter. Speed on display is very stable and correct now, motor is running smooth (maybe a little jerk when moving from zero?) and speed limiting is working fine. Thanks to all who was helping me with this feature!

There is just one issue: I couldn't get the display to correctly persist my custom speed limit, once in a while or from a reboot it reverted back to 25 km/h! I'm using the latest display firmware.

I'll create a PR for the speed limiter.

Btw: can't seem to get the cadence above 100 RPM. I'm using the 36v motor setting.

If you like, I can test it.
Are the only changes in the Ebike.c?

Regards

Dirk

You can get the complete firmware including the speed limiter here: https://github.com/endlesscadence/TongSheng_TSDZ2_motor_controller_firmware/tree/speed_limiter. Press "clone or download" button and download the zip file.

Keep in mind that the custom speed limit value (e.g. 30 km/h) is sometimes reset to 25 km/h (in my case but can be another speed limit, some previous value is restored?). I believe this has nothing to do with the speed limiter itself but seems to be an issue with the storage of the speed limit value in km/h.
 
I got to 121 cadence this morning on the 36v just set the erps overspeed to 700
if you use config menu 3 (which is now menu 5) you can find which variable is limiting your cadence

Enjoy ;)
 

Attachments

  • IMG_20180830_41284.jpg
    IMG_20180830_41284.jpg
    29.5 KB · Views: 2,949
There are several opinions about the used display in relation with the open source firmware.
Now there is a tiny display on the market, that may have most of the wished features:

Matrix display
programmable
Bluetooth
Tiny

https://bitbucket.org/eggpower/eggriderv2/wiki/Home

Did anyone just try to implement this?

Regards
troebi
 
I did a commit with:
1. speed limiter with reducing linear ramp power
2. implemented BOOST at startup that power for each assist level can be configured on LCD3
3. motor startup when assist level is 0 now do not happens as expected
4. speed reset to 25km/h do no happens anymore

1. just the same concept as EndlessCadence did. It works when we are driving on the bicycle but works very badly with wheel on the air. That's it for something that took only 30m to develop. Much more time is needed for something good.

2. Works but I am implementing now BOOST for a specific duration of time...

4. 25km/h because there was offroad mode implemented. I accepted a contribution from another user that did it. But seems it is not intuitive that we thought was a bug, so I did comment that piece of code until we think in a good implementation.
 
Casainho can you please explain exactly what BOOST does and how is it different to what happens on the older firmware ?
 
troebi said:
There are several opinions about the used display in relation with the open source firmware.
Now there is a tiny display on the market, that may have most of the wished features:

Matrix display
programmable
Bluetooth
Tiny

https://bitbucket.org/eggpower/eggriderv2/wiki/Home

Did anyone just try to implement this?

Regards
troebi


This is the display I recommended, due to ease if update, compact size, price, and quality. It is the SW102 from TOPOLOGY.

I've been in touch with Eggrider for some time, and they are implementing TSDZ2 support.

I'm also buying directly from TOPOLOGY, and they are implementing TSDZ2 support as well as we go over the protocol and requirements.

HOWEVER... These won't be compatible with the open source firmware... I am working on hiring someone to make this display compatible with the open source firmware, or as an alternative, to make the open source firmware compatible with the stock displays/protocol... So we will see how that goes... It's all outside my expertise but I'm determined to make it work!
 
Casainho regarding phase angle advance

"Fortunately, many drive chips, including the LV8811G power MOSFET driver from ON Semiconductor, allow the designer to introduce a phase-angle advance to the sinusoidal drive current to ensure its peak coincides with that of the back EMF. The phase-angle advance is typically set to increase linearly with the input voltage, which determines the motor’s speed (Figure 4)."

Source
https://www.digikey.com.au/en/articles/techzone/2017/jan/why-and-how-to-sinusoidally-control-three-phase-brushless-dc-motors

I think 80 is good at low rpm and around 115 is good at high rpm

Can you point me to where about in the code the advance is happening ??
EDIT
Is this it ?
Code:
ui32_l_x1048576 = 110;

  // calc IwL
  ui32_temp = ui32_i_phase_current_x2 * ui32_l_x1048576;
  ui32_temp *= ui32_w_angular_velocity_x16;
  ui16_iwl_128 = ui32_temp >> 18;

  // calc FOC angle
  ui8_foc_angle = asin_table (ui16_iwl_128 / ui16_e_phase_voltage);

looks like its increasing with phase current right.. Can I just start at 80 and add a factor in there like * 1.6 ?

Also I just noticed on the config menu no.8 FOC angle is 4 and goes to maximum of 9 then at high rpm it goes down to 5. Is this the expected behaviour.. shouldn’t it be going up with speed ?
 
Hi,
I had a test ride with Version 0.6 and the fork including the speed limiter of endless caddence.
Following findings:
- when changing the assistance level, the enginge stops for a moment and restarts.
- The custoomized assistence levels where reset sometimes (I think at power off)
- The speed limiter algorithm is working well on the road, I think "weel on air" is not a refference because the counterforce is missing, you dont need signnificant power at all to spin the weel. On the road you have at least 80 W to keep on going in the flat.

I would like to put on the new version on the road,
I can compile the (actual) motor software , but how do I get the latest LCD ? In the system I find the buggy LCD 0.6 only !

Best Regards

Dirk
 
jbalat said:
Casainho can you please explain exactly what BOOST does and how is it different to what happens on the older firmware ?
This is the idea:

fi7ippo said:
Also on every assist level, the initial boost whenever you start is very high till 6kmh near uncomfortable for me, LCD says more than 300-400w, is so high and dangerous for internal gears I think, especially if you are in an high gear!
It could be more smart to limit at 100-150w till 6kmh if possible! Or better add a configurable startup power limit..
The only way to workaround this was to set the max power on fly every time... not so user friendly!
 
buba said:
Thanks Casainho and other for a great job you are doing with the open source firmware.

I would like to ask if we can program TSDZ2 with power signal on in turbo mode from the begining?

That way we can test it without use of any LCD.
No, it is being developed to use only with LCD3. Although I like that idea, there are difficulties on development to make that working.
 
I developed and corrected the following features/issues (release V0.7):

1. speed limiter with reducing power with a linear ramp
2. implemented STARTUP POWER BOOST (some configurations on LCD3)
3. motor startup when assist level is 0 now do not happens as expected
4. speed reset to 25km/h do no happens anymore

1. just the same concept as EndlessCadence did. It works when we are driving on the bicycle but works very badly with wheel on the air. That's it for something that took only 30m to develop. Much more time is needed for something good.

2. The description from configuration manual: https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/TSDZ2-and-KT-LCD3-advanced-features-with-Flexible-OpenSource-firmwares
Code:
4: startup power boost: boost the initial motor startup
 0: config: default value: 1. 0 to enable power boost only when startup and bicycle wheel = 0; 1 every time pedal cadence or torque sensor are zero.
 1: boost time: default value = 25 (2.5 seconds). 0 to disable startup power boost feature.
 2: assist level boost power: this is the boost power (for assist level 1) in watts. Note that this value is not limited by the Max battery power screen value, it is although limited by the battery max current value.
 x: assist level boost power: this is the boost power for assist level x -- same as the previous and repeats for the next assist level.

4. 25km/h because there was offroad mode implemented. I accepted a contribution from another user that did it. But seems it is not intuitive that we thought was a bug, so I did comment that piece of code until we think in a good implementation.
 
jbalat said:
Casainho regarding phase angle advance
Oh men, I wrote a long and detailed answer but I lost it because of internet bad connection...

Well, I think we should think on implementing field weakening -- I did open and issue so we can focus our discussion there: https://github.com/OpenSource-EBike-firmware/TongSheng_TSDZ2_motor_controller_firmware/issues/28

I think the idea is that we keep FOC working and get the best efficiency possible:

// 36V motor: L = 76uH
// 48V motor: L = 135uH
// ui32_l_x1048576 = 142; // 1048576 = 2^20 | 48V
// ui32_l_x1048576 = 80; // 1048576 = 2^20 | 36V

BUT when we approach the ERPS speed limit (and/or duty_cycle starts decreasing ???), we should adding a phase advance value so we start to loss efficiency but we get more motor speed, over the nominal max speed of 4000RPM/450ERPS.

I think by now you already have some good experience with this values... maybe we can figure out an algorithm to do this. And we can start by something very simple, like doing some iterations (increasing/decreasing of the angle offset until we get the motor_speed_erps we are looking for).
 
Hi,
I have test drive the version (downloaded at 15:30)
But seems to be 0.7, because Boost menue is included.

I!!! found the problem that sometimes the boost did not stop when I release the pedal, sometimes it does. !!! So the bike moved unexpected.
Maybe a threshold may be implemented if the torque is a little drifting.


The default boost for assit level 5 and 6 was 1950w :-?

The speed limiter was working good,

Neverteless I am very happy with this firmware:)
Regards

Dirk
 
One thing more:
at my version, I could not set the boost time!

when switching through the menues
I lost my my complete configuration after restarting the bike.
Is there any hidden default reset funktion?
 
Dirkro said:
One thing more:
at my version, I could not set the boost time!

when switching through the menues
I lost my my complete configuration after restarting the bike.
Is there any hidden default reset funktion?
You are not using the V0.7. I install the V0.7 hex file.
 
casainho said:
buba said:
Thanks Casainho and other for a great job you are doing with the open source firmware.

I would like to ask if we can program TSDZ2 with power signal on in turbo mode from the begining?

That way we can test it without use of any LCD.
No, it is being developed to use only with LCD3. Although I like that idea, there are difficulties on development to make that working.


Hi,

What about with the original firmware, is there a setting I could change to always start in turbo mode? I like to wire a switch for the coaster brake models, and use it without a display or speed sensor, so there is only 1 wire to the battery for a real clean setup.
 
casainho said:
jbalat said:
Casainho regarding phase angle advance
Oh men, I wrote a long and detailed answer but I lost it because of internet bad connection...

Well, I think we should think on implementing field weakening -- I did open and issue so we can focus our discussion there: https://github.com/OpenSource-EBike-firmware/TongSheng_TSDZ2_motor_controller_firmware/issues/28

I think the idea is that we keep FOC working and get the best efficiency possible:

// 36V motor: L = 76uH
// 48V motor: L = 135uH
// ui32_l_x1048576 = 142; // 1048576 = 2^20 | 48V
// ui32_l_x1048576 = 80; // 1048576 = 2^20 | 36V

BUT when we approach the ERPS speed limit (and/or duty_cycle starts decreasing ???), we should adding a phase advance value so we start to loss efficiency but we get more motor speed, over the nominal max speed of 4000RPM/450ERPS.

I think by now you already have some good experience with this values... maybe we can figure out an algorithm to do this. And we can start by something very simple, like doing some iterations (increasing/decreasing of the angle offset until we get the motor_speed_erps we are looking for).

Thank you casainho I know I'm not going mad. I have been testing at greater than 110 cadence and there is some need to ramp the FOC advance to get the motor to spin faster with more power even if it means some field weakening ;)
 
casainho said:
EndlessCadence said:
Maybe I just go back to the previous version of the firmware, but programming the LCD3 again is a major pain :(
Leave the programming header connected on LCD3. Yes, try the version that was working until we figure out what is happening to you.

I just drilled a little hole in case of the lcd and soldered the programming cable to the lcd3.
It works pretty good.


IMG_8707.jpg

View attachment 1
 
Back
Top