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

Hi casainho, I've quickly flashed both your 0.4 hex files. Configuration using LCD3 was easy but motor somehow isn't running great with this software. Display shows a constantly varying speed and there is no way I can get it right with repositioning the speed sensor. The speed sensor hasn't been changed during the update. Do you have any idea what could be wrong? The motor also feels a bit rough now but that can be caused by the varying speed sensor. I've also noticed that the PAS max cadence was 0 by default (on the display).
 
Hi,
maybe the speed limit can be installed:

all in km/h , it is a (hopefuly) similar to the behavior of Bosch & Yamaha :
The factor is 1 0.5km/h under "speedlimit" and goes down to 0 linear until two km/h over the speed limit. Then the factor is =0

Sorry, but the only thing i can programm is Basic...

speed_limit_factor=0.4*((speedlimit+2)-speed)
if speed<(speed_limit-0.5) then speed_limit_factor=1
if speed >(speed_limit+2) then speed_limit_factor=0

output power= temp_power*speed_limit_factor

Regards

Dirk
 
e3s said:
Can be showed the human power in the display instead of the istant power?
Yes!! See here how you can help:

https://github.com/OpenSource-EBike-firmware/TongSheng_TSDZ2_motor_controller_firmware/issues/6
 
Unfortunately I haven't it yet. I have already ordered it... I'm waiting. If it arrives soon I can give my contribute
 
casainho said:
jbalat said:
Casainho and endless cadence I did some more testing and I reduced the foc angle down from 130 to 100 on my 36v

At 100 I still had 110+ cadence but the power was not consistent at 550w it was bouncing between 550 and 475 using level 5 and around 36km/hr.
When you have a good value (after testing), please say. Maybe we can include as an option to get higher cadence.

Will do. I tried FOC 100 on the way in. It felt smooth, power at 32km/hr was still around the 220w mark, but I had the feeling it was holding back a bit (almost like friction somewhere). On my last 100m run at level 5 assist and 550W it could only deliver about 440w so I could not get to 38km/hr. It was very cold <5 deg C. Perhaps battery could not deliver ? Will try again on the way home and see if temperature is a factor.
 
Did you ever solve the hall sensor auto learn stuff and purpose for other code for that matter? Not that I would need it for anything, but just like in TSDZ2 firmware there are a lot of references for the auto learn mode in KZQW22A code, but it's seems to be deliberately ignored. I was also wondering why there is like 1kB worth of unused functions and what was their purpose, as well as some functions that would have done something if the input pin was connected to something. Some of the unused stuff seem to be just like the functions that are actually used, but with small changes.

The most obvious difference I could spot between the two for now was that the serial package has truly been altered, not for this model in general, but this particular device. There's no hidden values for different protocol, just deleted code and some random packet id number :|
 
Hi C++ gurus
firstly the FOC of 105 is working well so give that a try if you have a 36v motor.
This is the minimum FOC value that gives me 550w of power when I have asked for 550w at level 5 assist, >36km/hr
please try for yourself and report back

in motor.c
Code:
  ui32_l_x1048576 = 105;

remember also to boost the max overdrive erps in main.h to get higher cadence
Code:
#define MOTOR_OVER_SPEED_ERPS 700 // motor max speed, protection max value | 30 points for the sinewave at max speed

anyway to the fun stuff..
Im really happy with power delivery from 80 to 90 cadence but I want to try like a power band above 70 cadence.
Anything over 70 cadence I want to multiply in (cadence/70)

Firstly this is the code now in ebike_app.c. I don't know if the logic is correct - please see my comments //JB
Code:
 // cadence percentage (in x256)
  ui16_temp = (((uint16_t) ui8_pas_cadence_rpm) << 8) / ((uint16_t) PAS_MAX_CADENCE_RPM); //JB THIS IS A VALUE FROM 0-1 ?
  // limit the calculated value to be no more than PAS_MAX_CADENCE_RPM x256
  if (ui8_pas_cadence_rpm > PAS_MAX_CADENCE_RPM)
  {
    ui16_temp = ((uint16_t) PAS_MAX_CADENCE_RPM) << 8;   //JB THIS IS A VALUE OF 120 ?
  }

If this is correct then I want to do something like this..
Code:
 // cadence percentage (in x256)
  ui16_temp = (((uint16_t) ui8_pas_cadence_rpm) << 8) / ((uint16_t) PAS_MAX_CADENCE_RPM); 
 //JB
  if (ui8_pas_cadence_rpm > 70)
  {
    ui16_temp = ui16_temp * ui_pas_cadence_rpm / 70
  }
  // limit the calculated value to be no more than PAS_MAX_CADENCE_RPM x256
  if (ui8_pas_cadence_rpm > PAS_MAX_CADENCE_RPM)
  {
    ui16_temp = ((uint16_t) PAS_MAX_CADENCE_RPM) << 8;   //JB THIS IS A VALUE OF 120 ?
  }
 
I installed as discribes, path where set.

EndlessCadence said:
Hi Dirk, compiling the code isn't hard at all. I've made some fixes in the makefile for compiling on Windows, those changes are already in the latest master branch of the project.

1. Install SDCC (https://sourceforge.net/projects/sdcc/files/sdcc-win64/3.6.0/). Make sure to add it to your PATH (option in one of the last screens of the installer... )....
.......
4. Double-click Start_Compiling.bat to compile the firmware. The resulting main.ihx can be programmed in the controller.

I did not get anything out, a lot of Error Messages


Warning: Non-connected liverange found and extended to connected component of th
e CFG:iTemp44. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out
-fmt-ihx --debug -outils.c utils.c
sdcc -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fm
t-ihx --debug main.c StdPeriphLib/src/stm8s_iwdg.rel StdPeriphLib/src/stm8s_itc
.rel StdPeriphLib/src/stm8s_clk.rel StdPeriphLib/src/stm8s_gpio.rel StdPeriphLib
/src/stm8s_uart2.rel StdPeriphLib/src/stm8s_tim1.rel StdPeriphLib/src/stm8s_tim2
.rel StdPeriphLib/src/stm8s_tim3.rel StdPeriphLib/src/stm8s_exti.rel StdPeriphLi
b/src/stm8s_adc1.rel StdPeriphLib/src/stm8s_flash.rel watchdog.rel torque_sensor
.rel uart.rel pwm.rel motor.rel wheel_speed_sensor.rel brake.rel pas.rel adc.rel
timers.rel ebike_app.rel utils.rel
main.c:122: warning 126: unreachable code
Warning: Non-connected liverange found and extended to connected component of th
e CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of th
e CFG:iTemp0. Please contact sdcc authors with source code to reproduce.

?ASlink-Warning-Undefined Global '_eeprom_init_variables' referenced by module '
ebike_app'

?ASlink-Warning-Undefined Global '_eeprom_init' referenced by module 'main'
make: *** [main] Error 1

C:\Temp\TSDZ2\TongSheng_TSDZ2_motor_controller_firmware-master>pause
Drücken Sie eine beliebige Taste . . .


Do I need something more than SDCC ?
Maybe libaries?

Regards

Dirk
 
Dirkro said:
Do I need something more than SDCC ?

You need SDCC3.7.0 or higher. See the exe-files (not the upper link with the green button!).
https://sourceforge.net/projects/sdcc/files/snapshot_builds/x86_64-w64-mingw32-setup/

see the german tutorial also ;):
https://www.pedelecforum.de/wiki/doku.php?id=elektrotechnik:eek:pen_source_firmware_einrichtung_software

regards
stancecoke
 
EndlessCadence said:
Hi casainho, I've quickly flashed both your 0.4 hex files. Configuration using LCD3 was easy but motor somehow isn't running great with this software. Display shows a constantly varying speed and there is no way I can get it right with repositioning the speed sensor. The speed sensor hasn't been changed during the update. Do you have any idea what could be wrong? The motor also feels a bit rough now but that can be caused by the varying speed sensor. I've also noticed that the PAS max cadence was 0 by default (on the display).
I just tested again and found that issue with the wheel speed. And found that I did a small mistake. As for motor, my seems to run just fine!! Can you test to flash again the firmware and make sure you configured correctly the parameter for 36/48V motor?? (that was the only thing I changed about the motor).
About the PAS max cadence, I just verified (after erase the EEPROM) and I got as default value 110 as expected.

Maybe you need to erase your EEPROM before flashing....

I just uploaded the V0.5 with the corrections for wheel speed.
 
mutetus said:
Did you ever solve the hall sensor auto learn stuff and purpose for other code for that matter? Not that I would need it for anything, but just like in TSDZ2 firmware there are a lot of references for the auto learn mode in KZQW22A code, but it's seems to be deliberately ignored. I was also wondering why there is like 1kB worth of unused functions and what was their purpose, as well as some functions that would have done something if the input pin was connected to something. Some of the unused stuff seem to be just like the functions that are actually used, but with small changes.

The most obvious difference I could spot between the two for now was that the serial package has truly been altered, not for this model in general, but this particular device. There's no hidden values for different protocol, just deleted code and some random packet id number :|
Thanks for sharing!!

No, I don't know about the auto learn of hall sensor connections. But I understand the original firmware implementation is different about the hall sensors.
I wounder how with only 16kbytes of flash memory, they still have code using part of that very limited space and is not used!!

My guess, with all this information, is that the code is kind of generic (maybe they bought from someone?? maybe from Kunteng as it uses the same STM8??) and they just adapted to their custom LCD and board. Also, I still think the original firmware does not implement FOC.
 
jbalat said:
Hi C++ gurus
firstly the FOC of 105 is working well so give that a try if you have a 36v motor.
The firmware is in C code, not C++. With C++ would be very different...

And I put your information on the motor.c file, as comments, so we don't lost this!!!

jbalat said:
ui16_temp = (((uint16_t) ui8_pas_cadence_rpm) << 8) / ((uint16_t) PAS_MAX_CADENCE_RPM); //JB THIS IS A VALUE FROM 0-1 ?
<<8 is equal to * 256. >>8 is equal to /256. So that value is from 0 to 255!!

jbalat said:
ui16_temp = ui16_temp * ui_pas_cadence_rpm / 70
I would make instead: ui16_temp = (ui16_temp * ui_pas_cadence_rpm) / 70;

And there is no more PAS_MAX_CADENCE_RPM, now it is a value you setup on LCD3.
 
Dirkro said:
I did not get anything out, a lot of Error Messages
If I understand correctly, you just want to configure your motor to be 36V, right? If so, you can now choose it on LCD3, no more need to build the firmware.
See here: https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/TSDZ2-and-KT-LCD3-advanced-features-with-Flexible-OpenSource-firmwares
 
stancecoke said:
Dirkro said:
Do I need something more than SDCC ?

You need SDCC3.7.0 or higher. See the exe-files (not the upper link with the green button!).
https://sourceforge.net/projects/sdcc/files/snapshot_builds/x86_64-w64-mingw32-setup/

see the german tutorial also ;):
https://www.pedelecforum.de/wiki/doku.php?id=elektrotechnik:eek:pen_source_firmware_einrichtung_software

regards
stancecoke

Most of the errors are gone,
only one:

but I downloaded V0.4 this morning.
Maybe it was a problem during change to 0.5?



ebike_app.c:351: warning 116: left shifting more than size of object changed to
zero
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out
-fmt-ihx --debug -outils.c utils.c
sdcc -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fm
t-ihx --debug main.c StdPeriphLib/src/stm8s_iwdg.rel StdPeriphLib/src/stm8s_itc
.rel StdPeriphLib/src/stm8s_clk.rel StdPeriphLib/src/stm8s_gpio.rel StdPeriphLib
/src/stm8s_uart2.rel StdPeriphLib/src/stm8s_tim1.rel StdPeriphLib/src/stm8s_tim2
.rel StdPeriphLib/src/stm8s_tim3.rel StdPeriphLib/src/stm8s_exti.rel StdPeriphLi
b/src/stm8s_adc1.rel StdPeriphLib/src/stm8s_flash.rel watchdog.rel torque_sensor
.rel uart.rel pwm.rel motor.rel wheel_speed_sensor.rel brake.rel pas.rel adc.rel
timers.rel ebike_app.rel utils.rel
main.c:122: warning 126: unreachable code

?ASlink-Warning-Undefined Global '_eeprom_init_variables' referenced by module '
ebike_app'

?ASlink-Warning-Undefined Global '_eeprom_init' referenced by module 'main'
make: *** [main] Error 1

C:\Temp\TSDZ2\TongSheng_TSDZ2_motor_controller_firmware-master>pause
Drücken Sie eine beliebige Taste . . .
 
stancecoke
is there an easy way to check which version I have installed ?

BTW guys can you please help with the code on my last post ?
 
HI!
with the 0.5 I was able to get a "main.ihx" This is the firmware for the motor isnt it?
Regards

Dirk
 
Dirkro said:
HI!
with the 0.5 I was able to get a "main.ihx" This is the firmware for the motor isnt it?
Regards

Dirk

yes.

Somebody has deleted the flash command from "my" start_compiling.bat :-(
Why open an additional program, search for the right hex-file and press buttons, if all of that ran completely automatically?! :shock:

regards
stancecoke
 
Dirkro said:
HI!
with the 0.5 I was able to get a "main.ihx" This is the firmware for the motor isnt it?
Regards

Dirk
Follow this guide to flash the firmware and flash the V0.5: https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/How-to-install-the-Flexible-OpenSource-firmware

You don't need to build the firmware. Just follow that guide.
 
stancecoke said:
Somebody has deleted the flash command from "my" start_compiling.bat :-(
Why open an additional program, search for the right hex-file and press buttons, if all of that ran completely automatically?! :shock:
I accepted a pull request that did that. I guess the thing is that there is missing a guide for Windows....
 
casainho said:
stancecoke said:
Somebody has deleted the flash command from "my" start_compiling.bat :-(
Why open an additional program, search for the right hex-file and press buttons, if all of that ran completely automatically?! :shock:
I accepted a pull request that did that. I guess the thing is that there is missing a guide for Windows....

Stancecoke my version is 3.6.9 thanks sounds like i should upgrade

Also I am keeping your compile.bat version with the flash routine. It saves me so much time since I have been making changes and flashing many times a day during my testing :D

Casainho thanks for looking at my code. Looks like I need to learn C not C++
 
casainho said:
guide to flash the firmware and flash the V0.5: https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/How-to-install-the-Flexible-OpenSource-firmware

You don't need to build the firmware. Just follow that guide.
You are so kind!


I know,
It is so good to to play with the parameters myself a bit!
For instance for me the lower support levels where much too high.
Because want to be able to save batterie and more input from myself and get a range of >70 km from my 36 V, 11A Batterie!
I decreased to 0.4, 0.8, 1.5, 3.0, 6.0
Furthermore want to play a bit with the parameters for candence
And my batterie is not first quality, So I need to decrease the voltage level at 80-20%

I will try to get my ols fashened torque wrench (with a analog scale) back which I can put on the pedal screw. Then you will get a good estimate for the torque sensor calibration and human power. What is the maximum of this value ?

Thanks and regards

Dirk
 
Dirkro said:
I will try to get my ols fashened torque wrench (with a analog scale) back which I can put on the pedal screw. Then you will get a good estimate for the torque sensor calibration and human power. What is the maximum of this value ?
I don't know the max value, I think it may depend. Please take note of min value at 0 force as also max value.

I wounder if the different TSDZ2 rotation on bicycle frame for every user will make an expressive difference...
 
casainho said:
stancecoke said:
Somebody has deleted the flash command from "my" start_compiling.bat :-(
Why open an additional program, search for the right hex-file and press buttons, if all of that ran completely automatically?! :shock:
I accepted a pull request that did that. I guess the thing is that there is missing a guide for Windows....
I did that, sorry guys :D We can restore this of course, but I hate to have a file called Start_Compiling which also flashes the firmware (in my case unintended) :shock:

@stancecoke, you do not maintain this code anymore, do you? Besides, I don't know which code is yours or others and what can be modified and what not. That's where a pull request is for, there we can decide whether we want the changes in the master branch...

As for Windows instructions, I've posted this before and we should add something like this to the wiki:
EndlessCadence said:
Hi Dirk, compiling the code isn't hard at all. I've made some fixes in the makefile for compiling on Windows, those changes are already in the latest master branch of the project.

1. Install SDCC (https://sourceforge.net/projects/sdcc/files/sdcc-win64/3.6.0/). Make sure to add it to your PATH (option in one of the last screens of the installer... )
2. Git clone the project or download zip file: https://github.com/OpenSource-EBike-firmware/TongSheng_TSDZ2_motor_controller_firmware (make sure to get the master branch)
3. Use any text editor to make the desired firmware changes. Also take note of the motor type you're using (36v/48v).
4. Double-click Start_Compiling.bat to compile the firmware. The resulting main.ihx can be programmed in the controller.
 
casainho said:
EndlessCadence said:
Hi casainho, I've quickly flashed both your 0.4 hex files. Configuration using LCD3 was easy but motor somehow isn't running great with this software. Display shows a constantly varying speed and there is no way I can get it right with repositioning the speed sensor. The speed sensor hasn't been changed during the update. Do you have any idea what could be wrong? The motor also feels a bit rough now but that can be caused by the varying speed sensor. I've also noticed that the PAS max cadence was 0 by default (on the display).
I just tested again and found that issue with the wheel speed. And found that I did a small mistake. As for motor, my seems to run just fine!! Can you test to flash again the firmware and make sure you configured correctly the parameter for 36/48V motor?? (that was the only thing I changed about the motor).
About the PAS max cadence, I just verified (after erase the EEPROM) and I got as default value 110 as expected.

Maybe you need to erase your EEPROM before flashing....

I just uploaded the V0.5 with the corrections for wheel speed.
Fantastic! Will try again when I have the time... :D
 
Back
Top