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

Electric Motors and Controllers
bwb   1 mW

1 mW
Posts: 17
Joined: Jun 23 2019 7:07am

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

Post by bwb » Jul 02 2019 2:38pm

I got 0.19 finally up and running 8)
by Rydon » This is the same as Bafang display wiring. Your motor probably has a female 8 pin connector and your daughter's has an 8 pin male or a 6 pin female. If your daughters motor has an 8 pin male you can convert her motor to be compatible with this same wiring using a special 1to4 cable I had manufactured that converts a standard TSDZ2 8 pin controller to use Bafang style wiring so you can use all of the Bafang throttles and brake sensors. Also, very soon, thanks to the talented engineers working on this project, you will also be able to flash the 850C and the new BlueTooth SW102 displays and they are compatible with this cable as well. You can find it here: https://www.electrifybike.com/store/p11 ... ade.html#/
If I was aware that this cable existed, it would have been much faster/easier than making a small interface cable.

Anyway, parameters settings quickly verified and made the first 500m testrun => congrats to the developpers.

@developpers: if test are needed, I can perhaps help. I have a 36V setup with trottle, brake sensors and I have Speedict Mercury logger between the battery and the rest of the bike. So I can do some logging/comparison. Voltage, current, power seem to match.
Image
Image

First thing now is ordering a new battery and learning the how to view the ebike parameter on the display.

casainho   1.21 GW

1.21 GW
Posts: 3588
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 05 2019 11:43am

Image

That is the current state of 850C LCD firmware. I want to make soon a version for final users. Note that the variable on the graph and on the numeric fields, can't be changed. I hope developers can help to further improve this firmware.
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, 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 » Jul 06 2019 5:18am



always on V 0.16, planned to move to 0.19, human torque sensor on V 0.16 ( hiting 850w human power ...)
RockRider 9.1 TSDZ2 open source firmware .

buba   10 kW

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

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

Post by buba » Jul 06 2019 7:43am

Just thought I would give a quick update.

It may seem I am absent from the community but it is the exact opposite. Have been developing every night the last week and the week before that. Sorry if I have not answered or engaged in anything! Thought that I should spend the little time I have to focus on the development.

I have changed and altered around 3000 lines of code if looking at GitHub data. A lot of changes that will help us expand the functionality and improve the feeling and response of the system. Am continually working on several things at the same time.

* Have improved the Power Assist function. It is more accurate in calculating the appropriate power and therefore improves the response. Especially in the low range. The human power calculation is also much more accurate.

* Have implemented a Torque Assist function. This one only relies on the pedal torque applied. Similar to how the original firmware does and other commercial versions. Very responsive.

* Have implemented a Cadence Assist. This one is useful for some users that need a more traditional ebike. Not added this implementation yet to my GitHub to reduce complexity in testing but planned for next beta.

* eMTB Assist. No introduction needed! Not added yet to reduce complexity but planned for next beta.

* Total redesign on communication logic so that we easily can expand to more displays. I think this is very important.

* The wiki is suffering but will update that one when I think the layout is finished and everything is ready for beta testing.

* A LOT of changes overall! Improving the execution time, logic, safety and reducing the overall complexity of the system. Have worked on both the display and controller. These last couple of days the focus has been on the feeling and response.

Planning for a beta for all users and gather some feedback. But appreciate that everyone is patient and giving me the time to do this. Will give more info when things start becoming more finished.

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


It seems I have a non-linear torque sensor after some quick testing. This is why I only have accurate human power readings in the low range and why it quickly levels out around 100-150 watts in my development firmware version. Just got the time to test this. Will later make a graph and try to model the torque sensor with continuous data points from min to max.

If other torque sensors are similar to mine this might explain why we always had somewhat accurate readings in the low range but too high in the higher range. Now there is a new code that does not increase this error to high values, instead it dampens the error. So when giving full power it only shows 100-150 watts which is still totally inaccurate. A look-up table will maybe be needed and also higher resolution on the torque.

But will first make some more tests in the coming days and try to investigate this whole thing before I get ahead of myself. Just throwing it out there for now.

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


Question: What is the actual ADC to current conversion on the current sensing ADC? We have discussed figures of 0.625 amps per step for 8 bit but in the comments in the code there are some notes stating five steps per amp -> 0.2 amps per step 10 bit and therefore 0.8 amps per step 8 bit. Just want to confirm and need some help clearing this out.
GitHub: https://github.com/leon927
PayPal: leonstor at bredband.net

buba   10 kW

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

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

Post by buba » Jul 06 2019 7:55am

tomtom50 wrote:
Jun 30 2019 7:17am
I'm glad to see some work on the human torque reading. My TSDZ2 flatters me daily, my old bones push 200W so easily...

A decent check could be done with rollers. On zero assist pedal a while at a steady speed and get a good human watts reading. Then in the same gear use throttle only to reach the same speed and read the electrical watts.

Rollers eliminate confounding factors like wind resistance, head or tail wind, or changes in grade like you have on the road. If you run rollers the same speed they draw the same power.

Since the motor and gears are about 80% efficient, 0.8 * electrical watts should be very close to the true mechanical work at the spindle and can be used to calibrate human watts. The displayed zero assist human watts should correspond within 5% or so.

I would do this but I don't know anyone who has a set of rollers.
Very good idea! When we are satisfied with the calculations and have something to test it would be very good to validate with rollers. Nice one!


elem wrote:
Jul 06 2019 5:18am


always on V 0.16, planned to move to 0.19, human torque sensor on V 0.16 ( hitting 850w human power ...)
You are superman! :wink:
GitHub: https://github.com/leon927
PayPal: leonstor at bredband.net

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 » Jul 06 2019 10:47am

buba wrote:
Jul 06 2019 7:43am
Just thought I would give a quick update.

It may seem I am absent from the community but it is the exact opposite. Have been developing every night the last week and the week before that. Sorry if I have not answered or engaged in anything! Thought that I should spend the little time I have to focus on the development.

I have changed and altered around 3000 lines of code if looking at GitHub data. A lot of changes that will help us expand the functionality and improve the feeling and response of the system. Am continually working on several things at the same time.


* Have implemented a Torque Assist function. This one only relies on the pedal torque applied. Similar to how the original firmware does and other commercial versions. Very responsive.



Many thanks for all your hard work Buba. I have been off the bike for a couple of months and have just flashed with version 19 and really pleased to find I can now push the bike backwards with the system switched on. That was badly needed.


I am just as pleased you are going to implement torque assist. I've just come back from a test ride on version 19 and all the time I was thinking it is odd not to have the most torque from the motor when you most need it slowly peddling up a steep hill and really pushing hard on the pedals but as the hill levels off and cadence picks up so does the motor assist when it is not really required as much. It's not just version19 of course, it's been like that for sometime.

Just got to sort out the power boost settings now as they have changed since 18

Thanks again for all your hard work.

casainho   1.21 GW

1.21 GW
Posts: 3588
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 06 2019 4:52pm

buba wrote:
Jul 06 2019 7:43am
It seems I have a non-linear torque sensor after some quick testing. This is why I only have accurate human power readings in the low range and why it quickly levels out around 100-150 watts in my development firmware version. Just got the time to test this. Will later make a graph and try to model the torque sensor with continuous data points from min to max.
I got the same values as you, BUT, I have 4 different bicycles with TSDZ2.

On my own bicycle, I get the same values as you: it is easy to get around 120W but very hard to go like over 180W.

I went to measure again and I got this - ADC values:
- rest: 62
- 5 kgs: 70 (delta of 8 )
- 10 kgs: 78 (delta of 8 )
- 15 kgs: 79 (delta of 1)
- 20 kgs: 80 (delta of 1)
- 25 kgs: 82 (delta of 2)

So as we can so, my torque sensor can measure well up to 10 kgs but at 15 kgs it is already not measuring.

Now with other bicycle, the one from my girlfriend:

ADC values:
- rest: 45
- 5 kgs: 52 (delta of 7)
- 10 kgs: 59 (delta of 7)
- 15 kgs: 66 (delta of 7)
- 20 kgs: 72 (delta of 6)
- 30 kgs: 85 (delta of 6.5)
- unknown kgs: 103 (max value the torque sensor measures)
(could not measure higher values but with my body of 100 kgs, the sensor seems to max out before I put all my weight but goes up to AC value of 103)

I tested on another bicycle and I saw that at rest ADC was 40 and max value was 72.

So, seems there are expressive variations on the TSDZ2 torque sensors :-(

Would be nice if we could look at the torque sensor details (Stancecoke where are you??) and see if we can tweak the bad torque sensors... here is an explanation how TSDZ2 torque sensor works:

https://github.com/OpenSource-EBike-fir ... nsor-works

Maybe we can adjust that 2 bolts??

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, 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   1.21 GW

1.21 GW
Posts: 3588
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 06 2019 5:52pm

casainho wrote:
Jul 06 2019 4:52pm
So, seems there are expressive variations on the TSDZ2 torque sensors :-(

Would be nice if we could look at the torque sensor details (Stancecoke where are you??) and see if we can tweak the bad torque sensors... here is an explanation how TSDZ2 torque sensor works:

https://github.com/OpenSource-EBike-fir ... nsor-works

Maybe we can adjust that 2 bolts??

Image
I just disassembled a torque sensor and I am pretty sure I see the "49E" hall sensor, you can get on google the datasheet of SS49E, Linear Hall Effect Sensor.

The holes for that 2 bolts are not round, they are like oval. I tested and I can move the hall sensor forward/backward and also left/right.
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, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

buba   10 kW

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

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

Post by buba » Jul 06 2019 7:07pm

Rafe wrote:
Jul 06 2019 10:47am
Many thanks for all your hard work Buba. I have been off the bike for a couple of months and have just flashed with version 19 and really pleased to find I can now push the bike backwards with the system switched on. That was badly needed.
So glad to hear from you again, Rafe! And good to have you back! A lot of improvements on the 0.19.0 I think you will like! The backwards resistance was solved by Casainho by the way, credit to him!

Rafe wrote:
Jul 06 2019 10:47am
buba wrote:
Jul 06 2019 7:43am


* Have implemented a Torque Assist function. This one only relies on the pedal torque applied. Similar to how the original firmware does and other commercial versions. Very responsive.

I am just as pleased you are going to implement torque assist. I've just come back from a test ride on version 19 and all the time I was thinking it is odd not to have the most torque from the motor when you most need it slowly peddling up a steep hill and really pushing hard on the pedals but as the hill levels off and cadence picks up so does the motor assist when it is not really required as much. It's not just version19 of course, it's been like that for sometime.

Just got to sort out the power boost settings now as they have changed since 18

Thanks again for all your hard work.
Nice to see that you are positive even before trying it out. Can report that the feeling using torque assist is very good and I am overall very pleased with the work so far. Have some ideas to further improve it so this is one of many things I will be doing the next couple of days. This is by far the biggest undertaking I have done in this project so hopefully it will be good.

Thank you for the kind words! Much appreciated!
GitHub: https://github.com/leon927
PayPal: leonstor at bredband.net

buba   10 kW

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

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

Post by buba » Jul 06 2019 7:14pm

casainho wrote:
Jul 06 2019 4:52pm
buba wrote:
Jul 06 2019 7:43am
It seems I have a non-linear torque sensor after some quick testing. This is why I only have accurate human power readings in the low range and why it quickly levels out around 100-150 watts in my development firmware version. Just got the time to test this. Will later make a graph and try to model the torque sensor with continuous data points from min to max.
I got the same values as you, BUT, I have 4 different bicycles with TSDZ2.

On my own bicycle, I get the same values as you: it is easy to get around 120W but very hard to go like over 180W.

I went to measure again and I got this - ADC values:
- rest: 62
- 5 kgs: 70 (delta of 8 )
- 10 kgs: 78 (delta of 8 )
- 15 kgs: 79 (delta of 1)
- 20 kgs: 80 (delta of 1)
- 25 kgs: 82 (delta of 2)

So as we can so, my torque sensor can measure well up to 10 kgs but at 15 kgs it is already not measuring.

Now with other bicycle, the one from my girlfriend:

ADC values:
- rest: 45
- 5 kgs: 52 (delta of 7)
- 10 kgs: 59 (delta of 7)
- 15 kgs: 66 (delta of 7)
- 20 kgs: 72 (delta of 6)
- 30 kgs: 85 (delta of 6.5)
- unknown kgs: 103 (max value the torque sensor measures)
(could not measure higher values but with my body of 100 kgs, the sensor seems to max out before I put all my weight but goes up to AC value of 103)

I tested on another bicycle and I saw that at rest ADC was 40 and max value was 72.

So, seems there are expressive variations on the TSDZ2 torque sensors :-(

Would be nice if we could look at the torque sensor details (Stancecoke where are you??) and see if we can tweak the bad torque sensors... here is an explanation how TSDZ2 torque sensor works:

https://github.com/OpenSource-EBike-fir ... nsor-works

Maybe we can adjust that 2 bolts??

Image
It all makes sense now! This is something I have been curious about for a long time and it is exciting to get more data. Nice!

You have a very high resting value, Casinho. That is something I have on my bike as well. But your girlfriend has a lower resting value and her torque sensor works as one would expect and produces basically linear output. Do not know if the resting value has any correlation to the accuracy and/or range but interesting.

My torque sensor is so bad now that it basically can not measure above 100 W if not pressing really hard at high cadence. This is actually why I developed Torque Assist as it is actually less noticeable in that mode. But that is another story.

Am very curious if it is possible to adjust or rectify this problem in a simple way. And then have it accurate without unique calibration coefficients. Otherwise human power will never work to its full potential...

Here is a graph on the data you provided:
Torque sensor readings.png
Torque sensor readings.png (12.87 KiB) Viewed 815 times
GitHub: https://github.com/leon927
PayPal: leonstor at bredband.net

casainho   1.21 GW

1.21 GW
Posts: 3588
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 06 2019 8:22pm

Image

Image

I took the risk to disassembly the torque sensor... and I moved the hall sensor to very near of the magnets. In the end, the torque sensor is working and the rest ADC value is now 17 instead of the previous 62!! The max value is almost the same as previous: 82.
Well, it is not working well as I need to make 25 kgs for the torque before the torque sensor starts increasing over 17... seems that in a few hours will need to make extra work to ride my bicycle on the planned trip :-)

So, maybe the hall sensor is saturated because is to near the magnets...
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, 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   1.21 GW

1.21 GW
Posts: 3588
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 06 2019 8:26pm

Image

This is the current state of 850C LCD firmware. The graph is missing some data points, I think it is because system is running slow for all the calculations it need to do. I wish I could implement the top white line on the graph, for it be like an envelope.

And I wish human power could be calculated correctly to be shown on the graph...
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, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

buba   10 kW

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

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

Post by buba » Jul 06 2019 8:38pm

casainho wrote:
Jul 06 2019 8:22pm
Image

Image

I took the risk to disassembly the torque sensor... and I moved the hall sensor to very near of the magnets. In the end, the torque sensor is working and the rest ADC value is now 17 instead of the previous 62!! The max value is almost the same as previous: 82.
Well, it is not working well as I need to make 25 kgs for the torque before the torque sensor starts increasing over 17... seems that in a few hours will need to make extra work to ride my bicycle on the planned trip :-)

So, maybe the hall sensor is saturated because is to near the magnets...
So it improved the rest value but there is an offset of 25 kg? Wow! I need to study the entire torque sensor package and understand how it works. Because right now it seems as human power readings will be impossible for all users to have... Did not expect this.
GitHub: https://github.com/leon927
PayPal: leonstor at bredband.net

fi7ippo   10 mW

10 mW
Posts: 24
Joined: Aug 26 2018 2:29am

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

Post by fi7ippo » Jul 07 2019 6:27am

buba wrote:
Jul 06 2019 8:38pm
casainho wrote:
Jul 06 2019 8:22pm
Image

Image

I took the risk to disassembly the torque sensor... and I moved the hall sensor to very near of the magnets. In the end, the torque sensor is working and the rest ADC value is now 17 instead of the previous 62!! The max value is almost the same as previous: 82.
Well, it is not working well as I need to make 25 kgs for the torque before the torque sensor starts increasing over 17... seems that in a few hours will need to make extra work to ride my bicycle on the planned trip :-)

So, maybe the hall sensor is saturated because is to near the magnets...
So it improved the rest value but there is an offset of 25 kg? Wow! I need to study the entire torque sensor package and understand how it works. Because right now it seems as human power readings will be impossible for all users to have... Did not expect this.
Hi Buba, I think that Casainho is right, the two bolt are the key, but for adjust the position of hall sensor we have to do a micrometrical movement on sensor. I try to explain me better: before adjust the hall position I was in this situation:

Rest ADC value: 52, Maximun ADC value: 96, so a resolution of 44 ADC steps

After 3 attempts, moving in small steps further and further away from the magnet the new readings are:

Rest ADC value: 35, Maximun ADC value: 96, so a resolution of 61 ADC steps

I think I can still distance the sensor from the magnet until I have a resolution of 70-75 ADC steps, but there is a lot of time for disassemble and reassemble the torque sensor and a resolution of 60 ADC steps could be enough!
Also seems that at the right position of hall sensor (at near 60 ADC steps resolution) we have a linear output to the force applied, but for this I wait the digital dynamometer that I ordered whit a 90kg of capacity and 0,1kg resolution for a detailed report!

Now after a fine calibrating, there is a problem on the pedal sensor torque reading (menu 9 - 3): the parameter reach the maximum value of 255 when the ADC pedal torque sensor reach value of 68, so in this case I can use about half of the sensor capacity...

I think the maximum ADC reading is variable for each torque sensor, but still fixed for each unit, due to the small differences in the windings of the two (transformers) or the magnet near the hall sensor, from unit to unit.

For calibration the torque sensor the rest value is read every time the unit is powered on, right?

So for improve sensor torque experience and resolution it would take a user modifiable parameter regarding the maximum ADC value (the parameter can be easily read from menu 9 - 2 from each user by applying the maximum pressure on the pedals)

Another usefull parameter for fine calibrating the user human power could be an editable parameter that adjust the kg applied for each ADC step (assuming the linear output of sensor)

Thanks guys, your work on this firmware is exceptional!

casainho   1.21 GW

1.21 GW
Posts: 3588
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 07 2019 9:38am

fi7ippo wrote:
Jul 07 2019 6:27am
buba wrote:
Jul 06 2019 8:38pm
casainho wrote:
Jul 06 2019 8:22pm
Image

Image

I took the risk to disassembly the torque sensor... and I moved the hall sensor to very near of the magnets. In the end, the torque sensor is working and the rest ADC value is now 17 instead of the previous 62!! The max value is almost the same as previous: 82.
Well, it is not working well as I need to make 25 kgs for the torque before the torque sensor starts increasing over 17... seems that in a few hours will need to make extra work to ride my bicycle on the planned trip :-)

So, maybe the hall sensor is saturated because is to near the magnets...
So it improved the rest value but there is an offset of 25 kg? Wow! I need to study the entire torque sensor package and understand how it works. Because right now it seems as human power readings will be impossible for all users to have... Did not expect this.
Hi Buba, I think that Casainho is right, the two bolt are the key, but for adjust the position of hall sensor we have to do a micrometrical movement on sensor. I try to explain me better: before adjust the hall position I was in this situation:

Rest ADC value: 52, Maximun ADC value: 96, so a resolution of 44 ADC steps

After 3 attempts, moving in small steps further and further away from the magnet the new readings are:

Rest ADC value: 35, Maximun ADC value: 96, so a resolution of 61 ADC steps

I think I can still distance the sensor from the magnet until I have a resolution of 70-75 ADC steps, but there is a lot of time for disassemble and reassemble the torque sensor and a resolution of 60 ADC steps could be enough!
Also seems that at the right position of hall sensor (at near 60 ADC steps resolution) we have a linear output to the force applied, but for this I wait the digital dynamometer that I ordered whit a 90kg of capacity and 0,1kg resolution for a detailed report!

Now after a fine calibrating, there is a problem on the pedal sensor torque reading (menu 9 - 3): the parameter reach the maximum value of 255 when the ADC pedal torque sensor reach value of 68, so in this case I can use about half of the sensor capacity...

I think the maximum ADC reading is variable for each torque sensor, but still fixed for each unit, due to the small differences in the windings of the two (transformers) or the magnet near the hall sensor, from unit to unit.

For calibration the torque sensor the rest value is read every time the unit is powered on, right?

So for improve sensor torque experience and resolution it would take a user modifiable parameter regarding the maximum ADC value (the parameter can be easily read from menu 9 - 2 from each user by applying the maximum pressure on the pedals)

Another usefull parameter for fine calibrating the user human power could be an editable parameter that adjust the kg applied for each ADC step (assuming the linear output of sensor)

Thanks guys, your work on this firmware is exceptional!
Nice to see someone that went to do what I would like. Thanks for sharing with us your knowledge.

Yes, it is difficult this calibration even because the torque sensor coils and wires are very fragile!!! It is very easy to damage the wires or the coils.

Maybe a way to calibrate a torque sensor could be:
- buy 1 torque sensor
- buy 2 motor controller

- flash a specific firmware on the motor controller that outputs the torque sensor ADC value by UART, so we can see easily on PC the value
- connect the torque sensor to the motor controller and adjust the sensor position to get a rest value of 40.

Can we trust on rest value for calibrate the sensor??

Also, can the square wave frequency and duty-cyle that is generated by the STM8 change in a way to improve the sensor range??
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, please consider making a donation. I am being using the donations to buy needed resources for my developments. My paypal: casainho AT gmail.com.

buba   10 kW

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

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

Post by buba » Jul 07 2019 10:59am

fi7ippo wrote:
Jul 07 2019 6:27am
Hi Buba, I think that Casainho is right, the two bolt are the key, but for adjust the position of hall sensor we have to do a micrometrical movement on sensor. I try to explain me better: before adjust the hall position I was in this situation:

Rest ADC value: 52, Maximun ADC value: 96, so a resolution of 44 ADC steps

After 3 attempts, moving in small steps further and further away from the magnet the new readings are:

Rest ADC value: 35, Maximun ADC value: 96, so a resolution of 61 ADC steps

I think I can still distance the sensor from the magnet until I have a resolution of 70-75 ADC steps, but there is a lot of time for disassemble and reassemble the torque sensor and a resolution of 60 ADC steps could be enough!
Also seems that at the right position of hall sensor (at near 60 ADC steps resolution) we have a linear output to the force applied, but for this I wait the digital dynamometer that I ordered whit a 90kg of capacity and 0,1kg resolution for a detailed report!
Cool that you have taken the time to test this and post your findings. Very valuable for the entire community! Thanks!

What I am most interested in, and this is by far the most important aspect, is the linearity of the sensor. No point in having a lot of range if it is not consistent with the force applied. Even if it were non-linear we could fix it with software but every torque sensor should be similarly non-linear so we can apply the same solution for all the users.

The things you have done and are planing to do are really great! :bigthumb: Would love to see the data you get!


fi7ippo wrote:
Jul 07 2019 6:27am
Now after a fine calibrating, there is a problem on the pedal sensor torque reading (menu 9 - 3): the parameter reach the maximum value of 255 when the ADC pedal torque sensor reach value of 68, so in this case I can use about half of the sensor capacity...
This is solved in my development version. Works with the full range and no conversion!


fi7ippo wrote:
Jul 07 2019 6:27am
For calibration the torque sensor the rest value is read every time the unit is powered on, right?
Yes, it is calibrated every time the system is powered on. But it is not calibrated properly in 0.19.0 and previous firmware versions. Noticed it with my particular torque sensor. So I rewrote the calibration process in my development version and now the current and torque are calibrated better and adjusts for every user and their hardware. This also helped to gain a lot of resolution and improved a lot of other things as well.


fi7ippo wrote:
Jul 07 2019 6:27am
So for improve sensor torque experience and resolution it would take a user modifiable parameter regarding the maximum ADC value (the parameter can be easily read from menu 9 - 2 from each user by applying the maximum pressure on the pedals)

Another usefull parameter for fine calibrating the user human power could be an editable parameter that adjust the kg applied for each ADC step (assuming the linear output of sensor)

Thanks guys, your work on this firmware is exceptional!
Yes, assuming the torque is linear it would be possible to further develop tools for higher accuracy. Great comments, thank you!
GitHub: https://github.com/leon927
PayPal: leonstor at bredband.net

buba   10 kW

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

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

Post by buba » Jul 07 2019 12:18pm

casainho wrote:
Jun 19 2019 5:57am
...

... because each ADC unit (10 bits) represents 0.156 amps, the best the system can measure. With the 8 bits variable we can store up to 40 amps...

...
What is the actual ADC to current conversion for the current measuring ADC? We have discussed figures of 0.625 amps per ADC step for 8 bit and 0.156 amps per step for 10 bit. But in the comments in the code there are some notes stating five ADC steps per amp -> 0.2 amps per step 10 bit and therefore 0.8 amps per step 8 bit. Just want to confirm what it is.

I am actually using 0.8 and 0.2 as these values are used for the FOC calculation and should be correct.
GitHub: https://github.com/leon927
PayPal: leonstor at bredband.net

Rydon   100 W

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

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

Post by Rydon » Jul 08 2019 12:26am

casainho wrote:
Jul 06 2019 8:26pm
Image

This is the current state of 850C LCD firmware. The graph is missing some data points, I think it is because system is running slow for all the calculations it need to do. I wish I could implement the top white line on the graph, for it be like an envelope.

And I wish human power could be calculated correctly to be shown on the graph...
Looks great. Can I try it out? Do you have a hex file and some instructions?

User avatar
jbalat   10 kW

10 kW
Posts: 561
Joined: Nov 10 2012 11:50pm
Location: Melbourne, Australia

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

Post by jbalat » Jul 08 2019 7:23am

It is not practical for users to pull apart their torque sensors although for the few that did it has really given us some good data.

Just stating what everyone else is probably thinking by now...
It should be fairly easy to set up a menu item to measure adc values for 5kg, 10kg, say up to 40kg which can be done with a digital luggage scales attached to the peddle. By interpolating between these values then this would ensure that everyone would have calibrated human torque and the best resolution for their sensor even if it is non linear.
Please subscribe to my Youtube home page for Quadcopters, FPV and Bike Rides http://www.youtube.com/jbalatutube
My build log here http://endless-sphere.com/forums/viewto ... =6&t=55352
For some cool ebike talk join us on The Best ebike https://www.facebook.com/groups/193581737807033/
Tech talk TSDZ2 Opensource firmware https://endless-sphere.com/forums/viewt ... &start=150
Opensource TSDZ2 Wiki https://github.com/OpenSource-EBike-fir ... _wiki/wiki

thineight   100 W

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

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

Post by thineight » Jul 08 2019 8:46am

Agree with jbalat, removing and, specially, reinstalling the torque sensor is a bit tricky and I would avoid it with pleasure. Iterative process to tune the values (correct me if I misunderstood the above messages) makes the operation even more annoying.
I had to disassemble twice due to a factory faulty torque sensor and I think this operation is not common at all for average user.

Software interpolation between read values (linear or parabolic least square?) sounds a better choice to a non-electronic engineer like me..
Question for the gurus: is it possible for each user to read the values at known force (as suggested by jbalat), plot the result and and determine whether a linear or parabolic/bilinear relationship is applicable?
Of course the two relationship must be implemented in the controller and settable from the display in terms of coefficients..

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

buba   10 kW

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

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

Post by buba » Jul 08 2019 8:47am

jbalat wrote:
Jul 08 2019 7:23am
It is not practical for users to pull apart their torque sensors although for the few that did it has really given us some good data.

Just stating what everyone else is probably thinking by now...
It should be fairly easy to set up a menu item to measure adc values for 5kg, 10kg, say up to 40kg which can be done with a digital luggage scales attached to the peddle. By interpolating between these values then this would ensure that everyone would have calibrated human torque and the best resolution for their sensor even if it is non linear.
I agree. Pulling apart sensors is not something that should be expected of users. I am still curious in the non-linearity though. But that is something entirely different and just a mere curiosity to further learn about the torque sensor.

It is possible to:

* Create a calibration menu and setup an array of ADC to pedal torque values
* Send the whole array of data to the controller
* Have the controller measure the ADC torque value and convert it to torque with the help of the calibration array.
* Use the torque value with cadence to calculate human power
* Convert human power to motor assist power

But that is also a lot of effort and complexity. If it is linear it would be much simpler!

Luckily I have created Torque Assist and it seems the timing is perfect. I am only using Torque assist now and the beauty is that when setup correctly for my hardware it feels great. Planning to increase the resolution of the torque sensor and current control by a factor of four (4) so it should be even more responsive. I would assume that this is the way the original firmware does it and also other commercial products. And this is how my eMTB mode works that is user configurable. (Will soon add my eMTB branch to my official branch and start testing eMTB mode extensively)

However, I will do whatever I can to help and try to make the Power Assist work! But it will be good that users have options.

thineight wrote:
Jul 08 2019 8:46am
Agree with jbalat, removing and, specially, reinstalling the torque sensor is a bit tricky and I would avoid it with pleasure. Iterative process to tune the values (correct me if I misunderstood the above messages) makes the operation even more annoying.
I had to disassemble twice due to a factory faulty torque sensor and I think this operation is not common at all for average user.

Software interpolation between read values (linear or parabolic least square?) sounds a better choice to a non-electronic engineer like me..
Question for the gurus: is it possible for each user to read the values at known force (as suggested by jbalat), plot the result and and determine whether a linear or parabolic/bilinear relationship is applicable?
Of course the two relationship must be implemented in the controller and settable from the display in terms of coefficients..

Thanks
It is possible to read the values and find a formula that converts the ADC value to real life torque. But if the formula is not applicable between different users and their specific hardware it becomes more complex. If there is a universal formula everyone can use it is only necessary to measure a few data points (coefficients) to adjust the formula. Same is true if it is linear and the range depends on the rest value. But in every other case it can add complexity with diminishing returns.
Last edited by buba on Jul 08 2019 10:17am, edited 3 times in total.
GitHub: https://github.com/leon927
PayPal: leonstor at bredband.net

casainho   1.21 GW

1.21 GW
Posts: 3588
Joined: Feb 14 2011 2:43pm

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

Post by casainho » Jul 08 2019 8:51am

I just calibrate my torque sensor and found it can now measure up to 40 kgs, which is 4x more than before and this means I will get 4x more motor power assistance when I stop and after I need a quick and strong response from the motor, like when I am doing mountain biking!!

I am sure we all want a good torque sensor, that is why most of us prefer TSDZ2 over a Bafang. It is a really fun game, to apply more force with our legs and feel a strong answer from the motor!!

I wrote a wiki page with the process I used to calibrate my sensor (note that I did this process twice, on 2 different torque sensors):

How to calibrate the torque sensor --> https://github.com/OpenSource-EBike-fir ... que-sensor
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, 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 » Jul 08 2019 11:51am

I am sure we all want a good torque sensor, that is why most of us prefer TSDZ2 over a Bafang. It is a really fun game, to apply more force with our legs and feel a strong answer from the motor!!
yes, it's why i moved from BBS02b to TSDZ2 .

someone know if it's possible to buy the torque/PAS captor alone ( without axle ) !?
RockRider 9.1 TSDZ2 open source firmware .

buba   10 kW

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

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

Post by buba » Jul 08 2019 4:37pm

casainho wrote:
Jul 08 2019 8:51am
I just calibrate my torque sensor and found it can now measure up to 40 kgs, which is 4x more than before and this means I will get 4x more motor power assistance when I stop and after I need a quick and strong response from the motor, like when I am doing mountain biking!!

I am sure we all want a good torque sensor, that is why most of us prefer TSDZ2 over a Bafang. It is a really fun game, to apply more force with our legs and feel a strong answer from the motor!!

I wrote a wiki page with the process I used to calibrate my sensor (note that I did this process twice, on 2 different torque sensors):

How to calibrate the torque sensor --> https://github.com/OpenSource-EBike-fir ... que-sensor

Just looked at the code to check the ADC conversion:

Code: Select all

// ADC torque sensor
#define PEDAL_TORQUE_PER_8_BIT_ADC_STEP_X100                      52 // see note below

/*---------------------------------------------------------

  NOTE: regarding the torque sensor output values

  Torque (force) value found experimentaly.
  
  Measured with a cheap digital hook scale, we found that
  each torque sensor unit is equal to 0.52 Nm. Using the 
  scale it was found that 0.33 kg was measured as 1 torque 
  sensor unit.
  
  Force (Nm) = 1 Kg * 9.18 * 0.17 (0.17 = arm cranks size)
---------------------------------------------------------*/
So the value of 52 is too low due to: Force (Nm) = 1 Kg * 9.18 * 0.17 (0.17 = arm cranks size)

It should be: Force (Nm) = 1 Kg * 9.81 * 0.17 (0.17 = arm cranks size)

And therefore the conversion should be 54, up from 52.

Also noticed it says 0.33 kg per ADC step. Assuming that is 10 bit ADC steps it would mean that the 8 bit ADC steps represent 0.33 * 4 = 1.32 kg. Looking at your new data I see that when applying 40 kg on the pedals you get a delta of 25 ADC steps. This is a conversion of at least 62, up from 54.

Another problem is that the conversion is based on 10 bit values. So for the previous value of 52 it was calculated with:
(1) Force (Nm) = 0.33 * 9.18 * 0.17 ≈ 0.52 -> 52

But should have been calculated:
(2) Force (Nm) = 0.33 * 9.81 * 0.17 ≈ 0.54 -> 54

And with your new data and testing it should be around :
(3) Force (Nm) = 0.4 * 9.81 * 0.17 ≈ 0.67 -> 67

But this only holds true for 10 bit values. The 8 bit values are:

(1) Force (Nm) = 1.32 * 9.18 * 0.17 ≈ 2.05 -> 205

(2) Force (Nm) = 1.32 * 9.81 * 0.17 ≈ 2.20 -> 220

(3) Force (Nm) = 1.6 * 9.81 * 0.17 ≈ 2.67 -> 267

Using the new conversion factor would result in around 5 times higher human power readings. When I was giving full power with the new development firmware I only got around 100 - 150 watts human power, even less than that. With the new conversion factor I would get closer to 500 - 750 watts. Which is more plausible in a high power situation.
GitHub: https://github.com/leon927
PayPal: leonstor at bredband.net

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 » Jul 08 2019 9:06pm

After another heavy trip through the mud with water, I decided to disassemble the motor for prevention. There was water behind the gear cover (I am now redoing the protection cover and installing a rubber seal for a tighter connection, later I will show what happened). I took off the torque sensor and was surprised as the surface of the coils became bare. PCB layer disappeared completely. In casainho photo up in some message later does not have this layer either. What could lead to its destruction? Was water mixed with grease? or something different? I will try to restore the sensor, install thin rings from the PCB. And then adjust the sensor with bolts.
Attachments
IMG_20190709_122624.jpg
IMG_20190709_122605.jpg
IMG_20190709_122549.jpg
IMG_20190709_122549.jpg (199.04 KiB) Viewed 478 times

Post Reply