New TSDZ2 Open Source firmware with Bluetooth interface

I see you put the instructions for getting a board from PCBway.com as well, so can get one there too. Thank you for the great work! Looks awesome
 
Hi all,
this week i had some test rides in the mountains with the new board installed in my Bike and everything went well.
A total of 60Km and 3000m uphill.

2020516131826_20200515_172528.jpg


Here a couple of screenshots of a portion of the ride data of today.

2020518235621_Screenshot_20200518-230841.png

2020518235650_Screenshot_20200518-230920.png
 
Hi,
two new features are arriving, thanks to a suggestion i had on Reddit and a pull request on Github.

1) Anti-theft activated by Android app.
2) New BT Cycling Speed and Cadence Profile (CSCP) and the possibility to select between CSCP and Cycling Power Profile (CPP) from the android app. (to have compatibility also with devices unable to use the CPP like the Garmin Vivoactive).
 
mspider65 said:
this week i had some test rides in the mountains with the new board installed in my Bike and everything went well.
A total of 60Km and 3000m uphill.

2020516131826_20200515_172528.jpg

Very good work!! I asked for myself what was your ambition, what would be the new and most advanced feature you wanted to implement -- in my head could be map navigation on the Android app, but, after researching and talking with others, seems VERY hard for someone to do it. And on the journey I ended up seeing how the commercial products are doing it and then I found they are not doing it!! They are instead creating ebikes compatible with the wireless standard ANT+ Light Electric Vehicles (LEV) profile -- then a new world of map navigation and advanced fitness and cycling sensors opens!!

I would like to invite you to read more about this idea of a Fully wireless TSDZ2 mid drive motor (like Specialized Turbo Levo) and I hope we can collaborate in future. As you can see, your board and Android app are a reference, I hope they can be reused on this new project: https://endless-sphere.com/forums/viewtopic.php?f=28&t=106346

 
casainho said:
I would like to invite you to read more about this idea of a Fully wireless TSDZ2 mid drive motor (like Specialized Turbo Levo) and I hope we can collaborate in future. As you can see, your board and Android app are a reference, I hope they can be reused on this new project: https://endless-sphere.com/forums/viewtopic.php?f=28&t=106346


hello Casainho,
thanks, but I would have done nothing if your Open Source Firmware had not been there.
I don't have plan to add too many features to the Android App, my intention is to use the app mainly for the setup and monitoring of the motor.
I use the bike mainly for fun to ride in the mountains and normally i don't use nothing else than the switch to change assistance level :).
The only advanced feature i use when i ride on new traks, is map navigation, and for this feature i prefer to have a rugged Android Phone. I had in past also Garmin devices but i think now an Android Phone give a lot more flexibility (my favorite navigation app is Oruxmaps).
In any case your idea is really interesting and i think also ANT+ is now a consolidated standard for the ebikes.
I will be glad to follow the thread and, if i can, i will also give help.

Massimo
 
mspider65 said:
casainho said:
I would like to invite you to read more about this idea of a Fully wireless TSDZ2 mid drive motor (like Specialized Turbo Levo) and I hope we can collaborate in future. As you can see, your board and Android app are a reference, I hope they can be reused on this new project: https://endless-sphere.com/forums/viewtopic.php?f=28&t=106346


hello Casainho,
thanks, but I would have done nothing if your Open Source Firmware had not been there.
I don't have plan to add too many features to the Android App, my intention is to use the app mainly for the setup and monitoring of the motor.
I use the bike mainly for fun to ride in the mountains and normally i don't use nothing else than the switch to change assistance level :).
The only advanced feature i use when i ride on new traks, is map navigation, and for this feature i prefer to have a rugged Android Phone. I had in past also Garmin devices but i think now an Android Phone give a lot more flexibility (my favorite navigation app is Oruxmaps).
In any case your idea is really interesting and i think also ANT+ is now a consolidated standard for the ebikes.
I will be glad to follow the thread and, if i can, i will also give help.

Massimo
Maybe the advantage of ANT+ is the cycling sensors (and ANT technology belongs to Garmin). And Garmin advantage is probably their advanced fitness algorithms and metrics, and all integrations between different devices - they even buy the fitness algorithms to FirstBeat.

Since this wireless project have Bluetooth + ANT+ parts, and the Bluetooth part have the same objective as your project, makes sense to just use your project.

On the firmware side I just need a firmware that implements the same you are doing (I already have implemented UART and cycling Bluetooth profiles on SW102 display). Then I need to have ANT+ running simultaneous and implemented the specific profiles on ANT+.

So, I will keep following your project closely. And please implement the last firmware version, you will get motor cadence support up to 120 RPM!!
 
New version released.
The new files(Android apk, ESP32 firmware, and TSDZ2 firmware) are un Github at the following link https://github.com/TSDZ2-ESP32/TSDZ2-ESP32-Wiki/tree/master/bin

The main changes are:

- New Torque Sensor offset calibration procedure. The original 0.20.0 beta 1 code and also the current casainho version never worked well on my byke. Now i have always a correct Torque Offset ADC value calculated at motor startup.

- Further reduced the ADC sampling rate from 5,3MHz to 4MHz (for even better conversione precision).

- Added Theft protection function activated from the Android app. If the function is enabled, when the LCD is switched on, the LCD displays the Error E04 and the engine does not provide power until the Android application connects.
[youtube]kdxsYvd5-8s[/youtube]


To update the previous version, you must first update the Android app and then, from the Android app, you must update the ESP32 board firmware and then the TSDZ2 firmware via OTA.
 
Hi, then yesterday I got the PCB that Mspider65 sent me which I thank for the great availability and courtesy, today, after identifying the corresponding colors of my controller compared to the standard ones found in the project wiki, I connected and installed with the help of my trusted mechanic the Bluetooth transmitter and following the very precise instructions of the project the show started my TSDZ2 connects to the cell, I updated the firmware of the ESP32 card, I installed the SW Ver.3 of Mspider65 ( via PC I will then remove the protection), I set the engine, battery and temperature sensor settings from the mobile phone and then immediately took a test ride, what to say a show I felt a really great satisfaction also because all it worked on the first try and I still don't get tired of thanking Mspider65 for his wonderful project.
I use the VLCD 6.
:bigthumb: :bigthumb: :bigthumb:
 
Thanks for the compliments,
you are the first who got to try the project. I am glad that everything worked immediately.
I hope that the others to whom I have sent the boards are also satisfied.

Now, however, if all those who asked me for the board confirm, I no longer have any.

But ordering the boards on your own on PCBWay is very easy.
https://github.com/TSDZ2-ESP32/TSDZ2-ESP32-Wiki/wiki/How-to-get-the-PCB

If you have experience in PCB manufacturing, you can still order the boards wherever you want or assemble yourself. All the necessary files and informations are on Github.

Massimo
 
Hi Mspider65, I installed the new updates and everything works great! :D
 

Attachments

  • Screenshot_2020-06-03-00-52-47.png
    Screenshot_2020-06-03-00-52-47.png
    10.6 KB · Views: 2,161
  • Screenshot_2020-06-03-00-52-33.png
    Screenshot_2020-06-03-00-52-33.png
    7.7 KB · Views: 2,161
Thanks to mspider65, I got my ESP32 board a little while ago.
Unfortunately, I'd been unable to start the installation process until today, but I can also confirm how well made the board is!

I installed the board on an 8 pin controller, so slight difference on the colours referenced in the wiki - I can help to update this if needed.
As I've got an 8 pin controller, I also used the 1t4 cable from EcoCycles. This means I've modified my VLCD5 to use a bafang connector. I haven't finished the installation enough to ride the trike yet, but hope to get that done this weekend and take some pictures.

As well as testing the VLCD5 which worked great, I also tested the SW102 from EcoCycles.
This mini display has TSDZ2 compatible firmware pre-loaded, so my hope was it'd be compatible with the ESP32 setup.
The great news is, it does! All the functionality of the SW102 appears active, power level and power mode selection also works!

mspider65, you've done a great job and I'll do some further testing with the SW102 to confirm it's 100% compatible.
This could be a great option for others to use the SW102 with OSF without having to open up the display!

One quick question, are there any plans to make this work with Casainho's latest firmware? I'd like to test the force weakening, etc.
Happy to help with testing.
 
pgwguk said:
Thanks to mspider65, I got my ESP32 board a little while ago.
Unfortunately, I'd been unable to start the installation process until today, but I can also confirm how well made the board is!

I installed the board on an 8 pin controller, so slight difference on the colours referenced in the wiki - I can help to update this if needed.
As I've got an 8 pin controller, I also used the 1t4 cable from EcoCycles. This means I've modified my VLCD5 to use a bafang connector. I haven't finished the installation enough to ride the trike yet, but hope to get that done this weekend and take some pictures.

As well as testing the VLCD5 which worked great, I also tested the SW102 from EcoCycles.
This mini display has TSDZ2 compatible firmware pre-loaded, so my hope was it'd be compatible with the ESP32 setup.
The great news is, it does! All the functionality of the SW102 appears active, power level and power mode selection also works!

mspider65, you've done a great job and I'll do some further testing with the SW102 to confirm it's 100% compatible.
This could be a great option for others to use the SW102 with OSF without having to open up the display!

One quick question, are there any plans to make this work with Casainho's latest firmware? I'd like to test the force weakening, etc.
Happy to help with testing.


Hi Paul, have fun with the new setup!
Yes, as soon as I have a little more time I would also like to add the Casainho's field weakening option.

Massimo
 

Attachments

  • CimaVezzena.jpg
    CimaVezzena.jpg
    212.5 KB · Views: 2,022
New release available.
The main changes are all related to the TSDZ2 firmware.
1) New Pedal start/stop detection algorithm.
Now both PAS sensors and both sensor transitions are used to detect pedal start/stop. The new algorithm is about two times more responsive than the previous "advanced cadence mode" but without the need to do any calibration.
2) Battery current is now always sampled at the middle of the PWM cycle (not using more the previous buffered sample)
3) 4 time faster eBike control loop (40 times/second instead of 10 times/second)
3) Many other small fixes and code refactoring.

The result is a much responsive but at the same time really smooth motor.

Before to start the implementation of the "field weakening" feature I have also done some tests with the current new firmware at high cadence in order to have a baseline and i had an unexpected result.
In my current setup (36V motor and 36V battery) i'm able to have assistance up to a cadence of 97 RPM.
The images below also shows that the limit is not the duty cycle (always below the max value of 254) but the motor Max ERPS that hit the max value of 520 set in the Software. For this reason, I think that by setting a higher value of max ERPS it will be possible to have assistanace even above 100 RPM.
 

Attachments

  • Screenshot_20200727-221502.png
    Screenshot_20200727-221502.png
    140.4 KB · Views: 1,771
  • Screenshot_20200727-221537.png
    Screenshot_20200727-221537.png
    134.2 KB · Views: 1,771
  • Screenshot_20200727-221701.png
    Screenshot_20200727-221701.png
    136.8 KB · Views: 1,771
mspider65 said:
For this reason, I think that by setting a higher value of max ERPS it will be possible
This limit exists to make sure to get a proper sinusodial shape of the phase current. If you get two less PWM updates per electric revolution, you won't get an proper current shape. With the limit of 520 we get 30 points on the sine- curve per revolution at the PWM frequency of 15625 Hz.

regards
stancecoke
 
mspider65 said:
hefest said:
Any progress on supporting tsdz2 firmware v1.0.0?
The Controller protocol and firmware parameters are different and the porting involves all the layers (ESP32 and Android app.), and since I am really satisfied with the current firmware, i don't have in plan (at least for now) to port the v1.0.0.
I really hope we can merge TSDZ2 wireless standard project and this one in the future, so everyone can enjoy the most updated firmware and features.

A video showing the Garmin GPS cycling computer controlling the battery voltage to turn on / off the motor -- changing assist level on the display and when value is zero it disable the motor voltage:

[youtube]P9KJfSMeXSI[/youtube]
 
mspider65 said:
...

Before to start the implementation of the "field weakening" feature I have also done some tests with the current new firmware at high cadence in order to have a baseline and i had an unexpected result.
In my current setup (36V motor and 36V battery) i'm able to have assistance up to a cadence of 97 RPM.
The images below also shows that the limit is not the duty cycle (always below the max value of 254) but the motor Max ERPS that hit the max value of 520 set in the Software. For this reason, I think that by setting a higher value of max ERPS it will be possible to have assistanace even above 100 RPM.
imho is that what Jbalat did found already and what is implemented as "experimental high cadence"
That option changes the erps from 520 to 700, but also the foc angle from 80 to 115 and can go to 130 rpm cadence.
stancecoke said:
.... With the limit of 520 we get 30 points on the sine- curve per revolution at the PWM frequency of 15625 Hz....
imho this could be one the reasons why Casainho increased the PWM to 19kHz
 
casainho said:
I really hope we can merge TSDZ2 wireless standard project and this one in the future, so everyone can enjoy the most updated firmware and features.

Both changes (Current ADC sampling, and new PAS algorihm) are quite easy to implement.
For the battery current ADC just replace the code
Code:
ui16_g_adc_battery_current = UI16_ADC_10_BIT_BATTERY_CURRENT;
with
Code:
ui16_g_adc_battery_current = ADC1->DRH;
ui8_temp= ADC1->DRL;
ui16_g_adc_battery_current = (ui16_g_adc_battery_current << 2) |  (uint16_t)(ui8_temp & 0x03);

and the new PAS algorithm is the following and i think it is self explanatory.

Code:
    /*
     * - New pedal start/stop detection Algorithm (by MSpider65) -
     *
     * Pedal start/stop detection uses both transitions of both PAS sensors
     * ui8_pas_state stores the PAS1 and PAS2 state: bit0=PAS1,  bit1=PAS2
     * Pedal forward ui8_pas_state sequence is: 0x01 -> 0x00 -> 0x02 -> 0x03 -> 0x01
     * After a stop, the first forward transition is taken as reference transition
     * Following forward transition sets the cadence to 7RPM for immediate startup
     * Then, starting form the second reference transition, the cadence is calculated based on counter value
     * All transitions resets the stop detection counter (much faster stop detection):
     */

// cadence sensor variables
#define NO_PAS_REF 5
#define CADENCE_TICKS_STARTUP 6250 // about 7-8 RPM
#define CADENCE_SENSOR_STANDARD_MODE_SCHMITT_TRIGGER_THRESHOLD    350

volatile uint16_t ui16_cadence_sensor_ticks = 0;
volatile uint32_t ui32_crank_revolutions_x20 = 0;
static uint16_t ui16_cadence_sensor_ticks_counter_min = CADENCE_SENSOR_CALC_COUNTER_MIN;
static uint8_t ui8_pas_state_old = 4;
static uint16_t ui16_cadence_calc_counter, ui16_cadence_stop_counter;
static uint8_t ui8_cadence_calc_ref_state = NO_PAS_REF;
static uint8_t ui8_pas_old_valid_state[4] = { 0x01, 0x03, 0x00, 0x02 };

    uint8_t ui8_pas_state = (PAS1__PORT->IDR & PAS1__PIN) | ((PAS2__PORT->IDR & PAS2__PIN) >> 6);

    if (ui8_pas_state != ui8_pas_state_old) {
        if (ui8_pas_state_old != ui8_pas_old_valid_state[ui8_pas_state]) {
            // wrong state sequence: backward rotation
            ui16_cadence_sensor_ticks = 0;
            ui8_cadence_calc_ref_state = NO_PAS_REF;
            goto skip_cadence;
        }

        ui16_cadence_sensor_ticks_counter_min = ui16_cadence_sensor_ticks_counter_min_speed_adjusted;

        if (ui8_pas_state == ui8_cadence_calc_ref_state) {
            // ui16_cadence_calc_counter is valid for cadence calculation
            ui16_cadence_sensor_ticks = ui16_cadence_calc_counter;
            ui16_cadence_calc_counter = 0;
            // software based Schmitt trigger to stop motor jitter when at resolution limits
            ui16_cadence_sensor_ticks_counter_min += CADENCE_SENSOR_STANDARD_MODE_SCHMITT_TRIGGER_THRESHOLD;
        } else if (ui8_cadence_calc_ref_state == NO_PAS_REF) {
            // this is the new reference state for cadence calculation
            ui8_cadence_calc_ref_state = ui8_pas_state;
            ui16_cadence_calc_counter = 0;
        } else if (ui16_cadence_sensor_ticks == 0) {
            // Waiting the second reference transition: set the cadence to 7 RPM for immediate start
            ui16_cadence_sensor_ticks = CADENCE_TICKS_STARTUP;
        }
        // Reference state for crank revolution counter increment
        if (ui8_pas_state == 0)
            ui32_crank_revolutions_x20++;

        skip_cadence:
        // reset the counter used to detect pedal stop
        ui16_cadence_stop_counter = 0;
        // save current PAS state
        ui8_pas_state_old = ui8_pas_state;
    }

    if (++ui16_cadence_stop_counter > ui16_cadence_sensor_ticks_counter_min) {
        // pedals stop detected
        ui16_cadence_sensor_ticks = 0;
        ui16_cadence_stop_counter = 0;
        ui8_cadence_calc_ref_state = NO_PAS_REF;
    } else if (ui8_cadence_calc_ref_state != NO_PAS_REF) {
        // increment cadence tick counter
        ++ui16_cadence_calc_counter;
    }

casainho said:
A video showing the Garmin GPS cycling computer controlling the battery voltage to turn on / off the motor -- changing assist level on the display and when value is zero it disable the motor voltage:
I am happy to see that the fully wireless TSDZ2 project is going well :)
 
stancecoke said:
mspider65 said:
For this reason, I think that by setting a higher value of max ERPS it will be possible
This limit exists to make sure to get a proper sinusodial shape of the phase current. If you get two less PWM updates per electric revolution, you won't get an proper current shape. With the limit of 520 we get 30 points on the sine- curve per revolution at the PWM frequency of 15625 Hz.

regards
stancecoke

Thanks, you are right. Also the PWM frequency should be increased in order to have a correct interpolation of the phase current.
Maybe it's better if I take some time to reread the theory of electric motors :)
 
mspider65 said:
hefest said:
Any progress on supporting tsdz2 firmware v1.0.0?

The Controller protocol and firmware parameters are different and the porting involves all the layers (ESP32 and Android app.), and since I am really satisfied with the current firmware, i don't have in plan (at least for now) to port the v1.0.0.

Didn't you tell me when I was buying esp32 controller from you that you plan to upgrade to 1.0? I'm pretty sure because I asked.
 
Back
Top