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

Can anyone please give me some advice on how to properly set up the UART communication between LCD and Motor in order to include the 2 additional parameters for eMTB mode?

1. on controller side, I added and using the two following variables defined in ebike_app.h:
Code:
typedef struct
{
  uint16_t ui16_assist_level_factor_x1000;
 ....
  uint8_t ui8_battery_current_min_adc;
  uint8_t ui8_eMTB_factor;		// <-- NEW
  uint8_t ui8_eMTB_exponential; 	// <-- NEW
} struct_config_vars;

while on LCD side I also included the two variables in rt_vars and ui_vars:

Code:
typedef struct rt_vars_struct {
	uint16_t ui16_adc_battery_voltage;
	...
  	uint8_t ui8_street_mode_throttle_enabled;
  	uint8_t ui8_eMTB_factor;		// <-- NEW
  	uint8_t ui8_eMTB_exponential;		// <-- NEW
} rt_vars_t;

Code:
typedef struct ui_vars_struct {
	uint16_t ui16_adc_battery_voltage;
	...
	uint8_t ui8_street_mode_throttle_enabled;
	uint8_t ui8_eMTB_factor;		// <-- NEW
	uint8_t ui8_eMTB_exponential;		// <-- NEW
  	uint16_t var_speed_graph_auto_max_min;
  	...
  	uint8_t var_motor_foc_threshold_min;
} ui_vars_t;

I then added two additional entries in configscreen.c:
Code:
static Field assistMenus[] =
{
FIELD_EDITABLE_UINT(_S("Num assist levels", "Num Levels"), &ui_vars.ui8_number_of_assist_levels, "", 1, 20),
FIELD_EDITABLE_UINT("Level 1", &ui_vars.ui16_assist_level_factor[0], "", 1, 65535, .div_digits = 3),
...
FIELD_EDITABLE_UINT("Level 20", &ui_vars.ui16_assist_level_factor[19], "", 1, 65535, .div_digits = 3),
FIELD_EDITABLE_UINT(_S("eMTB exponential", "eMTB exp"), &ui_vars.ui8_eMTB_exponential, "", 1, 3),	// <-- NEW
FIELD_EDITABLE_UINT(_S("eMTB factor", "eMTB factor"), &ui_vars.ui8_eMTB_factor, "", 1, 100),		// <-- NEW
FIELD_END };

I also updated the EEPROM configurations for ui_vars in order to load the defaults and then store the new settings.
finally in state.c I copy the values of ui_vars to rt_vars:

Code:
void copy_rt_to_ui_vars(void) {
ui_vars.ui16_adc_battery_voltage = rt_vars.ui16_adc_battery_voltage;
...
rt_vars.ui8_street_mode_throttle_enabled = ui_vars.ui8_street_mode_throttle_enabled;  
rt_vars.ui8_eMTB_factor = ui_vars.ui8_eMTB_factor;		// <-- NEW
rt_vars.ui8_eMTB_exponential = ui_vars.ui8_eMTB_exponential;	// <-- NEW
}

So I think I am now ready to send and receive the two additional variables to the controller over UART. what is the proper method in order not to break the communication interface?
thanks a lot
Silvio
 
silvocross said:
Can anyone please give me some advice on how to properly set up the UART communication between LCD and Motor in order to include the 2 additional parameters for eMTB mode?

1. on controller side, I added and using the two following variables defined in ebike_app.h:
Code:
typedef struct
{
  uint16_t ui16_assist_level_factor_x1000;
 ....
  uint8_t ui8_battery_current_min_adc;
  uint8_t ui8_eMTB_factor;		// <-- NEW
  uint8_t ui8_eMTB_exponential; 	// <-- NEW
} struct_config_vars;

while on LCD side I also included the two variables in rt_vars and ui_vars:

Code:
typedef struct rt_vars_struct {
	uint16_t ui16_adc_battery_voltage;
	...
  	uint8_t ui8_street_mode_throttle_enabled;
  	uint8_t ui8_eMTB_factor;		// <-- NEW
  	uint8_t ui8_eMTB_exponential;		// <-- NEW
} rt_vars_t;

Code:
typedef struct ui_vars_struct {
	uint16_t ui16_adc_battery_voltage;
	...
	uint8_t ui8_street_mode_throttle_enabled;
	uint8_t ui8_eMTB_factor;		// <-- NEW
	uint8_t ui8_eMTB_exponential;		// <-- NEW
  	uint16_t var_speed_graph_auto_max_min;
  	...
  	uint8_t var_motor_foc_threshold_min;
} ui_vars_t;

I then added two additional entries in configscreen.c:
Code:
static Field assistMenus[] =
{
FIELD_EDITABLE_UINT(_S("Num assist levels", "Num Levels"), &ui_vars.ui8_number_of_assist_levels, "", 1, 20),
FIELD_EDITABLE_UINT("Level 1", &ui_vars.ui16_assist_level_factor[0], "", 1, 65535, .div_digits = 3),
...
FIELD_EDITABLE_UINT("Level 20", &ui_vars.ui16_assist_level_factor[19], "", 1, 65535, .div_digits = 3),
FIELD_EDITABLE_UINT(_S("eMTB exponential", "eMTB exp"), &ui_vars.ui8_eMTB_exponential, "", 1, 3),	// <-- NEW
FIELD_EDITABLE_UINT(_S("eMTB factor", "eMTB factor"), &ui_vars.ui8_eMTB_factor, "", 1, 100),		// <-- NEW
FIELD_END };

I also updated the EEPROM configurations for ui_vars in order to load the defaults and then store the new settings.
finally in state.c I copy the values of ui_vars to rt_vars:

Code:
void copy_rt_to_ui_vars(void) {
ui_vars.ui16_adc_battery_voltage = rt_vars.ui16_adc_battery_voltage;
...
rt_vars.ui8_street_mode_throttle_enabled = ui_vars.ui8_street_mode_throttle_enabled;  
rt_vars.ui8_eMTB_factor = ui_vars.ui8_eMTB_factor;		// <-- NEW
rt_vars.ui8_eMTB_exponential = ui_vars.ui8_eMTB_exponential;	// <-- NEW
}

So I think I am now ready to send and receive the two additional variables to the controller over UART. what is the proper method in order not to break the communication interface?
thanks a lot
Silvio
So, first you should add them to ui and rt vars as you did, as also to EEPROM so they will be saved.

Them go to configurations and add a menu for emtb and add there that 2 new configurations.

As this 2 new variables need to be configured only on configurations menu, they can be added to configurations UART package. This package is sent to motor controller at system startup on motor init and everytime leaving the configurations menu.

You will need to expand the configurations package, increment the buffers also.
 
casainho said:
So, first you should add them to ui and rt vars as you did, as also to EEPROM so they will be saved.

Them go to configurations and add a menu for emtb and add there that 2 new configurations.

As this 2 new variables need to be configured only on configurations menu, they can be added to configurations UART package. This package is sent to motor controller at system startup on motor init and everytime leaving the configurations menu.

You will need to expand the configurations package, increment the buffers also.

Hi Casainho, thanks for the quick reply. I am adding them to FRAME_TYPE_CONFIGURATIONS as:

Code:
    // eMTB
      ui8_usart1_tx_buffer[80] = rt_vars.ui8_eMTB_factor;		// <-- NEW
      ui8_usart1_tx_buffer[81] = rt_vars.ui8_eMTB_exponential;		// <-- NEW

but I believe I'll have to change the CRC parameters as well?
 
silvocross said:
casainho said:
So, first you should add them to ui and rt vars as you did, as also to EEPROM so they will be saved.

Them go to configurations and add a menu for emtb and add there that 2 new configurations.

As this 2 new variables need to be configured only on configurations menu, they can be added to configurations UART package. This package is sent to motor controller at system startup on motor init and everytime leaving the configurations menu.

You will need to expand the configurations package, increment the buffers also.

Hi Casainho, thanks for the quick reply. I am adding them to FRAME_TYPE_CONFIGURATIONS as:

Code:
    // eMTB
      ui8_usart1_tx_buffer[80] = rt_vars.ui8_eMTB_factor;		// <-- NEW
      ui8_usart1_tx_buffer[81] = rt_vars.ui8_eMTB_exponential;		// <-- NEW

but I believe I'll have to change the CRC parameters as well?
Now you only need to increment ui8_usart1_tx_buffer size as also increment the Len of the package as the crc will be done for the package len.
 
casainho said:
Now you only need to increment ui8_usart1_tx_buffer size as also increment the Len of the package as the crc will be done for the package len.

Thank you very much, with the suggested changes the communication is now properly working.
So the status from my side:
1. In the Level assist configuration menu there are now 2 additional fields: eMTB Factor (1-100) and eMTB Exponential (1-3)
2. Choosing eMTB Exponential == 1 (default), the motor current delivery will be proportional to the human power as standard.
3. Choosing eMTB Exponential == 2, a quadratic factor will be added to the standard calculation
4. Choosing eMTB Exponential == 3, a cubic factor will be added to the standard calculation
5. eMTB factor is used to scale up or down the added contribution.
I will now perform some tests in order to find a good default parameter configuration and then post the files, in case anyone will like to perform some beta testing.
 
Nfer said:
ilu said:
phm2000 said:
...

Are you sure?

I asked Eco Ebike about the bluetooth update of their SW102 display on January and they told me:

"The initial OSF upload by Bluetooth is not available yet. It is still a work in progress. For now, you have to open it, and do it manually. We recommend using the OSF 850c until the Bluetooth OSF update is available for the SW102, and then you can swap displays."
i follow the thread from time to time and if i understand and remember it correctly, geeksville was working on it in the past. A first test version didn't work though and after that geeksville was privately busy for some time and then apparently lost interest in the project and hasn't been developed since the end of last year.

But like I said, maybe I remember it wrong
 
Hi Group,

Can someone explain the theory of operation for throttle? Is the throttle current limited by the current PAS level setting? Is it affected by the boost settings?

Is it possible to use the throttle as a direct motor current control override regardless of current PAS level or boost settings?
 
I was curious about the latest beta and after flashing, i just get an error on the display: e:brakes

I do have brake sensors installed, but did not have any issues before the new beta firmware. Is it possible to go back a rev with SW102?

Thanks!
SC
 
gatorsean said:
I was curious about the latest beta and after flashing, i just get an error on the display: e:brakes

I do have brake sensors installed, but did not have any issues before the new beta firmware. Is it possible to go back a rev with SW102?
I think that is because a motor wrong firmware version. For some reason that error is wrong in the beta version as it was corrected on previous version.
 
Field weakening: increase motor speed / pedal cadence over battery voltage limit

I think I know how to increase the motor torque / motor speed / pedal cadence when it currently reduces when approaching the 90 pedal cadence / motor speed 4000 RPM (considering a 48V battery and 48V motor or 36V battery and 36V motor).

The motor is always acting as a generator and the higher the speed the more voltage it generates - and this voltage has inverse polarity / opposes to the battery voltage.
At nominal speed of 4000 RPM, the motor generates the same 48V as the battery voltage, meaning that at 4000 RPM there is no current being absorbed by the motor, so no power - that is why we see motor absorbing less and less power near the 90 cadence / motor 4000 RPM.

Field weakening is a way to reduce the voltage that the motor generates and that way it can rotate faster than the 4000 RPM, still absorb current from the battery and produce torque. There is a catch, on this state the amount of torque it produces per current amp is now less, depends on the motor but can be something like need 2 times more current to produce the same amount of torque, this means it is highly inefficient and will heat the motor faster!! - still, may be good to have this extra motor speed / motor torque near a and over the 90 pedal cadence RPM for short periods. And I hope to have a configuration on display to enable / disable field weakening as also enable up to also only 100 pedal cadence or other value, as also to show the amount of battery energy used by Km so user will be able carefully choose what fits for his riding style, battery range optimization or max torque over full cadence range.

The best way to have higher cadence is clearly to have a high voltage battery (because it will be the most efficiency possible), and there are users testing a 15S 60V battery on a 48V motor.

How to implement field weakening

NOTE: we already know that field weakening works on TSDZ2 because we already use it on the option experimental high cadence mode BUT this is a quick and dirty solution that is inefficient (for the same power used, lower torque at low cadence values and not the best torque at high cadence).

Looking at this Shane Colton document (as also many others), this is how I implemented FOC on our firmware without field weakening. We use V and IwL to calculate the angle (FOC angle value we can see on the display on technical menu), where V is the battery voltage applied to motor wires, I is the motor phase current, w is the motor speed and L is the motor inductance. The only variables are I and w, this means the FOC angles increases with motor phase current and motor speed:

image.png


And field weakening should be like this:
image.png


My current idea to implement is simple: once the PWM duty-cycle is near max value (means that the voltage applied to motor wires is max, equal to battery voltage) AND motor phase current AND battery current are less than the target / desired values, then increment the FOC angle. The catch here is that amount of target current now has a different factor, can be something like 1.25x, 1.5x or more for the same amount of desired motor torque and here is a graph for some specific motor - note that want to increase the nominal speed by max of 1.34 factor, from cadence 90 RPM to max of 120 RPM (I will start my implementation looking at the increase of motor speed with wheel rotating on the air, small torque needed and then I hope to find a reasonable approximation of the curve for our motors):
image.png
 
casainho said:
Field weakening: increase motor speed / pedal cadence over battery voltage limit

Hi Casainho, very interesting. I'm curious when do you use the cadence over 90rpm? Is it on the steep hills using your lowest gear to climb a hill on your MTB?

I personally stay most of the time at 60-80 rpm as recreational and utility cyclists Wikipedia explains. But I changed the front chainring for the 50t . The original one coming with the TSD2Z is very small and you have to pedal like a hamster to get to 25km/h
My back wheel is only 20inch though...
 
vshitikov said:
casainho said:
Field weakening: increase motor speed / pedal cadence over battery voltage limit

Hi Casainho, very interesting. I'm curious when do you use the cadence over 90rpm? Is it on the steep hills using your lowest gear to climb a hill on your MTB?

I personally stay most of the time at 60-80 rpm as recreational and utility cyclists Wikipedia explains. But I changed the front chainring for the 50t . The original one coming with the TSD2Z is very small and you have to pedal like a hamster to get to 25km/h
My back wheel is only 20inch though...
I use a 52V battery with a 48V motor and usually I get this speeds when riding at city on a road with a a lot of cars then I go as fast as possible because I fell safe at high speeds on this street due to the stress the cars do on me if I go slow:

image.png


I think I like to ride maybe at 90 RPM cadence but at that value I have much less power available, maybe just 200 watts while maybe at 75 RPM I have the full 800W available. And that get's worse as the battery discharge... that is why I would like to have more power / torque at 90 RPM or more... and here the voltage on the same ride as seen on the previous graph, you can see the voltage goes lower a bit when pulling the max power for the 45 or 50 km/h.
I have 27.5 wheels, 40T chain wheel and 11T:

image.png
 
Hi,

I have a friend who has a Specialized Turbo Levo (TL).

It uses a Gramin Edge 1030 GPS. The 1030 has a specific application to connect to the Turbo Levo.

TL connects to Garmin via ANT + and sends the instantaneous engine power and human instantaneous power data to the 1030.

Garmin records data for each activity.

At the end, or during the activity, it is possible to know the average engine power and the average human power.

I also use a Garmin and I have no experience with similar applications for Android smartphone.

I have the following questions to ask the forum.

1 - Which Android applications allow you to show and record activity data. Data such as speed, power, distance, cadence, etc? And also record GPS locations?

2 - What is the format of the activity files? Garmin .FIT file format? GPX format?

3 - Which android applications will allow to develop applications to connect other peripherals, such as cadence sensors, power sensors? etc. Or connect to TSDZ2 firmware? using bluetooth.

Thanks
 
casainho said:
gatorsean said:
I was curious about the latest beta and after flashing, i just get an error on the display: e:brakes

I do have brake sensors installed, but did not have any issues before the new beta firmware. Is it possible to go back a rev with SW102?
I think that is because a motor wrong firmware version. For some reason that error is wrong in the beta version as it was corrected on previous version.

Hi casainho. I flashed the sw102-otaupdate-0.9.0.zip and the TSDZ2-v0.58.0.hex and get this error. Can you tell me which motor firmware to use as this is what was posted together on Github for the Beta.
 
AZUR said:
Hi,

I have a friend who has a Specialized Turbo Levo (TL).

It uses a Gramin Edge 1030 GPS. The 1030 has a specific application to connect to the Turbo Levo.

TL connects to Garmin via ANT + and sends the instantaneous engine power and human instantaneous power data to the 1030.

Garmin records data for each activity.

At the end, or during the activity, it is possible to know the average engine power and the average human power.

I also use a Garmin and I have no experience with similar applications for Android smartphone.

I have the following questions to ask the forum.

1 - Which Android applications allow you to show and record activity data. Data such as speed, power, distance, cadence, etc? And also record GPS locations?

2 - What is the format of the activity files? Garmin .FIT file format? GPX format?

3 - Which android applications will allow to develop applications to connect other peripherals, such as cadence sensors, power sensors? etc. Or connect to TSDZ2 firmware? using bluetooth.

Thanks
I moved from Fitbit watch to Garmin watch recently. Garmin watch broads cast user HR over ANT+ and I would like to have my HR on the 860C display while riding. I think TSDZ2 ESP32 / NRF52 BLE and ANT+ project is a good idea, it can be seen like a gateway in the middle of an ebike motor and display, and that connect to external sensors as also a mobile app. Also the TSDZ2 ESP32 Android app seems to have active development.

Schema.png


Note that:
- seems that there are many bicycle sensors that are only ANT+ and not Bluetooth
- SW102 display does not support ANT, only Bluetooth
- ESP32 board does not support ANT
- Arduino Nano 33 BLE supports ANT+ and Bluetooth and also includes an accelerometer, a gyroscope, and a magnetometer

I think the Arduino Nano 33 BLE is a better choice because it would support the ANT+ sensors and the accelerometer, a gyroscope that could be used to detect hills and increase or decrease motor assist level.

image.png


• nRF52840 Flash 1MB and RAM 256KB, 3.3V
• BLE and ANT+
• accelerometer, a gyroscope, and a magnetometer with 3-axis resolution each
• 45mm x 18mm
 
gatorsean said:
Hi casainho. I flashed the sw102-otaupdate-0.9.0.zip and the TSDZ2-v0.58.0.hex and get this error. Can you tell me which motor firmware to use as this is what was posted together on Github for the Beta.
I tough it would work. I will focus on next version and test that on my side.
 
Just in case anyone is after a tsdz2, pswpower have stock in Europe of 36v units and can deliver in about a week with DHL. Just had two more delivered today for a couple more conversions.
 
casainho said:
gatorsean said:
Hi casainho. I flashed the sw102-otaupdate-0.9.0.zip and the TSDZ2-v0.58.0.hex and get this error. Can you tell me which motor firmware to use as this is what was posted together on Github for the Beta.
I tough it would work. I will focus on next version and test that on my side.

No worries mate. It is with the most sincere respect and appreciation that I want to thank you for your incredible contributions to the community. You should know that your hard work is bringing so much joy and happiness to us during a time when it is needed the most.

Let me know if I can do anything to help you moving forward.
 
vshitikov said:
casainho said:
Field weakening: increase motor speed / pedal cadence over battery voltage limit

Hi Casainho, very interesting. I'm curious when do you use the cadence over 90rpm? Is it on the steep hills using your lowest gear to climb a hill on your MTB?

I personally stay most of the time at 60-80 rpm as recreational and utility cyclists Wikipedia explains. But I changed the front chainring for the 50t . The original one coming with the TSD2Z is very small and you have to pedal like a hamster to get to 25km/h
My back wheel is only 20inch though...

Casainho I am so glad you finally have some time to work on field weakening. Good luck and let me know if there is any way I can help keeping in mind that I still have the ktlcd3

Why do you need to go above 90rpm. It is not a common practice to ride above 80 but if you were overtaking someone or taking a run up to get up a hill or over a jump then the last thing you want to do is have to change up a gear. This way you can keep your power and momentum going until it is a better time to change gears. Hope I explained it well. You will only be above 90 for just a few seconds so even if it is really inefficient it is still a much better option than having to play around with your gears in some circumstances.
 
jbalat said:
Casainho I am so glad you finally have some time to work on field weakening. Good luck and let me know if there is any way I can help keeping in mind that I still have the ktlcd3

Why do you need to go above 90rpm. It is not a common practice to ride above 80 but if you were overtaking someone or taking a run up to get up a hill or over a jump then the last thing you want to do is have to change up a gear. This way you can keep your power and momentum going until it is a better time to change gears. Hope I explained it well. You will only be above 90 for just a few seconds so even if it is really inefficient it is still a much better option than having to play around with your gears in some circumstances.
Yes, I hope to be able to do it and will be last big feature on the project.

And what is the mas cadence RPM for you? Maybe the 125 is to much?
 
casainho said:
And what is the mas cadence RPM for you? Maybe the 125 is to much?

I think 125 would be awesome. Not sure if you saw my last video but I was able to get to 128 with a 36v motor using 14s and high cadence setting and only 115 on 10s which is my normal ride. Currently power drops off quite a bit at these higher speeds so you need to put in lots of effort which is very disappointing. Would be great if power could be maintained for a little longer.
Thanks for your efforts :)
 
jbalat said:
casainho said:
And what is the mas cadence RPM for you? Maybe the 125 is to much?

I think 125 would be awesome. Not sure if you saw my last video but I was able to get to 128 with a 36v motor using 14s and high cadence setting and only 115 on 10s which is my normal ride. Currently power drops off quite a bit at these higher speeds so you need to put in lots of effort which is very disappointing. Would be great if power could be maintained for a little longer.
Thanks for your efforts :)
I saw your video but I don't remember now. But you value 128 max RPM? Do you expect to use it or you think you hit 128 just because was a test but on regular basis you use a lower value?
 
120 rpm cadence over an extended time, is really in that young and very fit rider zone, if we are fitting these engines then I would suspect that the age group and fitness may well be represented by the fact we are fitting engines :D Do we really need to worry too much about the benefits of upper 120's, probably not as most of those young and fit riders will be riding analogue bikes and still keeping up with us.

As previously stated I run 80 - 95 rpm cadence on a regular basis, but age is now meaning 100's are out.
 
Waynemarlow said:
120 rpm cadence over an extended time, is really in that young and very fit rider zone, if we are fitting these engines then I would suspect that the age group and fitness may well be represented by the fact we are fitting engines :D Do we really need to worry too much about the benefits of upper 120's, probably not as most of those young and fit riders will be riding analogue bikes and still keeping up with us.

As previously stated I run 80 - 95 rpm cadence on a regular basis, but age is now meaning 100's are out.
I am interested on this max value of cadence because current 125 value seems a bit high for me and if it can be lower, I expect to increase a bit the efficiency. Like why not 110 instead of 125? From 90 to 110 is already a good increase... or maybe to 115...
 
Back
Top