TSDZ2 EBike wireless standard (like Specialized Turbo Levo) - OpenSource

rananna said:
On the good news/bad news front, I have tracked down the intermittent unresponsiveness of the remote issue.
Unfortunately, it relates to the sdk pwm implementation of Nordic's that I am using for LED control. There appears to be a timer conflict with the s340 soft device that causes intermittent hangups.
I cannot find any fix to the issue.
So, I undertook today to rewrite the firmware to eliminate pwm control. Needless to say, as I had spent considerable time implementing pwm, I was disappointed to have to do this.
However, most battery power loss is due to the time spent NOT riding the bike, so there should be minimal power hit due to this change.
Anyway, the firmware now appears stable and I gave not seen any intermittent hangs.
So, that bug seems to be squashed.

I want to write a testing checklist this evening to follow tomorrow to be sure the firmware works well, and I should be able to send you a release candidate along with updated docs later that day.

Ok - so you're no longer enabling softblink or pwm_low_power in the SDK? I'd enabled them in the latest PR to the wireless controller as I planned to add the LED control in so I should remove if so...
 
beemac said:
rananna said:
On the good news/bad news front, I have tracked down the intermittent unresponsiveness of the remote issue.
Unfortunately, it relates to the sdk pwm implementation of Nordic's that I am using for LED control. There appears to be a timer conflict with the s340 soft device that causes intermittent hangups.
I cannot find any fix to the issue.
So, I undertook today to rewrite the firmware to eliminate pwm control. Needless to say, as I had spent considerable time implementing pwm, I was disappointed to have to do this.
However, most battery power loss is due to the time spent NOT riding the bike, so there should be minimal power hit due to this change.
Anyway, the firmware now appears stable and I gave not seen any intermittent hangs.
So, that bug seems to be squashed.

I want to write a testing checklist this evening to follow tomorrow to be sure the firmware works well, and I should be able to send you a release candidate along with updated docs later that day.
yes, you can remove it.
Ok - so you're no longer enabling softblink or pwm_low_power in the SDK? I'd enabled them in the latest PR to the wireless controller as I planned to add the LED control in so I should remove if so...
 
beemac said:
On the good news/bad news front, I have tracked down the intermittent unresponsiveness of the remote issue.
Unfortunately, it relates to the sdk pwm implementation of Nordic's that I am using for LED control. There appears to be a timer conflict with the s340 soft device that causes intermittent hangups.
I cannot find any fix to the issue.
So, I undertook today to rewrite the firmware to eliminate pwm control. Needless to say, as I had spent considerable time implementing pwm, I was disappointed to have to do this.
However, most battery power loss is due to the time spent NOT riding the bike, so there should be minimal power hit due to this change.
Anyway, the firmware now appears stable and I gave not seen any intermittent hangs.
So, that bug seems to be squashed.

I want to write a testing checklist this evening to follow tomorrow to be sure the firmware works well, and I should be able to send you a release candidate along with updated docs later that day.

Ok - so you're no longer enabling softblink or pwm_low_power in the SDK? I'd enabled them in the latest PR to the wireless controller as I planned to add the LED control in so I should remove if so...

Yes you can remove it
 
beemac said:
Ok if it was just one sample then I think for now leave that info out about the 'bad stlink version' - as the bad board also looked burned from the photos you posted and without any information on errors or similar it may cause confusion.
That STLink were able to connect and detect the STM8 but only when flashing it gives the timeout. And it worked perfeclty for the NRF52.
 
rananna said:
beemac said:
Ok - so you're no longer enabling softblink or pwm_low_power in the SDK? I'd enabled them in the latest PR to the wireless controller as I planned to add the LED control in so I should remove if so...

Yes you can remove it

Ok thanks will do.
 
casainho said:
beemac said:
Ok if it was just one sample then I think for now leave that info out about the 'bad stlink version' - as the bad board also looked burned from the photos you posted and without any information on errors or similar it may cause confusion.
That STLink were able to connect and detect the STM8 but only when flashing it gives the timeout. And it worked perfeclty for the NRF52.

Ok thanks - I'll update if we see anyone else having similar issues.

On the problem I was having yesterday where assist would randomly change when the motor was spinning - it's not a bug in code. I'm pretty sure now it's electrical. Only happens on one of my boards - and if I ground the board separately the issue stops happening. I'll check my wiring but something we should be aware of.
 
beemac said:
if I ground the board separately the issue stops happening. I'll check my wiring but something we should be aware of.
I already burned some boards and had a lot of issues because of the ground and because I must use the STLinkv2 connected to my computer, that is connected to mains. We need to be very careful, development is different and more difficult than the final system.
 
casainho said:
beemac said:
if I ground the board separately the issue stops happening. I'll check my wiring but something we should be aware of.
I already burned some boards and had a lot of issues because of the ground and because I must use the STLinkv2 connected to my computer, that is connected to mains. We need to be very careful, development is different and more difficult than the final system.

Hi - I think there may be a problem with the main loop for the wireless controller. Unless the comments are old - it should only be entering the processing loop 20 times second - but it does it more like 200 times a second.

The problem I think is because the outer while loop is spinning faster than expected - so it re-enters with the same value of main_ticks a few times so the modulo equals zero for 10 or so cycles. Without the 45ms delay I record about 200 loops per second - which drops back to 21 with the delay.

I first noticed something odd might be going on when I added the button code - I had to fudge one of the button timer constants otherwise the button presses needed to be really quick to register but I didn't look too much into it.

I'll make it skip if it re-enters with the same tick value and test...

Slowing the loop down also seems to make the assist changing stop - maybe the button press debounce/filtering can work properly now. Probably saves some power too!

Here's my test code and the loop - just in case I've done something stupid! :)

Code:
while (1)
  {
    // every 50 ms
    if (main_ticks % (50 / MSEC_PER_TICK) == 0)
    {
      ui16_loopspersecondcounter++;
      if ((get_time_base_counter_1ms() - ui32_timeoflastsamplems) > 1000)
      {
        ui32_timeoflastsamplems = get_time_base_counter_1ms();
        ui16_loopspersecond = ui16_loopspersecondcounter;
        ui16_loopspersecondcounter = 0;
      }


      nrf_delay_ms(45);
      // exchange data from realtime layer to UI layer
      // do this in atomic way, disabling the real time layer (should be no problem as
      // copy_rt_to_ui_vars() should be fast and take a small piece of the 50ms periodic realtime layer processing
      rt_processing_stop();
      copy_rt_ui_vars();
      rt_processing_start();

      ble_send_periodic_data();
      ble_update_configurations_data();
      TSDZ2_power_manage();

      walk_assist_state();
      handle_buttons();
      //alternatField(); // Removed until we can resolve what to do with the alternate state display requirements
      streetMode();
    }


Edit - ok yes as a quick test updating the loop so it skips if it re-enters with the same tick value drops the loops_per_second down to 25-30.. Still oddly a bit quick but much better!

Code:
  while (1)
  {
    // every 50 ms
    if (main_ticks % (50 / MSEC_PER_TICK) == 0)
    {
      ui32_thistrigger = main_ticks;
      if (ui32_lasttrigger != ui32_thistrigger) 
      {
        ui32_lasttrigger = ui32_thistrigger;

        ui16_loopspersecondcounter++;
        if ((get_time_base_counter_1ms() - ui32_timeoflastsamplems) > 1000)
        {
          ui32_timeoflastsamplems = get_time_base_counter_1ms();
          ui16_loopspersecond = ui16_loopspersecondcounter;
          ui16_loopspersecondcounter = 0;
        }

        // exchange data from realtime layer to UI layer
        // do this in atomic way, disabling the real time layer (should be no problem as
        // copy_rt_to_ui_vars() should be fast and take a small piece of the 50ms periodic realtime layer processing
        rt_processing_stop();
        copy_rt_ui_vars();
        rt_processing_start();

        ble_send_periodic_data();
        ble_update_configurations_data();
        TSDZ2_power_manage();

        walk_assist_state();
        handle_buttons();
        //alternatField(); // Removed until we can resolve what to do with the alternate state display requirements
        streetMode();
      }
    }
 
I did a ride yesterday and also today. I removed the wheel speed sensor with the expectation I could see the speed on the Garmin Edge, calculated from the GPS - when I have the TSDZ2 connected, the wheel speed is 0 and I expected I could use an invalid value on ANT+ LEV profile and so the Edge would then use the GPS calculated speed, but turns out there is no invalid value, the speed value is required on ANT+ LEV...
 
casainho said:
I did a ride yesterday and also today. I removed the wheel speed sensor with the expectation I could see the speed on the Garmin Edge, calculated from the GPS - when I have the TSDZ2 connected, the wheel speed is 0 and I expected I could use an invalid value on ANT+ LEV profile and so the Edge would then use the GPS calculated speed, but turns out there is no invalid value, the speed value is required on ANT+ LEV...

Yes, the garmin treats the ebike as a 'sensor' and grabs all available data from that sensor for use in the display, even if it is invalid or missing!
If we cannot find a workaround for the garmin bike computers, we probably have to implement the ANT+ cadence/speed profile to grab that data from the sensor for use in the ANT LEV profile.
more work to do....
 
rananna said:
casainho said:
I did a ride yesterday and also today. I removed the wheel speed sensor with the expectation I could see the speed on the Garmin Edge, calculated from the GPS - when I have the TSDZ2 connected, the wheel speed is 0 and I expected I could use an invalid value on ANT+ LEV profile and so the Edge would then use the GPS calculated speed, but turns out there is no invalid value, the speed value is required on ANT+ LEV...

Yes, the garmin treats the ebike as a 'sensor' and grabs all available data from that sensor for use in the display, even if it is invalid or missing!
If we cannot find a workaround for the garmin bike computers, we probably have to implement the ANT+ cadence/speed profile to grab that data from the sensor for use in the ANT LEV profile.
more work to do....
I contacted garmin support to ask them about this.
SUPPORT CENTER
CHAT
Session started between Kelsey and rananna.
Please give me a moment to look into your issue and I will be right with you.

rananna:Is it possible to use speed data from a speed/cadence sensor or the built in gps if I have connected an ANT LEV enabled bike? I would like the garmin to ignore the speed data sent by ANT LEV and use the speed/cadence sensor.

Kelsey:Hi rananna! One moment and I'll check for you.

rananna:thanks!
Kelsey:Thanks for waiting! If you use a speed + cadence sensor with your Edge (or Garmin watch), that'll override the ANT LEV bike's own sensor.

rananna:eek:k thanks, is there anyway to set the sensor priority in the configuration settings?

Kelsey:Unfortunately, no

rananna:Final question: Can you tell the edge to ignore speed data from ANT LEV and speed/cadence sensors and ONLY use the GPS info from the edge?

Kelsey:And still use the ANT LEV, correct?

rananna:yes.

Kelsey:Unfortunately, no.

rananna:eek:k, thank you for your help!
rananna:goodbye...

Kelsey:Thanks for choosing Garmin. Have a great day!-Kelsey

Kelsey:I hope that I was able to help you today. Please re-contact us if you require further assistance.Kelsey has exited the session.I hope that I was able to help you today. Please re-contact us if you require further assistance.

so it appears that if a user adds an external speed or speed/cadence sensor it will override the ANT LEV data, which is good as it means we do not have to implement another profile, but , there is no way to use the GPS speed with ANT LEV and no speed sensor, which is not as good.

However, I would expect that a lot of users with bike computers already have the speed/cadence sensor already on their bikes. They are not too expensive and easy to install.
 
@casainho,
For the remote I fixed the latest bugs , updated the docs and submitted a release candidate Pull request for your testing.
 
I know you guys are busy here. Question, from "OpenSourceEBike.github.io", Flashing with Ubuntu, "openocd -f stlink-v2.cfg -f nrf52.cfg".

I get an error in the nrf52.cfg file line 28, i.e.
rf52.cfg:28: Error: invalid command name "dap"
in procedure 'script'
at file "embedded:startup.tcl", line 60
at file "nrf52.cfg", line 28

I am trying to run this server setup from /usr/bin and have copied the two noted cfg files here also?

Really enjoy following this thread, and look forward to the release. :bigthumb:
 
Tiger_one said:
I know you guys are busy here. Question, from "OpenSourceEBike.github.io", Flashing with Ubuntu, "openocd -f stlink-v2.cfg -f nrf52.cfg".

I get an error in the nrf52.cfg file line 28, i.e.
rf52.cfg:28: Error: invalid command name "dap"
in procedure 'script'
at file "embedded:startup.tcl", line 60
at file "nrf52.cfg", line 28

I am trying to run this server setup from /usr/bin and have copied the two noted cfg files here also?

Really enjoy following this thread, and look forward to the release. :bigthumb:

Check the documentation here - this might help = https://opensourceebike.github.io/stlinkv2.html

Please report back if it helps so we can update the docs.
 
rananna said:
@casainho,
For the remote I fixed the latest bugs , updated the docs and submitted a release candidate Pull request for your testing.
Code:
  //set variables for ANT transmission in order of connectIQ fields
  // 1. lev speed
  p_profile->common.lev_speed = ui_vars.ui16_wheel_speed_x10 / 10;
Is not this piece of code wrong? The specifications says: The LEV Speed is a 12 bit value representing the current speed of the LEV in 0.1 km/h.

I think ui16_wheel_speed_x10 should not be divided by 10, right?
 
casainho said:
rananna said:
@casainho,
For the remote I fixed the latest bugs , updated the docs and submitted a release candidate Pull request for your testing.
Code:
  //set variables for ANT transmission in order of connectIQ fields
  // 1. lev speed
  p_profile->common.lev_speed = ui_vars.ui16_wheel_speed_x10 / 10;
Is not this piece of code wrong? The specifications says: The LEV Speed is a 12 bit value representing the current speed of the LEV in 0.1 km/h.

I think ui16_wheel_speed_x10 should not be divided by 10, right?
Yes, you are right.
Please make the change.
 
rananna said:
casainho said:
rananna said:
@casainho,
For the remote I fixed the latest bugs , updated the docs and submitted a release candidate Pull request for your testing.
Code:
  //set variables for ANT transmission in order of connectIQ fields
  // 1. lev speed
  p_profile->common.lev_speed = ui_vars.ui16_wheel_speed_x10 / 10;
Is not this piece of code wrong? The specifications says: The LEV Speed is a 12 bit value representing the current speed of the LEV in 0.1 km/h.

I think ui16_wheel_speed_x10 should not be divided by 10, right?
Yes, you are right.
Please make the change.
Done. I also put the ANT+ LEV motor temperature:

Code:
  //8. motor temperature
  //one byte, bits 4-6
  //000 unknown
  //001  cold
  //010 cold/warm
  //011 warm
  //100 warm/hot
  //101 hot

  uint8_t temp = ui_vars.ui8_motor_temperature;
  uint8_t temp_max = ui_vars.ui8_motor_temperature_max_value_to_limit;
  uint8_t temp_min = ui_vars.ui8_motor_temperature_min_value_to_limit;
  uint8_t lev_temp;
  if (temp < 20) // cold
    lev_temp = 0b001;
  else if (temp < 50) // cold/warm
    lev_temp = 0b010;
  else if (temp < temp_min) // warm
    lev_temp = 0b011;
  else if (temp < temp_max) // warm/hot
    lev_temp = 0b100;
  else // hot
    lev_temp = 0b101;
  
  p_profile->page_1.temperature_state = lev_temp;

And I moved the disp_soc to common - please try think the code that should be reused and put on the common.c.

disp_soc(int soc) can now be used both on TSDZ2 wireless and remote firmware:

Code:
void disp_soc(int soc)
{
  nrf_delay_ms(500);
  for (int i = 0; i < soc; i++)
  {
    bsp_board_led_on(LED_B__PIN);
    nrf_delay_ms(300);
    bsp_board_led_off(LED_B__PIN);
    nrf_delay_ms(300);
  }
}

New testing release v0.6.2 - I tested and seems to work well, I really like the LED colors and the flash frequency :)

https://github.com/OpenSourceEBike/TSDZ2_wireless/releases/tag/v0.6.0
 
beemac said:
Tiger_one said:
I know you guys are busy here. Question, from "OpenSourceEBike.github.io", Flashing with Ubuntu, "openocd -f stlink-v2.cfg -f nrf52.cfg".

I get an error in the nrf52.cfg file line 28, i.e.
rf52.cfg:28: Error: invalid command name "dap"
in procedure 'script'
at file "embedded:startup.tcl", line 60
at file "nrf52.cfg", line 28

I am trying to run this server setup from /usr/bin and have copied the two noted cfg files here also?

Really enjoy following this thread, and look forward to the release. :bigthumb:

Check the documentation here - this might help = https://opensourceebike.github.io/stlinkv2.html

Please report back if it helps so we can update the docs.
Yes, this link enabled me to upgrade the STLinkV2 I purchased from Ecco Cycles!
Upgraded in macOS Big Sur 11.2. Must open security to permit to run java GUI and install needed lib which is included in upgrade download from STMicroelectronics website.
Tks
 
Tiger_one said:
beemac said:
Tiger_one said:
I know you guys are busy here. Question, from "OpenSourceEBike.github.io", Flashing with Ubuntu, "openocd -f stlink-v2.cfg -f nrf52.cfg".

I get an error in the nrf52.cfg file line 28, i.e.
rf52.cfg:28: Error: invalid command name "dap"
in procedure 'script'
at file "embedded:startup.tcl", line 60
at file "nrf52.cfg", line 28

I am trying to run this server setup from /usr/bin and have copied the two noted cfg files here also?

Really enjoy following this thread, and look forward to the release. :bigthumb:

Check the documentation here - this might help = https://opensourceebike.github.io/stlinkv2.html

Please report back if it helps so we can update the docs.
Yes, this link enabled me to upgrade the STLinkV2 I purchased from Ecco Cycles!
Upgraded in macOS Big Sur 11.2. Must open security to permit to run java GUI and install needed lib which is included in upgrade download from STMicroelectronics website.
Tks

Great - and to confirm now you can flash the bootloader fw ok now that you've upgraded the stlink? You don't get the "invalid command name "dap"" anymore?
 
beemac said:
Great - and to confirm now you can flash the bootloader fw ok now that you've upgraded the stlink? You don't get the "invalid command name "dap"" anymore?
Nope, same error message. (to be clear, only "STLinkV2" in USB, no "nRF52840 dongle" until tomorrow)
P.S. I'm in VirtualBox on my mac with Ubuntu install for build of "OSF wireless"
 
My STLink-v2 is setup for flashing the TSDZ2 via Speed sensor connection.

Is it possible to make the nRF52840 dongle flash connection via this connector, I.E. is the SWDIO and SWDCLK pins available. My STLink-v2 is in a shrink-wrap, so can not see wiring. Thinking NO. So I will be opening up the shrink-wrap.

Ebike_wireless_bootloader-schematic.png

P.S. I have asked this question to ECO-Bike will reply with answer
 
rananna said:
@casainho,
For the remote I fixed the latest bugs , updated the docs and submitted a release candidate Pull request for your testing.

@casainho & @rannanna

I had a bit of time today and thought it would be nice to actually write some code instead of copy pasting and bug fixing! :) I wanted to put some led control in the wireless controller - as it would be really useful when running headless or if the phone is in your pocket (and you don't have a remote of course!). I didn't want the led sequences to block - so I've knocked up a simple led sequence player that can be clocked at whatever rate we want. It works ok - but haven't done a pull request as it needs a bit more testing - and I need to create all the sequence definitions from rananna's docs.

https://github.com/4var1/TSDZ2_wireless/blob/led-alert/EBike_wireless_TSDZ2/firmware/ledalert.c

You can queue up led sequences with a single call - and let it get on with it.

If I get some more time later I'll post an exciting video...
 
Tiger_one said:
My STLink-v2 is setup for flashing the TSDZ2 via Speed sensor connection.

Is it possible to make the nRF52840 dongle flash connection via this connector, I.E. is the SWDIO and SWDCLK pins available. My STLink-v2 is in a shrink-wrap, so can not see wiring. Thinking NO. So I will be opening up the shrink-wrap.

Ebike_wireless_bootloader-schematic.png

P.S. I have asked this question to ECO-Bike will reply with answer

I don't really understand the question - you don't flash anything to do with the nrf with that connector...

Read the docs for the Open Source firmware first if you haven't already flashed your motor.
 
beemac said:
Tiger_one said:
My STLink-v2 is setup for flashing the TSDZ2 via Speed sensor connection.

Is it possible to make the nRF52840 dongle flash connection via this connector, I.E. is the SWDIO and SWDCLK pins available. My STLink-v2 is in a shrink-wrap, so can not see wiring. Thinking NO. So I will be opening up the shrink-wrap.

Ebike_wireless_bootloader-schematic.png

P.S. I have asked this question to ECO-Bike will reply with answer

I don't really understand the question - you don't flash anything to do with the nrf with that connector...

Read the docs for the Open Source firmware first if you haven't already flashed your motor.
Mine is enclosed with heat shrink so don't know the pinout. We do use it to flash the boot loader to both nRF52840s do we not?

20210208_133032.jpg
ECO-Cycles reply: for anyone else that may have this STLink-V2
"Hi,
It's just the 3.3v, GND, and SWIM.
We used to do the 5v, GND, SWIM, and RST, but the above works more reliably.
Here is the wiring colors for the 6 pin line:
brown: 3.3v-5V (VCC)
black: SWIM
orange: ROUND (GND)
red/purple: RESET (RST) - NOT USED
green: headlight 6V – NOT USED
white/yellow : speed sensor input – NOT USED"
 
Back
Top