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

Electric Motors and Controllers
Rafe   10 W

10 W
Posts: 91
Joined: Oct 16 2018 5:56pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by Rafe » Jan 14 2019 10:14am

flufferty wrote:
Jan 14 2019 4:13am
Did anyone try to flash back to stock from the flexible firmware?
I have a 36v motor and a 52v battery, and trying to get back to stock with the 52v-profiles from eyebsickle, left me with the controller thinking the battery is empty. So it wont run. But I used the same profiles before the flexible, successfully.

I made sure to double-check the voltage/amps in eeprom-file before flashing.
Sorry to use this thread but the main question is what do I need to go back to stock from flexible?

1. Flash stock program (-s flash in stm8flash)
2. Flash data eeprom (-s eeprom)

Missing anything?
Do I need to relock or flash the opt?
That's annoying. I lost my original controller firmware settings (52v 750w) but always supposed I could still easily go back to OEM using https://www.eco-ebike.com/blogs/eco-cyc ... romscratch so having read your post I just gave it a try and to my horror the battery voltage only shows one bar and this is a battery charged up to over 58v, no power to motor or light. Has anyone got the original controller firmware for 52v

bart594   100 µW

100 µW
Posts: 7
Joined: Jan 14 2019 3:47pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by bart594 » Jan 14 2019 3:59pm

Rafe wrote:
Jan 14 2019 10:14am

That's annoying. I lost my original controller firmware settings (52v 750w) due to a virus attack but always supposed I could still easily go back to OEM using https://www.eco-ebike.com/blogs/eco-cyc ... romscratch so having read your post I just gave it a try and to my horror the battery voltage only shows one bar and this is a battery charged up to over 58v, no power to motor or light. Perhaps the option byte needs to be reflashed as well then. Has anyone got the original controller firmware for 52v
The same thing.
1 bar on the display and no power after returning back to original firmware...(program and data flashed back from backup)
but i have problem that with open source firmware by marcoq my motor doesn't work too :-(

Kisazul   1 W

1 W
Posts: 53
Joined: Jun 18 2018 10:32pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by Kisazul » Jan 15 2019 1:53am

casainho wrote:
Jan 09 2019 1:34pm
New stable flexible OpenSource firmware v0.17.0, get it here: https://github.com/OpenSource-EBike-fir ... ag/v0.17.0

Thanks to all the developers, testers and other contributors!!

Changes from v0.16.x:
KT-LCD3:
- settable odometer
- trip distance function
- TM and TTM time measurement
- imperial units throughout the system
- saved menu state for all menus when power down
- implemented automatic fast increase/decrease of variables on configuration menus
- flashing time on menu number and variables is now short -- it is easier to see the values
Hi casainho, Are these improvements already in the bafang 850c? Could you post a firmware for an 850c screen hex or bin file?

casainho   10 GW

10 GW
Posts: 4361
Joined: Feb 14 2011 2:43pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by casainho » Jan 15 2019 2:51am

Kisazul wrote:
Jan 15 2019 1:53am
casainho wrote:
Jan 09 2019 1:34pm
New stable flexible OpenSource firmware v0.17.0, get it here: https://github.com/OpenSource-EBike-fir ... ag/v0.17.0

Thanks to all the developers, testers and other contributors!!

Changes from v0.16.x:
KT-LCD3:
- settable odometer
- trip distance function
- TM and TTM time measurement
- imperial units throughout the system
- saved menu state for all menus when power down
- implemented automatic fast increase/decrease of variables on configuration menus
- flashing time on menu number and variables is now short -- it is easier to see the values
Hi casainho, Are these improvements already in the bafang 850c? Could you post a firmware for an 850c screen hex or bin file?
It is not working, I am slowly implementing using the design. There is an issue that most times the display communication with TSDZ2 hangs and that is anoying.

I hope next week to start prototype the graph, starting to show human pedal power. And let's see if I figure out the issue with hanging.
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

Kisazul   1 W

1 W
Posts: 53
Joined: Jun 18 2018 10:32pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by Kisazul » Jan 15 2019 3:39am

Good luck in solving the issue, casainho! The power chart will be a very cool thing for this display!

Rafe   10 W

10 W
Posts: 91
Joined: Oct 16 2018 5:56pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by Rafe » Jan 15 2019 12:32pm

bart594 wrote:
Jan 14 2019 3:59pm

The same thing.
1 bar on the display and no power after returning back to original firmware...(program and data flashed back from backup)
but i have problem that with open source firmware by marcoq my motor doesn't work too :-(

Cracked it! It is the Option Byte that needs to be changed back as well. After a lot of messing around swapping between the OEM setup and the Opensource I discovered that the open source firmware changes a couple of lines in the Option Byte even if you only select programme current tab.

I came across this old post by endlesscadence https://endless-sphere.com/forums/viewt ... 0#p1415882
linking to what he believes is the OEM firmware for the 36v controller so I thought nothing to lose by having a go with applying the 36v Option Byte to the 52v OEM firmware and it worked instantly. I didn't bother downloading the hex file which is linked a couple of posts later as the link endlesscadence provides has a photo of the option Byte ST link page, I could see only two lines were different and it was seconds just to change the 2 lines using the drop down menu boxes in the ST visual programmer.

I've now repeated this a couple of times swapping between OEM and Open source firmware systems and no problems to report. It's easy for me as I purchased a HIGO 8 pin extension lead for the LCD3 mod and I can swap over in less than a minute.

(One word of warning though the Controller firmware Casainho has posted alongside LCD3 17.0 opensource firmware does not work and the version posted with version 16.0 should be used.)


Link to OEM programme and data firmware https://drive.google.com/drive/folders/ ... jMrpW2ZqvH
Link to OEM Option Byte photo https://github.com/hurzhurz/tsdz2/blob/ ... onbyte.PNG
Link to Open source firmwares (use 16.0 controller firmware) https://github.com/OpenSource-EBike-fir ... e/releases

dameri   100 W

100 W
Posts: 164
Joined: Sep 20 2018 10:57am

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by dameri » Jan 15 2019 1:13pm

Rafe wrote:
Jan 15 2019 12:32pm
bart594 wrote:
Jan 14 2019 3:59pm

The same thing.
1 bar on the display and no power after returning back to original firmware...(program and data flashed back from backup)
but i have problem that with open source firmware by marcoq my motor doesn't work too :-(

Cracked it! It is the Option Byte that needs to be changed back as well. After a lot of messing around swapping between the OEM setup and the Opensource I discovered that the open source firmware changes a couple of lines in the Option Byte even if you only select programme current tab.

I came across this old post by endlesscadence https://endless-sphere.com/forums/viewt ... 0#p1415882
linking to what he believes is the OEM firmware for the 36v controller so I thought nothing to lose by having a go with applying the 36v Option Byte to the 52v OEM firmware and it worked instantly. I didn't bother downloading the hex file which is linked a couple of posts later as the link endlesscadence provides has a photo of the option Byte ST link page, I could see only two lines were different and it was seconds just to change the 2 lines using the drop down menu boxes in the ST visual programmer.

I've now repeated this a couple of times swapping between OEM and Open source firmware systems and no problems to report. It's easy for me as I purchased a HIGO 8 pin extension lead for the LCD3 mod and I can swap over in less than a minute.

(One word of warning though the Controller firmware Casainho has posted alongside LCD3 17.0 opensource firmware does not work and the version posted with version 16.0 should be used.)


Link to OEM programme and data firmware https://drive.google.com/drive/folders/ ... jMrpW2ZqvH
Link to OEM Option Byte photo https://github.com/hurzhurz/tsdz2/blob/ ... onbyte.PNG
Link to Open source firmwares (use 16.0 controller firmware) https://github.com/OpenSource-EBike-fir ... e/releases
Could it be problem in 52V and 750W motor for firmware does not work? I don't understand. I have 36 V battery and 250 W motor. I've been commuting now two days, not long trips but v17.0 works very well. And it's so good that I'm not going back to stock firmware. Feels just like I have bought new motor which has very much more power.

Rafe   10 W

10 W
Posts: 91
Joined: Oct 16 2018 5:56pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by Rafe » Jan 15 2019 2:28pm

bart594 wrote:
Jan 14 2019 3:59pm



Could it be problem in 52V and 750W motor for firmware does not work? I don't understand. I have 36 V battery and 250 W motor. I've been commuting now two days, not long trips but v17.0 works very well. And it's so good that I'm not going back to stock firmware. Feels just like I have bought new motor which has very much more power.

I think you may have misunderstood me. 17.0 works fine I've done about 150 miles on it now it's just the TSDW2 controller firmware that Casainho has listed with it that seem to be the wrong files, the versions listed with 16,0 work fine and they are supposed to be exactly the same files. The clue is the file sizes and they have changed . It's only a small incidental point that I added out of interest to my post on how to swap between OEM and Opensource controller firmware.
https://github.com/OpenSource-EBike-fir ... e/releases

dameri   100 W

100 W
Posts: 164
Joined: Sep 20 2018 10:57am

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by dameri » Jan 15 2019 2:45pm

Rafe wrote:
Jan 15 2019 2:28pm
bart594 wrote:
Jan 14 2019 3:59pm



Could it be problem in 52V and 750W motor for firmware does not work? I don't understand. I have 36 V battery and 250 W motor. I've been commuting now two days, not long trips but v17.0 works very well. And it's so good that I'm not going back to stock firmware. Feels just like I have bought new motor which has very much more power.

I think you may have misunderstood me. 17.0 works fine I've done about 150 miles on it now it's just the TSDW2 controller firmware that Casainho has listed with it that seem to be the wrong files, the versions listed with 16,0 work fine and they are supposed to be exactly the same files. The clue is the file sizes and they have changed . It's only a small incidental point that I added out of interest to my post on how to swap between OEM and Opensource controller firmware.
https://github.com/OpenSource-EBike-fir ... e/releases
Sorry, yes I did. By the way I'm not bart594 :)

bart594   100 µW

100 µW
Posts: 7
Joined: Jan 14 2019 3:47pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by bart594 » Jan 15 2019 2:55pm

Rafe wrote:
Jan 15 2019 12:32pm

Cracked it! It is the Option Byte that needs to be changed back as well. After a lot of messing around swapping between the OEM setup and the Opensource I discovered that the open source firmware changes a couple of lines in the Option Byte even if you only select programme current tab.

I came across this old post by endlesscadence https://endless-sphere.com/forums/viewt ... 0#p1415882
linking to what he believes is the OEM firmware for the 36v controller so I thought nothing to lose by having a go with applying the 36v Option Byte to the 52v OEM firmware and it worked instantly. I didn't bother downloading the hex file which is linked a couple of posts later as the link endlesscadence provides has a photo of the option Byte ST link page, I could see only two lines were different and it was seconds just to change the 2 lines using the drop down menu boxes in the ST visual programmer.

I've now repeated this a couple of times swapping between OEM and Open source firmware systems and no problems to report. It's easy for me as I purchased a HIGO 8 pin extension lead for the LCD3 mod and I can swap over in less than a minute.

(One word of warning though the Controller firmware Casainho has posted alongside LCD3 17.0 opensource firmware does not work and the version posted with version 16.0 should be used.)


Link to OEM programme and data firmware https://drive.google.com/drive/folders/ ... jMrpW2ZqvH
Link to OEM Option Byte photo https://github.com/hurzhurz/tsdz2/blob/ ... onbyte.PNG
Link to Open source firmwares (use 16.0 controller firmware) https://github.com/OpenSource-EBike-fir ... e/releases
My motor is now working too!
Changing option bytes has done the trick for me
Thx Rafe!
:bigthumb:

Rydon   100 W

100 W
Posts: 252
Joined: Aug 11 2016 5:26pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by Rydon » Jan 15 2019 3:22pm

Rafe wrote:
Jan 15 2019 12:32pm

Cracked it! It is the Option Byte that needs to be changed back as well. After a lot of messing around swapping between the OEM setup and the Opensource I discovered that the open source firmware changes a couple of lines in the Option Byte even if you only select programme current tab.
Nice work! I have seen this issue as well. Are you saying that to go back to the OEM firmware you need to set the option byte to the value in the hurzhurz link? Is it the same for all versions of the OEM firmware? Does this mean that the opensource firmware changes the option byte?

perryscope   100 W

100 W
Posts: 106
Joined: Jan 06 2019 4:29pm
Contact:

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by perryscope » Jan 17 2019 4:30am

Just a word of warning for people making up cables for KT-LCD3 screens. I was received my KT-LCD3 screen today, modified it to add a connector and flashed without issue following the guide. I made the cable up following the guide on the Wiki. https://github.com/OpenSource-EBike-fir ... 3-to-TSDZ2

However, it would not communicate with my motor and refused to switch on?

As this was the first KT-LCD3 screen I had set up, i didn't realise at first that this just meant that it could not communicate with the Motor and thought the flash had not worked. My screen was the style with the long cable and white plug on the end so maybe that's the difference?

It turned out the colour coding on my screen was not the same as the guide in the wiki, specifically, the UART TX and RX colors were swapped

so the guide says..
KT-LCD3 ----- 8 wire (throttle)
red wire ----- blue wire (P+) battery voltage
blue wire ----- red wire Vin
black wire ----- black wire GND ground
green wire ----- brown wire UART TX motor controller
yellow wire ----- yellow wire UART RX motor controller

but my screen was wired...


PIN - KT-LCD3 ----- 8 wire (throttle)
1 red wire ----- blue wire (P+) battery voltage
2 blue wire ----- red wire Vin
3 black wire ----- black wire GND ground
4 yellow wire ----- brown wire UART TX motor controller
5 green wire ----- yellow wire UART RX motor controller

Image

So worth double checking on the PCB before making up the cable.

Not sure if the screen code should error if there is no communication detected?
Empowered people support rider and trustee
www.empoweredpeople.co.uk

thineight   100 W

100 W
Posts: 228
Joined: Oct 05 2018 3:53am

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by thineight » Jan 17 2019 4:12pm

perryscope wrote:
Jan 17 2019 4:30am
Just a word of warning for people making up cables for KT-LCD3 screens. I was received my KT-LCD3 screen today, modified it to add a connector and flashed without issue following the guide. I made the cable up following the guide on the Wiki. https://github.com/OpenSource-EBike-fir ... 3-to-TSDZ2

However, it would not communicate with my motor and refused to switch on?

As this was the first KT-LCD3 screen I had set up, i didn't realise at first that this just meant that it could not communicate with the Motor and thought the flash had not worked. My screen was the style with the long cable and white plug on the end so maybe that's the difference?

It turned out the colour coding on my screen was not the same as the guide in the wiki, specifically, the UART TX and RX colors were swapped

so the guide says..
KT-LCD3 ----- 8 wire (throttle)
red wire ----- blue wire (P+) battery voltage
blue wire ----- red wire Vin
black wire ----- black wire GND ground
green wire ----- brown wire UART TX motor controller
yellow wire ----- yellow wire UART RX motor controller

but my screen was wired...


PIN - KT-LCD3 ----- 8 wire (throttle)
1 red wire ----- blue wire (P+) battery voltage
2 blue wire ----- red wire Vin
3 black wire ----- black wire GND ground
4 yellow wire ----- brown wire UART TX motor controller
5 green wire ----- yellow wire UART RX motor controller

Image

So worth double checking on the PCB before making up the cable.

Not sure if the screen code should error if there is no communication detected?
Interesting, just to complete the picture, could you please post a photo of the actual KTLCD3 white connector with the coloured wires sequence?
Mine for instance has (left to right with metal contacts up):
Yellow
Green
Black
Blue
Red

Thanks
MTB KTM Ultra 29" - City bike DAYTONA 28"

buba   10 kW

10 kW
Posts: 588
Joined: Aug 31 2018 12:36am

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by buba » Jan 17 2019 4:23pm

buba wrote:
Jan 11 2019 1:27pm
This will be a big one…
Another big one…

Here is an update on what I have been working on since my last post. I have read all the feedback!

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

- The Cruise function has its own sub menu in the configuration menu where it is possible to set up Cruise as preferred by user.

- It is now possible to operate Cruise with two modes. The first one simply saves the current speed and maintains it and the other mode is settable: you can enter your target speed and it will get to and maintain that speed. There is a new sub field in the odometer field where the target speed is displayed. Switch between the two modes in the configuration menu.

- Completely new Cruise PID controller code. Smoother in all ranges of speed than my first implementation. It works by controlling the PWM to the motor by a custom made PID controller, tuned for safety for now. Can be made more aggressive but I see no need for that.

- Implemented button debounce on both Cruise and Walk Assist. But during testing this has turned out to be quite dangerous. Even for ultra short moments. I have removed this implementation due to safety. Please test out the functions as is and see how they work out.

- New sub menu in the configuration menu, Main Screen Setup, where the user can tailor the main screen. Enable or disable different sub fields in the odometer field. Future updates will enable users to switch out the time measurement for any other data, such as consumed watt-hours or, as user Dameri mentioned in a question, pedal cadence.

- Updated the Wiki and tried to explain all new functions and how they work. Please take a look and read more there: https://github.com/OpenSource-EBike-fir ... 8.X-(beta)

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

Do note that all this is still in development. I have submitted a pull request and look forward to Casainho testing out the firmware. And with his approval anyone interested or curious can download the beta and test for themselves. Updates and more improvements are coming!

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

Compressed changelog:

- Main Screen Setup
- Walk Assist
- Cruise
- Adjustable acceleration (current ramp up)
- New odometer sub menu: Current, Average and Max speed
- Experimental higher cadence mode
- Updated wiki

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

perryscope   100 W

100 W
Posts: 106
Joined: Jan 06 2019 4:29pm
Contact:

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by perryscope » Jan 17 2019 5:31pm

thineight wrote:
Jan 17 2019 4:12pm
perryscope wrote:
Jan 17 2019 4:30am
Just a word of warning for people making up cables for KT-LCD3 screens. I was received my KT-LCD3 screen today, modified it to add a connector and flashed without issue following the guide. I made the cable up following the guide on the Wiki. https://github.com/OpenSource-EBike-fir ... 3-to-TSDZ2

However, it would not communicate with my motor and refused to switch on?

As this was the first KT-LCD3 screen I had set up, i didn't realise at first that this just meant that it could not communicate with the Motor and thought the flash had not worked. My screen was the style with the long cable and white plug on the end so maybe that's the difference?

It turned out the colour coding on my screen was not the same as the guide in the wiki, specifically, the UART TX and RX colors were swapped

so the guide says..
KT-LCD3 ----- 8 wire (throttle)
red wire ----- blue wire (P+) battery voltage
blue wire ----- red wire Vin
black wire ----- black wire GND ground
green wire ----- brown wire UART TX motor controller
yellow wire ----- yellow wire UART RX motor controller

but my screen was wired...


PIN - KT-LCD3 ----- 8 wire (throttle)
1 red wire ----- blue wire (P+) battery voltage
2 blue wire ----- red wire Vin
3 black wire ----- black wire GND ground
4 yellow wire ----- brown wire UART TX motor controller
5 green wire ----- yellow wire UART RX motor controller

Image

So worth double checking on the PCB before making up the cable.

Not sure if the screen code should error if there is no communication detected?
Interesting, just to complete the picture, could you please post a photo of the actual KTLCD3 white connector with the coloured wires sequence?
Mine for instance has (left to right with metal contacts up):
Yellow
Green
Black
Blue
Red

Thanks
Sure looks the same at the plug end. It works great now I have swapped them on the screen PCB. Has anyone got a photo of the colours on the LCD end? maybe I got an odd one :)
Image
Empowered people support rider and trustee
www.empoweredpeople.co.uk

thineight   100 W

100 W
Posts: 228
Joined: Oct 05 2018 3:53am

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by thineight » Jan 17 2019 6:05pm

perryscope wrote:
Jan 17 2019 5:31pm

Sure looks the same at the plug end. It works great now I have swapped them on the screen PCB. Has anyone got a photo of the colours on the LCD end? maybe I got an odd one :)
Image
Very strange, your LCD3 wires on the board looks exactly the ones that jbalat shown on its video @min 6:55
https://youtu.be/0nXtaJniZQc
before he realized the TX and Rx were wrong. He changed therefore the wiring colours at the end on its paper (see the video @min 7:05) for user not to end up with the same mistake.
He has the 6 wires, same as me, and the paper shows the same configuration in the wiki.
Everything looks consistent to me, at least for the 6 wires motor, can anybody confirm the wirings on the wiki for 6 and 8 wires?
I am about to solder it tomorrow or Saturday.

Thanks..
Last edited by thineight on Jan 17 2019 6:09pm, edited 1 time in total.
MTB KTM Ultra 29" - City bike DAYTONA 28"

Rydon   100 W

100 W
Posts: 252
Joined: Aug 11 2016 5:26pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by Rydon » Jan 17 2019 11:39pm

buba wrote:
Jan 17 2019 4:23pm

Another big one…

Here is an update on what I have been working on since my last post. I have read all the feedback!
...
- Updated the Wiki and tried to explain all new functions and how they work. Please take a look and read more there: https://github.com/OpenSource-EBike-fir ... 8.X-(beta)
...
Compressed changelog:

- Main Screen Setup
- Walk Assist
- Cruise
- Adjustable acceleration (current ramp up)
- New odometer sub menu: Current, Average and Max speed
- Experimental higher cadence mode
- Updated wiki

------------------------------------------------------------------------------------------------------------------------------------
Just read the wiki. Very cool. This is getting so good! Can't wait to try it. :)

dameri   100 W

100 W
Posts: 164
Joined: Sep 20 2018 10:57am

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by dameri » Jan 18 2019 1:26am

buba wrote:
Jan 17 2019 4:23pm
buba wrote:
Jan 11 2019 1:27pm
This will be a big one…
Another big one…

Here is an update on what I have been working on since my last post. I have read all the feedback!

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

- The Cruise function has its own sub menu in the configuration menu where it is possible to set up Cruise as preferred by user.

- It is now possible to operate Cruise with two modes. The first one simply saves the current speed and maintains it and the other mode is settable: you can enter your target speed and it will get to and maintain that speed. There is a new sub field in the odometer field where the target speed is displayed. Switch between the two modes in the configuration menu.

- Completely new Cruise PID controller code. Smoother in all ranges of speed than my first implementation. It works by controlling the PWM to the motor by a custom made PID controller, tuned for safety for now. Can be made more aggressive but I see no need for that.

- Implemented button debounce on both Cruise and Walk Assist. But during testing this has turned out to be quite dangerous. Even for ultra short moments. I have removed this implementation due to safety. Please test out the functions as is and see how they work out.

- New sub menu in the configuration menu, Main Screen Setup, where the user can tailor the main screen. Enable or disable different sub fields in the odometer field. Future updates will enable users to switch out the time measurement for any other data, such as consumed watt-hours or, as user Dameri mentioned in a question, pedal cadence.

- Updated the Wiki and tried to explain all new functions and how they work. Please take a look and read more there: https://github.com/OpenSource-EBike-fir ... 8.X-(beta)

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

Do note that all this is still in development. I have submitted a pull request and look forward to Casainho testing out the firmware. And with his approval anyone interested or curious can download the beta and test for themselves. Updates and more improvements are coming!

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

Compressed changelog:

- Main Screen Setup
- Walk Assist
- Cruise
- Adjustable acceleration (current ramp up)
- New odometer sub menu: Current, Average and Max speed
- Experimental higher cadence mode
- Updated wiki

------------------------------------------------------------------------------------------------------------------------------------
Thank you very much. This is what I’ve been waiting.

Rydon   100 W

100 W
Posts: 252
Joined: Aug 11 2016 5:26pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by Rydon » Jan 18 2019 3:08am

Issue with coaster brake versions of the motor:

0.16.0 motor firmware
0.17.0 LCD3 firmware

Motor runs continuously as soon as LCD3 display initializes. I flashed the firmware to a second coaster brake motor with the same result. It is as if the throttle is on but coaster brake motors do not have throttles. I checked the 9. Advanced Technical Data and got these readings:

0 ADC Throttle 108
1 Throttle 120

Enabling the motor temperature protection shuts off the motor as expected since it uses the throttle circuit. However, it says not to enable this feature unless the temperature sensor has been installed. I just want to disable the throttle.

Does anyone know if there would be any unwanted effects if you use the "enable motor temperature protection" feature to disable the throttle if no temperature sensor is installed? Perhaps we need a disable throttle option.

casainho   10 GW

10 GW
Posts: 4361
Joined: Feb 14 2011 2:43pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by casainho » Jan 18 2019 4:04am

Rydon wrote:
Jan 18 2019 3:08am
Issue with coaster brake versions of the motor:
The issue is that no one that develops uses that type of motor -- even If I had that motor for development, not having it on my ebike makes difficult to test and understand the needed specific features.

One question: does that motor uses a throttle??

I would make this specific work, to help for that specific motor version (this is a task for you ;-) )
1. We keep all pins definitions about the controller here (see bellow): https://github.com/OpenSource-EBike-fir ... ler/pins.h
2. Look at wiring on the motor controller: are the wiring the same or there are other pins connections to the board?? -- seeing the differences will help us to understand.

Code: Select all

/* Connections:
 *
 * Motor PHASE_A: blue wire
 * Motor PHASE_B: green wire
 * Motor PHASE_C: yellow wire
 *
 * The battery_current is measured using the LM385 opamp in an non inverting configuration. The pin 1 is the output and has a low pass filter.
 * The pin 3 (+) has the signal input and pin 2 (-) has the feedback loop, composed of R1 = 11k and R2 = 1k.
 * The gain is: (R1 / R2) + 1 = (11k / 1k) + 1 = 12.
 * We know that 1 Amp of battery current is equal to 5 ADC_12bits steps, so 1 Amp = (5V / 1024) * 5 = 0.0244V.
 * Each 1 Amp at the shunt is then 0.0244V / 12 = 0.002V. This also means shunt should has 0.002 ohms resistance.
 * Since there is a transistor that has a base resistor connected throught a 1K resisitor to the shunt voltage, and also the base has
 * another connected resistor of 27K, I think the transistor will switch on at arround 0.5V on the shunt voltage and that means arround 22 amps.
 * The microcontroller should read the turned on transistor signal on PD0, to detect the battery_over_current of 22 amps. (?????)
 *
 * PIN                | IN/OUT|Function
 * ----------------------------------------------------------
 * PD0                | in  | battery_over_current (PD0 on original firmware configured as: Port D0 alternate function = TIM1_BKIN)
 * PB4  (ADC_AIN4)    | in  | torque sensor signal, this signal is amplified by the opamp
 * PB5  (ADC_AIN5)    | in  | battery_current (14 ADC bits step per 1 amp; this signal amplified by the opamp 358)
 * PB6  (ADC_AIN6)    | in  | battery_voltage (0.344V per ADC 8bits step: 17.9V --> ADC_10bits = 52; 40V --> ADC_10bits = 116; this signal atenuated by the opamp 358)
 *
 * PE5                | in  | Hall_sensor_A
 * PD2                | in  | Hall_sensor_B
 * PC5                | in  | Hall_sensor_C
 *
 * PB2  (TIM1_CH3N)   | out | PWM_phase_A_low
 * PB1  (TIM1_CH2N)   | out | PWM_phase_B_low
 * PB0  (TIM1_CH1N)   | out | PWM_phase_C_low
 * PC3  (TIM1_CH3)    | out | PWM_phase_A_high
 * PC2  (TIM1_CH2)    | out | PWM_phase_B_high
 * PC1  (TIM1_CH1)    | out | PWM_phase_C_high
 *
 * PD5  (UART2_TX)    | out | usart_tx
 * PD6  (UART2_RX)    | in  | usart_rx
 *
 * PC6                | in  | brake
 * PB7  (ADC_AIN7)    | in  | throttle
 * PD7                | in  | PAS1 (yellow wire)
 * PE0                | in  | PAS2 (blue wire)
 * PA1                | in  | wheel speed
 *
 * PD3                | out | torque sensor excitation
 * PB3  (ADC_AIN3)    | in  | ???? realted to torque sensor ???
 * PD4                | out | lights. Enable/disable 5V output of the circuit that powers the lights wire of 6V.
 *
 * PE6  (ADC_AIN9)    | in  | this signal goes to a pad of a resistor that is not assembled. If was assembled, it would measure the opamp output value related to AIN4.
 *
 * PE1  tested as input on original firmware | External interrupt enabled
 * PE2  tested as input on original firmware
 * PD1  tested as input on original firmware | External interrupt enabled
 *
 * PA2  tested as input on original firmware
 * PA4  configured as output on original firmware, original firmware seems to only put it at 1 / enable
 * PA5  tested as input on original firmware
 * PA6  configured as output on original firmware, original firmware seems to only put it at 1 / enable
 *
 */
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

casainho   10 GW

10 GW
Posts: 4361
Joined: Feb 14 2011 2:43pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by casainho » Jan 18 2019 4:28am

Hi Buba.

Great features but I am afraid to "receive" all of them at the same time. Also great work on documenting on the wiki the new features!!

I think there is a BIG issue with your pull request!! You should make small pull request, one pull request for each feature / bug (you gave the title "Higher cadence" to the pull request but it includes much more!!). That would be easier to make previous discussion of each feature / bug and also the testing. I understand it seems to make development kind of slow but has the advantage to involve the other developers and users, but make things going a bit slow, as for me, I need more time than you to review the code and understand it - going slow can be a good investment, I see the firmware getting more and more complex and can be a big issue if is hard for the users, I think we should take time to think very well the new additions.
I understand that you did previous discuss here some features, but it was to fast and not discuss all of them.

Can you please go back and submit small pull requests?? You should start writing a pull request for each feature you want to implement and when we give our feedback contribution and agree for a path, that it can be accepted and merged to master. I think you should divide at least in 3 different pull requests: 1. current ramp configuration; 2. walk assist; 3. cruise.

Like I think we could have a new release only with walk assist, so users can test it well, give feedback and then we can improve until we are happy with it. Then we would move no next version with next big feature alike walk assist.

Cruise seems another big feature, so I would leave to another pull request and firmware version.

buba wrote:
Jan 17 2019 4:23pm
buba wrote:
Jan 11 2019 1:27pm
This will be a big one…
Another big one…

Here is an update on what I have been working on since my last post. I have read all the feedback!

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

- The Cruise function has its own sub menu in the configuration menu where it is possible to set up Cruise as preferred by user.

- It is now possible to operate Cruise with two modes. The first one simply saves the current speed and maintains it and the other mode is settable: you can enter your target speed and it will get to and maintain that speed. There is a new sub field in the odometer field where the target speed is displayed. Switch between the two modes in the configuration menu.

- Completely new Cruise PID controller code. Smoother in all ranges of speed than my first implementation. It works by controlling the PWM to the motor by a custom made PID controller, tuned for safety for now. Can be made more aggressive but I see no need for that.

- Implemented button debounce on both Cruise and Walk Assist. But during testing this has turned out to be quite dangerous. Even for ultra short moments. I have removed this implementation due to safety. Please test out the functions as is and see how they work out.

- New sub menu in the configuration menu, Main Screen Setup, where the user can tailor the main screen. Enable or disable different sub fields in the odometer field. Future updates will enable users to switch out the time measurement for any other data, such as consumed watt-hours or, as user Dameri mentioned in a question, pedal cadence.

- Updated the Wiki and tried to explain all new functions and how they work. Please take a look and read more there: https://github.com/OpenSource-EBike-fir ... 8.X-(beta)

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

Do note that all this is still in development. I have submitted a pull request and look forward to Casainho testing out the firmware. And with his approval anyone interested or curious can download the beta and test for themselves. Updates and more improvements are coming!

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

Compressed changelog:

- Main Screen Setup
- Walk Assist
- Cruise
- Adjustable acceleration (current ramp up)
- New odometer sub menu: Current, Average and Max speed
- Experimental higher cadence mode
- Updated wiki

------------------------------------------------------------------------------------------------------------------------------------
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

andrea_104kg   100 W

100 W
Posts: 181
Joined: Mar 05 2018 5:51pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by andrea_104kg » Jan 18 2019 5:14am

Sorry if I ask for information on the software modified by marcoq. Marcoq is busy for work in this period, maybe some users can help me. I loaded his software on a tsdz2 at 48v. Motor works, however, when it reaches its maximum power, it goes into Cut off, that is, it turns off temporarily and moves in tears. It is not the battery. The display is the watt meter does not turn off. The defect occurs whatever the ampere levels set in the parameters. Does it happen to someone else? The engine is new and with the original rom it went perfectly.

casainho   10 GW

10 GW
Posts: 4361
Joined: Feb 14 2011 2:43pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by casainho » Jan 18 2019 5:17am

andrea_104kg wrote:
Jan 18 2019 5:14am
Sorry if I ask for information on the software modified by marcoq. Marcoq is busy for work in this period, maybe some users can help me. I loaded his software on a tsdz2 at 48v. Motor works, however, when it reaches its maximum power, it goes into Cut off, that is, it turns off temporarily and moves in tears. It is not the battery. The display is the watt meter does not turn off. The defect occurs whatever the ampere levels set in the parameters. Does it happen to someone else? The engine is new and with the original rom it went perfectly.
Please create a specific thread for marcoq code (if does not exist yet) and ask there. As you can understand, the issue you are having does no happen with the OpenSource firmware with LCD3 so it is better to separate the threads to not bring confusion.
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of the Flexible OpenSource firmware for EBikes: TSDZ2 mid drive motor, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

If you like my work, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

User avatar
elem   100 W

100 W
Posts: 135
Joined: May 26 2017 4:27pm
Location: alpes maritimes
Contact:

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by elem » Jan 18 2019 7:04am

Thread created by andrea ...
soo it s located : https://endless-sphere.com/forums/viewt ... 5#p1439505

Named : TSDZ2 firmware open source adapted to VLCD5
RockRider 9.1 TSDZ2 open source firmware .

markjiizs   1 mW

1 mW
Posts: 10
Joined: Oct 25 2018 9:49pm

Re: TSDZ2 mid drive -- Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by markjiizs » Jan 18 2019 7:35am

Buba, if meanwhile we can test whole buch of code, feel free to share source or hex :) :bigthumb:

Post Reply