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

Electric Motors and Controllers
Post Reply
casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 17 2018 2:38pm

With the same spirit of Flexible OpenSource firmware for BMSBattery S/Kunteng KT motor controllers (0.25kW up to 5kW), that I started 1 year ago (on 25 April 2017), I just started the research for development of OpenSource firmware for TSDZ2 motor controller -- my notes are here:

https://opensourceebikefirmware.bitbuck ... otors.html
Last edited by casainho on Apr 18 2018 8:56am, edited 1 time in total.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

If you like my work, you can 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
John and Cecil   1 kW

1 kW
Posts: 473
Joined: Mar 14 2018 7:26pm

Re: Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by John and Cecil » Apr 17 2018 2:59pm

Woohoo!

...and Woof!

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

Re: Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by stancecoke » Apr 17 2018 3:08pm

you can find details on the torquesensor here:
https://www.pedelecforum.de/forum/index ... dz2.45029/
I wonder, how the working frequency for the sensor will be generated and the signal processing will be done in the firmware :?

regards
stancecoke

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

Re: Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by casainho » Apr 18 2018 7:31am

stancecoke wrote:
Apr 17 2018 3:08pm
you can find details on the torquesensor here:
https://www.pedelecforum.de/forum/index ... dz2.45029/
I wonder, how the working frequency for the sensor will be generated and the signal processing will be done in the firmware :?
THANKS!! you did a great works as always!!
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

Re: Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by casainho » Apr 18 2018 7:34am

VICTORY!!

The connection for firmware programming and debug are available on the connector for the speed sensor.

Seems that the original firmware is not read protected. I was able to read the option bytes, firmware and finally connect with OpenOCD for a debug session.

Please read my full notes here: https://opensourceebikefirmware.bitbuck ... enOCD.html

Image

Image
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

e3s   1 mW

1 mW
Posts: 11
Joined: Jan 08 2018 12:40pm

Re: Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by e3s » Apr 18 2018 8:09am

well done, a quick prevision of the possible customization? (I'm interested about current limit)

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

Re: Flexible OpenSource firmware for TongSheng TSDZ2 mid drive motor

Post by casainho » Apr 18 2018 8:57am

e3s wrote:
Apr 18 2018 8:09am
well done, a quick prevision of the possible customization? (I'm interested about current limit)
I guess that alone, I will not take less than 10 months. If other developers and brave testers like Stancecoke join, maybe in 3 months.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

jeanl   10 mW

10 mW
Posts: 30
Joined: Jan 24 2018 5:18pm

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

Post by jeanl » Apr 18 2018 10:31am

Kudos man, this is totally fun!!!

Drum   100 W

100 W
Posts: 246
Joined: Dec 29 2013 1:20pm
Location: Otaki New Zealand

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

Post by Drum » Apr 18 2018 9:21pm

Hi Casainho, watching with interest!

FWIW: Looks like someone else is offering updated firmware: https://www.youtube.com/watch?v=tj2aYtma64o

Obviously a "how to load the firmware" instruction video for people who have bought his disc. Not very informative, but may be of interest.

I couldn't spot any mention of software relating to the TSDZ2 controller on their website ( http://btn-ebike.com/index.asp ) , but in the "news" section it does imply they supply software for tuning the BBS units: http://btn-ebike.com/newsshow.asp?showi ... lassid=003 and the company lists videos about that subject, but nothing on the TSDZ2 software.

Best of luck with the project,
Dave

User avatar
eyebyesickle   10 kW

10 kW
Posts: 593
Joined: Apr 07 2015 9:28pm
Location: Nashville

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

Post by eyebyesickle » Apr 18 2018 9:41pm

Thats an old video that just tells how to upload a certain controller profile that they were sending to someone... its like I have files for 48v18a, 36v13a, 52v17a, etc etc, and once I connect the motor to the computer/program, I can choose to save whichever one. Also, if you know what is what, you can modify other settings, or just the current etc with this... This is the method I use for programming controllers right now, and it is extremely limited/difficult to modify specific settings as opposed to just uploading a motor/controller profile like the video shows.

I think what casianho is doing will be much better, with several parameters customizeable, and more user friendly!
www.eco-ebike.com - USA Stock + Support
www.recycles-ebike.com - Manufacturer/Direct w/ USA Support

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 19 2018 2:20am

Drum wrote:
Apr 18 2018 9:21pm
FWIW: Looks like someone else is offering updated firmware: https://www.youtube.com/watch?v=tj2aYtma64o
Thanks!!
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 19 2018 2:25am

eyebyesickle wrote:
Apr 18 2018 9:41pm
Thats an old video that just tells how to upload a certain controller profile that they were sending to someone... its like I have files for 48v18a, 36v13a, 52v17a, etc etc, and once I connect the motor to the computer/program, I can choose to save whichever one. Also, if you know what is what, you can modify other settings, or just the current etc with this... This is the method I use for programming controllers right now, and it is extremely limited/difficult to modify specific settings as opposed to just uploading a motor/controller profile like the video shows.

I think what casianho is doing will be much better, with several parameters customizeable, and more user friendly!
I would like to validate the information I learned on this process.
1. Can you please confirm that you have some cable (STLinkV2??) that is connected to the cable that goes to speed sensor?
2. And the software for reading and writing, is something specific or the Windows version of ST for flashing this microcontrollers?
3. Are you reading and changing the EEPROM area of the microcontroller and/or the flash area?

It is not just firmware, It is also all tecnhical details about the system, even like the LCD :-)
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 19 2018 6:05am

First code runs, the traditional “Hello world” using printf() :-)
The sources for the firmware, were I put this very first code, are available here: https://github.com/OpenSource-EBike-fir ... r_firmware

Image

Image

And I got more info about the VLCD5 -- see all my notes here: https://opensourceebikefirmware.bitbuck ... VLCD5.html

NOTE: the motor controller can be enabled by simple connect green wire to white wire and this way there is no need to use LCD.

Image

Cable from motor controller | PAD on LCD PCB | notes
• green | P+ | battery voltage!!
• black | GND | ground
• white | Vin | ground when LCD disabled and P+ (battery voltage) when LCD is enabled
• brown | RX | UART TX motor controller
• orange | TX | UART RX motor controller
• purple | not connected | this cable is not connected to any PAD
• not available | 5V | the PAD has 5V label but seems it is not connected
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

jeanl   10 mW

10 mW
Posts: 30
Joined: Jan 24 2018 5:18pm

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

Post by jeanl » Apr 19 2018 10:36am

This is the totally fun part of the project, you must be having a ball!!!

qwerkus   100 W

100 W
Posts: 182
Joined: Jul 22 2017 4:00am

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

Post by qwerkus » Apr 19 2018 2:11pm

Some experience with openocd here. I also have a tsdz2 (though a noisy one). If you need some help, let me know. Also I have the buggy XH 18 display, and would be interested into fixing it.

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 19 2018 4:31pm

qwerkus wrote:
Apr 19 2018 2:11pm
Some experience with openocd here. I also have a tsdz2 (though a noisy one). If you need some help, let me know. Also I have the buggy XH 18 display, and would be interested into fixing it.
Thanks. OpenOCD and debug works great on Eclipse.

All the help is welcome. If you want to get involved, please look at the code in github and maybe you can participate in some part...
About displays, the ones used by Kunteng are cheaper and the code is already done, and they communicate through UART as XLCD5, so is just a matter of wiring.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 19 2018 4:34pm

I just tested and found that the firmware I did read from the motor controler is ok and I flashed it back and it works :-)
I also did a backup of opion bytes and EEPROM.
This means we can test the firmware and go back to original one when we want.

I would like to disassembly the firmware binary file as it can give some clues... Does anyone knows how to disassembly STM8 firmware bin files?? The file is on the project page.
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

qwerkus   100 W

100 W
Posts: 182
Joined: Jul 22 2017 4:00am

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

Post by qwerkus » Apr 19 2018 4:50pm

casainho wrote:
Apr 19 2018 4:31pm
Thanks. OpenOCD and debug works great on Eclipse.

All the help is welcome. If you want to get involved, please look at the code in github and maybe you can participate in some part...
About displays, the ones used by Kunteng are cheaper and the code is already done, and they communicate through UART as XLCD5, so is just a matter of wiring.
Never worked with eclipse, but why not. What I did was hardcore rpi openocd fixing of bricked routers - nothing really fancy. Thanks pointing out the code done on Kunteng, but there is no way I would give up the XH 18 grip shifting. As a matter of fact, other expressed interest into it (for an instance coupled with a bbs) so there is a lot of potential. I think we could make the XH 18 an "universal" display + shifter. Will have a look at your code once I dig out the rpi...

User avatar
eyebyesickle   10 kW

10 kW
Posts: 593
Joined: Apr 07 2015 9:28pm
Location: Nashville

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

Post by eyebyesickle » Apr 19 2018 6:47pm

casainho wrote:
Apr 19 2018 2:25am
eyebyesickle wrote:
Apr 18 2018 9:41pm
Thats an old video that just tells how to upload a certain controller profile that they were sending to someone... its like I have files for 48v18a, 36v13a, 52v17a, etc etc, and once I connect the motor to the computer/program, I can choose to save whichever one. Also, if you know what is what, you can modify other settings, or just the current etc with this... This is the method I use for programming controllers right now, and it is extremely limited/difficult to modify specific settings as opposed to just uploading a motor/controller profile like the video shows.

I think what casianho is doing will be much better, with several parameters customizeable, and more user friendly!
I would like to validate the information I learned on this process.
1. Can you please confirm that you have some cable (STLinkV2??) that is connected to the cable that goes to speed sensor?
2. And the software for reading and writing, is something specific or the Windows version of ST for flashing this microcontrollers?
3. Are you reading and changing the EEPROM area of the microcontroller and/or the flash area?

It is not just firmware, It is also all tecnhical details about the system, even like the LCD :-)
1.) Yes, I took the connectors that came with the STlinkV2, and wired them to a TSDZ2 speed sensor extension cable that was cut in half.
2) Windows ST Visual Programmer ~ STlinkV2 software
3) Data Memory is the area for manual adjustments of voltage and current, you can change a couple values and edit manually. Otherwise, I just load the whole program memory AND data memory for easy programming, from pre prepared files I have.

On a side note, I may try to get these running with NO display. I think to have a model (coaster brake version, im thinking) where there is NO display, and NO speed sensor, that would be super slick and clean. JUST the pedal assist, as long as we can make it automatically come on when the battery is powered on, I would just leave it at 3/4 assist =).
www.eco-ebike.com - USA Stock + Support
www.recycles-ebike.com - Manufacturer/Direct w/ USA Support

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 20 2018 12:54pm

I think this sensor that is screwed on the motor controller but is in visual line with the crank, is a PAS sensor. I verified it has signal 2 wires output (digital signal) that reacts when I pass a magnet in front of them and seems is a kind of quadrature signal and this way should be possible to detect if pedals are rotating forwards or backwards.

Question: I didn't saw any magnets on my crank, can you guys say if the crank has magnets??

Image

Image
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

Speady   10 W

10 W
Posts: 74
Joined: Nov 17 2015 10:45am
Location: an island, surrounded by water, big water,

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

Post by Speady » Apr 20 2018 1:31pm

There's only tiny magnets next to the hall sensor that enables torque sensing.
Image
Wouldn't spend much time in searching for a PAS.

casainho   100 MW

100 MW
Posts: 2661
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Apr 20 2018 2:04pm

Speady wrote:
Apr 20 2018 1:31pm
There's only tiny magnets next to the hall sensor that enables torque sensing.
Thanks.
Speady wrote:
Apr 20 2018 1:31pm
Wouldn't spend much time in searching for a PAS.
Why do you say that?
Developer of the Flexible OpenSource firmware for EBike motor controllers (TSDZ2 and KT) and LCDs (KT-LCD3 and Bafang 850C color LCD).

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

Speady   10 W

10 W
Posts: 74
Joined: Nov 17 2015 10:45am
Location: an island, surrounded by water, big water,

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

Post by Speady » Apr 20 2018 2:37pm

I don't know what you have in mind with a PAS Sensor.
There's quite a few software bugs you can patch instead.
The display cuts off after rolling a couple minutes without assist, the LVC and OVC need to be made adjustable to make the unit work on a 11S battery, and a soft start ramp would be nice too. So let us improve the programming in the first place.

User avatar
stancecoke   10 kW

10 kW
Posts: 896
Joined: Aug 02 2017 2:56pm

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

Post by stancecoke » Apr 20 2018 3:46pm

As far as I remember, the PAS magnets are in the outer ring of the secondary coil.

Regards
stancecoke

Speady   10 W

10 W
Posts: 74
Joined: Nov 17 2015 10:45am
Location: an island, surrounded by water, big water,

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

Post by Speady » Apr 20 2018 4:06pm

stancecoke wrote:
Apr 20 2018 3:46pm
As far as I remember, the PAS magnets are in the outer ring of the secondary coil
You are right. There are another 20 tiny magnets .

Post Reply