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

No max PWM duty and EPRS is not hit yet

If FOC is wrong then the motor could lose timing at high RPM

Thank you
I will check this and report back


I see value should be 80 for 36v
Code:
 // 36V motor: L = 76uH
  // 48V motor: L = 135uH
//  ui32_l_x1048576 = 142; // 1048576 = 2^20 | 48V
//  ui32_l_x1048576 = 80; // 1048576 = 2^20 | 36V

  // ui32_l_x1048576 = 142 <--- THIS VALUE WAS verified experimentaly on 2018.07 to be near the best value for a 48V motor,
  // test done with a fixed mechanical load, duty_cycle = 200 and 100 and measured battery current was 16 and 6 (10 and 4 amps)
  ui32_l_x1048576 = 142;

Just wondering if you need to advance or retard the timing with less load. I noticed on a small descent I could peddle at a higher rpm before the motor lost the plot
 
Ok I just tried 80 and it let's me hit the PWM duty and EPRS limits at around 112 cadence !!

In this case the power reduced gracefully rather than abruptly at lower cadence as before

I feel that the best angle may be a little higher so I will test over the next few days

Thanks
Getting closer ;)
 
jbalat said:
Ok I just tried 80 and it let's me hit the PWM duty and EPRS limits at around 112 cadence !!

In this case the power reduced gracefully rather than abruptly at lower cadence as before

I feel that the best angle may be a little higher so I will test over the next few days
The angle is calculated with I*W*L / Phase voltage: I phase (should be like 20 at low speeds, at startup) * W (ERPS speed) * Motor inductance / Phase voltage (is lower at low duty_cycle, low throttle, startup).

So the angle should increase as phase current increase and motor speed increase. On my 48V motor I see on LCD3 a value that starts at 1 and goes to max of 7. For the 36V motor, it also starts at 1 and should go to less higher values maybe like 4 but please see for yourself.
I validated for 48V motor where I put a fixed mechanical load (training roller) on the bicycle wheel and put motor running at a fixed battery current that went to measure the max speed with different fixed angles and got a table of best angle for a specific current, then I got the same values with the automatic FOC algorithm.
 
Ok well fingers crossed I will ride into work tomorrow and see how it goes !!

If this works then the only thing I can think of is the walk mode ? Are there any other issues you will be working on ?

My friends with TSDZ2 are very lazy and would all like to use their own displays. What would happen if we connect the stock VLCD5 or XH18, will they show speed and be able to select different assist levels ?
 
jbalat said:
Ok well fingers crossed I will ride into work tomorrow and see how it goes !!

If this works then the only thing I can think of is the walk mode ? Are there any other issues you will be working on ?

My friends with TSDZ2 are very lazy and would all like to use their own displays. What would happen if we connect the stock VLCD5 or XH18, will they show speed and be able to select different assist levels ?
Read here: https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/FAQ#Flexible_OpenSource_firmware
 
Hi all.
My test this morning with the correct FOC for 36v motor went well

The Good
I was able to achieve full cadence of 110 RPM at low gear/speeds with graceful power loss at the end
Motor felt smoother
It was a real pleasure to ride :)
In general it used between 20-40W less power above 30km/hr than before

What can be improved
So remember my post where I bumped power to 550w and I was doing 38km/hr without much effort.
So now for the same power setting I can only do 36km/hr with a lot of effort even with level 5 assist. I could not hit the max cadence (due to wind resistance) as the motor would not supply more than 12 amps. Setting was on 17

I think by changing the magnets from 24 to 20 somehow there is now a little bit less assistance at higher cadence

Is there somewhere in the code I can add extra power for higher cadence plzzzzzz... Then I can stop bugging you :D
 
casainho said:
jbalat said:
Ok well fingers crossed I will ride into work tomorrow and see how it goes !!

If this works then the only thing I can think of is the walk mode ? Are there any other issues you will be working on ?

My friends with TSDZ2 are very lazy and would all like to use their own displays. What would happen if we connect the stock VLCD5 or XH18, will they show speed and be able to select different assist levels ?
Read here: https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/FAQ#Flexible_OpenSource_firmware

Hi, I just read the linked page, but I think I have the same question as it is still not clear - if we hook up a XH-18 or VLCD-5 will it not work at all or no? Has the firmware been modified to the point where it completely won't work? Or could you at least adjust the assist etc?

I'm guessing it won't work at all, otherwise hopefully it would have been suggested, but then again, you never know...

Also, FYI I noticed a couple points that were not exactly accurate on that page, such as about the metal gear - which you actually can get pre-installed in a TSDZ2! :wink:
 
jbalat said:
Hi all.
My test this morning with the correct FOC for 36v motor went well

The Good
I was able to achieve full cadence of 110 RPM at low gear/speeds with graceful power loss at the end
Motor felt smoother
It was a real pleasure to ride :)
In general it used between 20-40W less power above 30km/hr than before

What can be improved
So remember my post where I bumped power to 550w and I was doing 38km/hr without much effort.
So now for the same power setting I can only do 36km/hr with a lot of effort even with level 5 assist. I could not hit the max cadence (due to wind resistance) as the motor would not supply more than 12 amps. Setting was on 17

I think by changing the magnets from 24 to 20 somehow there is now a little bit less assistance at higher cadence

Is there somewhere in the code I can add extra power for higher cadence plzzzzzz... Then I can stop bugging you :D
First, 550W on 36V battery is tue 15 amps which seems high current to me if you do it for long time -- did you check with your hand the motor temperature? Because if was high for long time maybe you did demagnetized the motor amd now it has lower torque for the same battery current.

To check, use the same configurations as before!!

On LCD3 you can see the calculated human power that I think if is 255, that max duty-cycle is asked and so the max of 17 amps is asked but b3cause of higher motor rpm the current may not be the max.

I really can't understand what is happening. At level assit 5 I think it is easily always asked max current...
 
eyebyesickle said:
casainho said:
jbalat said:
Ok well fingers crossed I will ride into work tomorrow and see how it goes !!

If this works then the only thing I can think of is the walk mode ? Are there any other issues you will be working on ?

My friends with TSDZ2 are very lazy and would all like to use their own displays. What would happen if we connect the stock VLCD5 or XH18, will they show speed and be able to select different assist levels ?
Read here: https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/FAQ#Flexible_OpenSource_firmware

Hi, I just read the linked page, but I think I have the same question as it is still not clear - if we hook up a XH-18 or VLCD-5 will it not work at all or no? Has the firmware been modified to the point where it completely won't work? Or could you at least adjust the assist etc?

I'm guessing it won't work at all, otherwise hopefully it would have been suggested, but then again, you never know...

Also, FYI I noticed a couple points that were not exactly accurate on that page, such as about the metal gear - which you actually can get pre-installed in a TSDZ2! :wink:
Stock LCDs doesn't work at all.

Please send me the full correction. Also If you want I can give you write access to the wiki.
 
Hi,

Understood, thanks for the clarification.

I misread the brake part - I thought it stated you needed the 5v for the magnet sensor, but it was the hidden wire sensor - my mistake. Seems all good less the possible pre-installed metal gear, no biggy at all. Glad you got that started...

I'm working on a troubleshooting flowchart to easily diagnose TSDZ2 and/or common / install issues... That should hopefully cover all the simple issues/mistakes that people have/make. If you want to put that or anything else I share on the wiki you are welcome to do so, of course, but I'll have to thoroughly test my own stuff for accuracy first!
 
eyebyesickle said:
Hi,

Understood, thanks for the clarification.

I misread the brake part - I thought it stated you needed the 5v for the magnet sensor, but it was the hidden wire sensor - my mistake. Seems all good less the possible pre-installed metal gear, no biggy at all. Glad you got that started...

I'm working on a troubleshooting flowchart to easily diagnose TSDZ2 and/or common / install issues... That should hopefully cover all the simple issues/mistakes that people have/make. If you want to put that or anything else I share on the wiki you are welcome to do so, of course, but I'll have to thoroughly test my own stuff for accuracy first!
Didn't know that I can get pre installed metal gear, as I didn't saw that on the PSWPower shop that seems a reference one.

Would be great to link to your documents, but I don't have time to read them and improve the wiki.......
 
Sorry I'm not sure I understand what you are saying about "PSW power shop seems a reference one"?

Plenty of options available outside of PSW... They definitely are not the best source for TSDZ2... A decent source for certain parts at a reasonable price, but they are limited in their model types and accessories options even compared to other Chinese distributors. No worries though, just had to mention it because people new to the TSDZ2 may read that and assume it's correct because the other info you provide is so good!
 
Ok just testing on the way home

Human power is 255
Duty is 254
Erps still under 500
Max amps only 12

If I slow down to low cadence then it will give me 550w but not at high cadence
 
jbalat said:
Ok just testing on the way home

Human power is 255
Duty is 254
Erps still under 500
Max amps only 12

If I slow down to low cadence then it will give me 550w but not at high cadence
Duty is at 254 so it is at max possible voltage applied to the motor coils!! The only way for speed to increase is if you reduce the mechanical load/if you pedal harder to reduce the mechanical load.

At lower speeds it can pull the max current but not at higher speeds!! That is because motor terminals has the BEMF voltage that increases with speed and at max motor speed tue BEMF voltage equals to the battery voltage so no current flows.

You can try to reflash the original firmware and or our firmware v2 to see if you see any difference to current version. If not, I suggest you to open the electric motor and look at the coils and magnets, trying to attract a metal piece to magnets to see if they attract in the same way all of them -- see here:

https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/TSDZ2-motor-demagnetized-due-to-heating-to-high-temperature
 
H Casainho,
Good news nothing wrong with my motor :mrgreen:

The old code 0.2 gives me full power at high rpm

The new code with magnets changed back to 24 also gives me full 550w !! And believe me you can tell the difference

Somewhere in the code there is a dependency on the number of magnets that reduces power at high rpm. I will see if I can track it down tonight.

An easy fix is to go back to 24 magnets and just reflash the KT-LCD with cadence * 1.2 to show correct cadence.

Not sure if this is relevant, But I should also mention that I changed max ERPS from 580 back to 520 in the new code also, both versions had 520 for this test.

UPDATE..
Blah can't find any reason why the code would reduce power but I did find this in ebike_app.c (uart_send_package)
Code:
// PAS cadence
  ui8_tx_buffer[12] = ui8_pas_cadence_rpm;

Just tested this and seems to work.
Code:
// PAS cadence
  ui8_tx_buffer[12] = (uint8_t) ((float) ui8_pas_cadence_rpm * 1.2);
 
jbalat said:
UPDATE..
Blah can't find any reason why the code would reduce power but I did find this in ebike_app.c (uart_send_package)
Code:
// PAS cadence
  ui8_tx_buffer[12] = ui8_pas_cadence_rpm;

Just tested this and seems to work.
Code:
// PAS cadence
  ui8_tx_buffer[12] = (uint8_t) ((float) ui8_pas_cadence_rpm * 1.2);
Well, I hate to have that fixes!!

Please see here all the changes I did from the commit of V0.2 to current master. I think it is this code and I am tired now to understand what I did some days ago...

View attachment changes.diff.txt

Code:
   // cadence percentage (in x256)
   ui16_temp = (((uint16_t) ui8_pas_cadence_rpm) << 8) / ((uint16_t) PAS_MAX_CADENCE_RPM);
+  // limit the calculated value to be no more than PAS_MAX_CADENCE_RPM x256
+  if (ui8_pas_cadence_rpm > PAS_MAX_CADENCE_RPM)
+  {
+    ui16_temp = ((uint16_t) PAS_MAX_CADENCE_RPM) << 8;
+  }

Maybe we just need to revert this values:
Code:
 // (1/(150RPM/60)) / (PAS_NUMBER_MAGNETS * 0.000064)
-#define PAS_ABSOLUTE_MAX_CADENCE_PWM_CYCLE_TICKS  (6250 / PAS_NUMBER_MAGNETS) // max hard limit to 150RPM PAS cadence
-#define PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS  (156250 / PAS_NUMBER_MAGNETS) // min hard limit to 6RPM PAS cadence
+#define PAS_ABSOLUTE_MAX_CADENCE_PWM_CYCLE_TICKS  (5208 / PAS_NUMBER_MAGNETS) // max hard limit to 150RPM PAS cadence
+#define PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS  (130208 / PAS_NUMBER_MAGNETS) // min hard limit to 6RPM PAS cadence
 
casainho said:
Maybe we just need to revert this values:
Code:
 // (1/(150RPM/60)) / (PAS_NUMBER_MAGNETS * 0.000064)
-#define PAS_ABSOLUTE_MAX_CADENCE_PWM_CYCLE_TICKS  (6250 / PAS_NUMBER_MAGNETS) // max hard limit to 150RPM PAS cadence
-#define PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS  (156250 / PAS_NUMBER_MAGNETS) // min hard limit to 6RPM PAS cadence
+#define PAS_ABSOLUTE_MAX_CADENCE_PWM_CYCLE_TICKS  (5208 / PAS_NUMBER_MAGNETS) // max hard limit to 150RPM PAS cadence
+#define PAS_ABSOLUTE_MIN_CADENCE_PWM_CYCLE_TICKS  (130208 / PAS_NUMBER_MAGNETS) // min hard limit to 6RPM PAS cadence
Ok, that values are incorrect and I did rollback the values. I just pushed this changes to master branch. I hope this solves your issue.
 
You da man !!!! ;)

Really appreciate your efforts
 
If possible, please put your issues and ideas on the list, so we can keep track of them: https://github.com/OpenSource-EBike-firmware/TongSheng_TSDZ2_motor_controller_firmware/issues
 
casainho said:
If possible, please put your issues and ideas on the list, so we can keep track of them: https://github.com/OpenSource-EBike-firmware/TongSheng_TSDZ2_motor_controller_firmware/issues

No worries will do from now on Casainho. I'm just glad you are not too busy to help since I'm really hyped up with this project :D

BTW the issue was not with the code. Finally figured it out. The only other thing we changed except for the no. of magnets was the FOC angle for my 36v.

- A value of 80 on the 36v is smoother gives higher cadence but limits the max power
- A value of 142 I get more power, less cadence and motor loses timing if I try to go to push a high cadence

*** So I changed it to 130 and it seems to be giving me good power and good cadence.

I dont know if 130 is ideal? Maybe its only good for high rpm but maybe 80 is better for normal riding ?
Sounds like we need to put this thing on a DYNO :)
 
Hi guys,

I'm an avid cyclist and a fellow software developer myself. Last week I've received my TSDZ2 and the LCD3 as well. I didn't mount the motor yet, have received the battery only yesterday and am still missing the battery connectors. However, I've made the programming cable and have updated the data memory to make my 36V motor work with the 48V battery (yes, I'll be overvolting :D ). I have to try the original firmware first to get a feel for the motor and the differences the new firmware will make.

I plan to and would love to cooperate on this project! But I've never worked with STM8 MCU's (primarily AD DSP, AVR and Microchip). Besides, the last years I'm only using high level programming languages, almost no more embedded devices. That possibly makes me more interested and experienced in exploring the other possible parts of the journey: display, connecting to the outside world, wireless, apps, maybe an easier programming interface. But, will help with the firmware whenever I see a possibility and am able to.

@Casainho: can't wait to try your firmware!
 
jbalat said:
casainho said:
If possible, please put your issues and ideas on the list, so we can keep track of them: https://github.com/OpenSource-EBike-firmware/TongSheng_TSDZ2_motor_controller_firmware/issues
BTW the issue was not with the code. Finally figured it out. The only other thing we changed except for the no. of magnets was the FOC angle for my 36v.

- A value of 80 on the 36v is smoother gives higher cadence but limits the max power
- A value of 142 I get more power, less cadence and motor loses timing if I try to go to push a high cadence

*** So I changed it to 130 and it seems to be giving me good power and good cadence.

I dont know if 130 is ideal? Maybe its only good for high rpm but maybe 80 is better for normal riding ?
Sounds like we need to put this thing on a DYNO :)
When you say "max power", "more power", please clarify if you talking about the electric motor power/amps or the torque you feel on the pedals.

I think the idea is to get the max torque per electric power (keep constant voltage and measure current on tests). On DYNO/bicycle training roller, we can put a constant PWM duty_cycle and change manually the angle, to see for each specific duty_cycle what is the best angle value so we get higher speed and lower current. NOTE: increasing angle in one direction over the ideal angle, will make motor rotate at higher speeds but asking more current for that (is less efficient) -- this is called "field weakening".
 
EndlessCadence said:
Hi guys,

I'm an avid cyclist and a fellow software developer myself.

I plan to and would love to cooperate on this project! But I've never worked with STM8 MCU's (primarily AD DSP, AVR and Microchip). Besides, the last years I'm only using high level programming languages, almost no more embedded devices.
The STM8 has only 16 kbytes of flash memory so this is a very small project, we should finish it soon :)

Keep a look at the issues to see if you can help:
https://github.com/OpenSource-EBike-firmware/TongSheng_TSDZ2_motor_controller_firmware/issues
 
casainho said:
When you say "max power", "more power", please clarify if you talking about the electric motor power/amps or the torque you feel on the pedals.
When I ask for 550w I want the motor to deliver 550w so I have less pressure on the pedals.
With the lower FOC it would give me 550w at low rpm but only 420w at high rpm.
I noticed as I backed off pressure on the pedals it would increase a little bit ??? Does that make sense ?

I think the idea is to get the max torque per electric power (keep constant voltage and measure current on tests). On DYNO/bicycle training roller, we can put a constant PWM duty_cycle and change manually the angle, to see for each specific duty_cycle what is the best angle value so we get higher speed and lower current. NOTE: increasing angle in one direction over the ideal angle, will make motor rotate at higher speeds but asking more current for that (is less efficient) -- this is called "field weakening".
Yes it would be interesting to work out the best angle for the most torque across the entire rpm !
 
I am waiting for your feedback on your issue: Watt Hours does not reset #12

I would like to implement tomorrow that reset but I need your feedback.
 
Back
Top