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

casainho said:
Eremit said:
If so, we really need some safety measures here: Faster auto switch off with no motor turns, despite of Watt usage above... 20 Watt or something like that for instance? Or could have a configured switch off save me from that?
Sorry for what happened.

No problem. For the fun I have with that motor under that software, I'm willing to do some mine-finding-dog job ;)

casainho said:
That's true, there is no such protection. On KT motor controllers firmware I did implement that, like if after 3 seconds of having duty-cycle/energy to the motor, if the bicycle wheel speed < min speed value, then the motor energy is turned off until torque sensor AND throttle are zero.

I didn't bring that code/protection from the other firmware to simplify when I started the project and then, guess what :)

That you will bring this part of code to the tongsheng also very soon? :wink: Pleeeaaase...!
 
Eremit said:
casainho said:
That's true, there is no such protection. On KT motor controllers firmware I did implement that, like if after 3 seconds of having duty-cycle/energy to the motor, if the bicycle wheel speed < min speed value, then the motor energy is turned off until torque sensor AND throttle are zero.

I didn't bring that code/protection from the other firmware to simplify when I started the project and then, guess what :)

That you will bring this part of code to the tongsheng also very soon? :wink: Pleeeaaase...!
Done. It is now on master branch (I push the code to master because it is bug solve code).

This is the code - for me seems to be ok but maybe users will ask to increase the 3 seconds time. If we stay more than 3 seconds pushing the pedals or throttle but wheel do not move, power to motor will be shutoff and LCD3 will show an error number (1), flashing on odometer field. As soon torque sensor and throttle = 0, will stay on the error state if during the 3 consecutive seconds for torque sensor and throttle = 0.

Code:
static void safe_tests (void)
{
  switch (safe_tests_state_machine)
  {
    // start when we have torque sensor or throttle
    case 0:
    if (ui8_torque_sensor_raw || ui8_throttle)
    {
      safe_tests_state_machine_counter = 0;
      safe_tests_state_machine = 1;
      break;
    }
    break;

    // wait during 3 seconds for bicyle wheel speed > 4km/h, if not we have an error
    case 1:
    safe_tests_state_machine_counter++;

    // timeout of 3 seconds, not less to be higher than value on torque_sensor_read ()
    // 3 seconds should be safe enough value, mosfets should not burn in 3 seconds if ebike wheel is blocked
    if (safe_tests_state_machine_counter > 30)
    {
      configuration_variables.ui8_error_states |= ERROR_STATE_EBIKE_WHEEL_BLOCKED;
      safe_tests_state_machine_counter = 0;
      safe_tests_state_machine = 2;
      break;
    }

    // bicycle wheel is rotating so we are safe
    if (ui16_wheel_speed_x10 > 40) // seems that 4km/h may be the min value we can measure for the bicycle wheel speed
    {
      safe_tests_state_machine_counter = 0;
      safe_tests_state_machine = 3;
      break;
    }
    break;

    // wait 3 consecutive seconds for torque sensor and throttle = 0, then we can restart
    case 2:
    if ((ui8_torque_sensor_raw == 0) && (ui8_throttle == 0))
    {
      safe_tests_state_machine_counter++;

      if (safe_tests_state_machine_counter > 30)
      {
        configuration_variables.ui8_error_states &= ~ERROR_STATE_EBIKE_WHEEL_BLOCKED;
        safe_tests_state_machine = 0;
        break;
      }
    }
    // keep reseting the counter so we keep on this state
    else
    {
      safe_tests_state_machine_counter = 0;
    }
    break;

    // wait for bicycle wheel to be stopped so we can start again our state machine
    case 3:
    if (ui16_wheel_speed_x10 == 0)
    {
      safe_tests_state_machine = 0;
      break;
    }
    break;

    default:
    safe_tests_state_machine = 0;
    break;
  }
}
 
like i proposed with my code changes. wouldn't it make sense to include the whole safety logic in one function at the end before powering the motor? so in the other parts of the code no safety checks have and shall be made?
so similar to this code below but with added logic? maybe adding codes on the display so it can easily reproduced why it doesnt run?

code 00000 = running
code 0001 = brake_set
code 0002 = no torque not throttle
....
this could be always shown

this fundament safety functions would not change often so when small extra features added code is always safe...

Code:
static void ebike_run_motor(uint8_t ui8_adc_battery_target_current)
{

  /* Safetiy Checks before running Motor */
  ui8_motor_state = MOTOR_OFF;  
  // check brake and Assist Level > 0
  if(!brake_is_set() && configuration_variables.ui8_power_regular_state_div25 > 0) 
  {
    // instant assistance disabled / secure mode
    if(!configuration_variables.ui8_motor_assistance_startup_without_pedal_rotation)
    {
      // no throttle mode
      if(ui8_safe_throttle==0)
      {
        // cadence torque and wheel speed > 0 then start motor maybe too secure?
        if ((ui8_safe_pas_cadence_rpm > 0) && (ui8_safe_torque_sensor > 0) && (ui16_safe_wheel_speed_x10 > 0)) { ui8_motor_state = MOTOR_ON;}
      } 
      // throttle mode
      else if (ui8_safe_throttle > 0)
      {
        // wheel turns then start motor
        if(ui16_safe_wheel_speed_x10 > 0) { ui8_motor_state = MOTOR_ON;}
      }
    // instant assistance enabled / risky mode
    } else {
       // throttle or torque 
       if (ui8_safe_throttle > 0 || ui8_safe_torque_sensor > 0){
         // only active until 5kmh (safety)
         if(ui16_safe_wheel_speed_x10 < 50) { ui8_motor_state = MOTOR_ON;}
       }
    }
  }

  // Motor should run and we have a current - set current and pwm
  if(ui8_motor_state == MOTOR_ON && ui8_adc_battery_target_current > 0){
    ebike_app_set_target_adc_battery_max_current(ui8_adc_battery_target_current);
    motor_set_pwm_duty_cycle_target (255);
  // Motor stop / Reset values
  } else {   
    ebike_app_set_target_adc_battery_max_current (0);
    motor_set_pwm_duty_cycle_target (0);    
  }
}
 
After testing, seems the issue I was having with boost not happening now is gone. I hope to ride more and see if it is really ok.

Next thing I should look for is to the EEPROM default values because there are some that are always incorrect!!

vscope said:
like i proposed with my code changes. wouldn't it make sense to include the whole safety logic in one function at the end before powering the motor? so in the other parts of the code no safety checks have and shall be made?
As you can see, now that I had to take care of the priority issue, I did follow your idea but only for the new needed bits.
 
maybe we should add a eeprom config version number to the builds.check on boot if eeprom version in build not the same as eeprom version saved in eeprom. clear eeprom and set defaults from build. if no changes in eeprom layout no reset to default needed eg minor fixes in code
 
vscope said:
maybe we should add a eeprom config version number to the builds.check on boot if eeprom version in build not the same as eeprom version saved in eeprom. clear eeprom and set defaults from build. if no changes in eeprom layout no reset to default needed eg minor fixes in code
That is done already, I am not sure if EC is changing that number when releases a new version.
 
EndlessCadence said:
casainho said:
Done. It is now on master branch (I push the code to master because it is bug solve code).
Thanks, good enough for now but for the future can you create issues and pull requests for bugs too? This automatically results in release notes amongst other things. Now users don't know what has been fixed etc.
ok I will.
 
casainho said:
EndlessCadence said:
casainho said:
Done. It is now on master branch (I push the code to master because it is bug solve code).
Thanks, good enough for now but for the future can you create issues and pull requests for bugs too? This automatically results in release notes amongst other things. Now users don't know what has been fixed etc.
ok I will.
Perfect, thanks!

I'm creating an issue and PR for you. Let's keep master clean at all times, alright? :wink:
 
EndlessCadence said:
I'm creating an issue and PR for you. Let's keep master clean at all times, alright? :wink:
EndlessCadence said:
I create a branch for every bugfix or feature and the create a pull request to master (for bugs) or development (for large features or refactoring of code).
I did not create the specific branch but at least put the code on master.
 
casainho said:
EndlessCadence said:
I'm creating an issue and PR for you. Let's keep master clean at all times, alright? :wink:
EndlessCadence said:
I create a branch for every bugfix or feature and the create a pull request to master (for bugs) or development (for large features or refactoring of code).
I did not create the specific branch but at least put the code on master.
Well I have a hard time fixing master right now! Did you do a forced push?
It seems that your local master wasn't up to date and you've pushed the changes (thus resetting master)?

Edit: issues with the master branch are now fixed. Can you verify the pull request for me?
https://github.com/OpenSource-EBike-firmware/TSDZ2-Smart-EBike/pull/23
 
EndlessCadence said:
casainho said:
EndlessCadence said:
I'm creating an issue and PR for you. Let's keep master clean at all times, alright? :wink:
EndlessCadence said:
I create a branch for every bugfix or feature and the create a pull request to master (for bugs) or development (for large features or refactoring of code).
I did not create the specific branch but at least put the code on master.
Well I have a hard time fixing master right now! Did you do a forced push?
It seems that your local master wasn't up to date and you've pushed the changes (thus resetting master)?

Edit: issues with the master branch are now fixed. Can you verify the pull request for me?
https://github.com/OpenSource-EBike-firmware/TSDZ2-Smart-EBike/pull/23
I did a commit but after had to pull master. A merged did happen automatically, I think. I didn force nothing.

I just found the issue about EEPROM, I tested the solution a few times and seems to work. Created a pull request to master and did the merge.
 
Hello,
I am using the latest version 0.14.2.
What is the best way to turn on the light using the lcd3 button?
I use the BuM LED front light for e-bikes with an input voltage of 6 to 42 volts.
At the moment the LED is connected directly to the battery.
 
casainho said:
Eremit said:
casainho said:
That's true, there is no such protection. On KT motor controllers firmware I did implement that, like if after 3 seconds of having duty-cycle/energy to the motor, if the bicycle wheel speed < min speed value, then the motor energy is turned off until torque sensor AND throttle are zero.

I didn't bring that code/protection from the other firmware to simplify when I started the project and then, guess what :)

That you will bring this part of code to the tongsheng also very soon? :wink: Pleeeaaase...!
Done. It is now on master branch (I push the code to master because it is bug solve code).


Man, that was fast. Thank you a lot!
 
Does XH18 work? (with an already configured by LCD3 motor, to the limited settings that it has)

Do you know if LCD5 is compatible i.e. runs LCD3 software, common segments are same positions, but just lacks some segments)
 
Is there a measured motor R for 36V motor(two winding - value across terminals)?

Jur calculates 0.93 https://endless-sphere.com/forums/viewtopic.php?f=30&t=93818&p=1377461&hilit=ohm#p1377461 using R ~ N

with is the same (0.94) as cas reports here: https://endless-sphere.com/forums/viewtopic.php?f=28&t=79788&p=1379745&hilit=ohms#p1379745

I am suspicious as R ~ N^2 for constant winding volume, and so 36V would be expected to be ~ 0.7ohm single
 
Hi everyone and very big thanks to casainho and jbalat. Also thanks everyone who has been involved in to developing open source TSDZ2.

I have 250 w tsdz2 with 36V battery. I have been driven it now almost 3000 km.

I ordered KT-LCD3 and stlink v2 for open source project.

Now I’m wondering how do I connect throttle cable to KT-LCD3? Do I have to solder it somewhere to KT-LCD3? In LCD5 display throttle cable is connected with connector.
 
dameri said:
Hi everyone and very big thanks to casainho and jbalat. Also thanks everyone who has been involved in to developing open source TSDZ2.

I have 250 w tsdz2 with 36V battery. I have been driven it now almost 3000 km.

I ordered KT-LCD3 and stlink v2 for open source project.

Now I’m wondering how do I connect throttle cable to KT-LCD3? Do I have to solder it somewhere to KT-LCD3? In LCD5 display throttle cable is connected with connector.
Do you need a throttle ? With the Opensource firmware just program the last assist mode so that you have super powers, you will not feel any pressure when you peddle.
There are not enough wires in the ktlcd to take the throttle to the top of the display so you will need to break out the throttle wire from the 8 pin connector below. Check out the wiki, there are some pics and wiring info there.

8 pin wiring here
https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/Wire-KT-LCD3-to-TSDZ2
 
I would like to thank Casainho for making all this possible, jbalat for his videos that motivated me to do the mods and EC for all the often mundane hard work he puts in.


What was a very functional but unexciting electric assist drive is now great fun to use and much more economical on the battery too.


I have converted what was the 52v version with throttle and lights and pleased that the throttle and lights still work with your mods. As it turned out the throttle version with the 8 core lead is probably the easier one to modify as the HIGO cable is readily available https://www.e-bike-technologies.de/index.php/en/connectors/higo/higo-main-connectors/higo-b8-detail so I did not need to cut any wiring and can easily revert back to the original system if there are any warranty problems.

On the subject of the throttle I do disagree with jbalat that they are not needed on torque drives as I often find myself on sections of track with ruts where pedalling is not possible. Also on TSDZ2 the walk assist does not work properly and is jerky making the throttle very useful as a walk asssist fuction, unfortunately with the open souce software the throttle seems to have little or no speed control it is either on or off, even though when I look at section 9 at the throttle values I can see it moves linearly from 0 to 255.


Had a few problems programming the motor and found the same as others that the lead needs to be very short but also found not all USB ports are created equal so it's definitely worth swapping ports and pulling anything from other ports that might drain power, in the end I gave up with lap top and now use a PC USB port connected directly to the MB and then a USB extension lead to the STlink dongle and on the odd occasion it still does not work I have to restart the PC. I started off with V13.0 and like others found that although the motor windings were energised (difficult to wheel bike backwards) the motor would not work either from the throttle or pedals even though in section 9 all the sensors indicated as energised. Eventually I decided to program both program memory and the data memory with the zero values that you first get when the ST Visual programmer is started and then load the program memory software on top of that and suddenly it all worked...hours of frustration solved, So I now always wipe the memories with zeros before loading the latest software.



Now a few snags I have found.

I have already mentioned the throttle has no fine control. Which by the way is blue gear very unfriendly.

Version 13.0 did place SOC in the bottom right section of the screen but since then no other version has and it is left blank but when I enable the temp sensing (I don't have a sensor) that is displayed. An option to place other data in that space would also be nice.

Latest default values for power boost are lower than the assist level values.

There is still an intermittent fault where there is a lag before torque assist cuts in which seems to be connected with power boost but I believe you are working on it.

When MPH is selected the distance is still recorded in those kilometer thingies.



But wow, the extension in range this software gives is fantastic, no worries about doing 70 + mile journeys on very hilly terrain now. Thank you.
 
Rafe said:
I would like to thank Casainho for making all this possible, jbalat for his videos that motivated me to do the mods and EC for all the often mundane hard work he puts in.


What was a very functional but unexciting electric assist drive is now great fun to use and much more economical on the battery too.


I have converted what was the 52v version with throttle and lights and pleased that the throttle and lights still work with your mods. As it turned out the throttle version with the 8 core lead is probably the easier one to modify as the HIGO cable is readily available https://www.e-bike-technologies.de/index.php/en/connectors/higo/higo-main-connectors/higo-b8-detail so I did not need to cut any wiring and can easily revert back to the original system if there are any warranty problems.

On the subject of the throttle I do disagree with jbalat that they are not needed on torque drives as I often find myself on sections of track with ruts where pedalling is not possible. Also on TSDZ2 the walk assist does not work properly and is jerky making the throttle very useful as a walk asssist fuction, unfortunately with the open souce software the throttle seems to have little or no speed control it is either on or off, even though when I look at section 9 at the throttle values I can see it moves linearly from 0 to 255.


Had a few problems programming the motor and found the same as others that the lead needs to be very short but also found not all USB ports are created equal so it's definitely worth swapping ports and pulling anything from other ports that might drain power, in the end I gave up with lap top and now use a PC USB port connected directly to the MB and then a USB extension lead to the STlink dongle and on the odd occasion it still does not work I have to restart the PC. I started off with V13.0 and like others found that although the motor windings were energised (difficult to wheel bike backwards) the motor would not work either from the throttle or pedals even though in section 9 all the sensors indicated as energised. Eventually I decided to program both program memory and the data memory with the zero values that you first get when the ST Visual programmer is started and then load the program memory software on top of that and suddenly it all worked...hours of frustration solved, So I now always wipe the memories with zeros before loading the latest software.



Now a few snags I have found.

I have already mentioned the throttle has no fine control. Which by the way is blue gear very unfriendly.

Version 13.0 did place SOC in the bottom right section of the screen but since then no other version has and it is left blank but when I enable the temp sensing (I don't have a sensor) that is displayed. An option to place other data in that space would also be nice.

Latest default values for power boost are lower than the assist level values.

There is still an intermittent fault where there is a lag before torque assist cuts in which seems to be connected with power boost but I believe you are working on it.

When MPH is selected the distance is still recorded in those kilometer thingies.



But wow, the extension in range this software gives is fantastic, no worries about doing 70 + mile journeys on very hilly terrain now. Thank you.
Good report!!

About throttle, it controlls motor current. On KT motor controllers we implemented the system to control motor current AND wheel speed. A little throttle with wheel on the air would probably limited by the wheel speed since the current is very low always with wheel on the air...
No one yet asked for this type of control, seems everyone else is happy with current way??

About SOC, if you have offroad mode disable, you can show SOC or motor temperature, you need to enable them and also use on/off click + down click.
 
About SOC, if you have offroad mode disable, you can show SOC or motor temperature, you need to enable them and also use on/off click + down click.


LOL. That easy I had not done the 'on/off click + down click' bit :oops: Thanks

Edit
Having just reread the v14 instructions I see that step is not mentioned for SOC
 
jbalat said:
dameri said:
Hi everyone and very big thanks to casainho and jbalat. Also thanks everyone who has been involved in to developing open source TSDZ2.

I have 250 w tsdz2 with 36V battery. I have been driven it now almost 3000 km.

I ordered KT-LCD3 and stlink v2 for open source project.

Now I’m wondering how do I connect throttle cable to KT-LCD3? Do I have to solder it somewhere to KT-LCD3? In LCD5 display throttle cable is connected with connector.
Do you need a throttle ? With the Opensource firmware just program the last assist mode so that you have super powers, you will not feel any pressure when you peddle.
There are not enough wires in the ktlcd to take the throttle to the top of the display so you will need to break out the throttle wire from the 8 pin connector below. Check out the wiki, there are some pics and wiring info there.

8 pin wiring here
https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/Wire-KT-LCD3-to-TSDZ2

I need throttle as a walk assist. My carage is in my living room :). I live third floor and I have physical limitations so it's very easy climb stairway with throttle. I don't use throttle when I'm driving.

Github shows only wiring to motor and motor lcd cable. Where should I connect wires from throttle.
 
dameri said:
jbalat said:
dameri said:
Hi everyone and very big thanks to casainho and jbalat. Also thanks everyone who has been involved in to developing open source TSDZ2.

I have 250 w tsdz2 with 36V battery. I have been driven it now almost 3000 km.

I ordered KT-LCD3 and stlink v2 for open source project.

Now I’m wondering how do I connect throttle cable to KT-LCD3? Do I have to solder it somewhere to KT-LCD3? In LCD5 display throttle cable is connected with connector.
Do you need a throttle ? With the Opensource firmware just program the last assist mode so that you have super powers, you will not feel any pressure when you peddle.
There are not enough wires in the ktlcd to take the throttle to the top of the display so you will need to break out the throttle wire from the 8 pin connector below. Check out the wiki, there are some pics and wiring info there.

8 pin wiring here
https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/Wire-KT-LCD3-to-TSDZ2

I need throttle as a walk assist. My carage is in my living room :). I live third floor and I have physical limitations so it's very easy climb stairway with throttle. I don't use throttle when I'm driving.

Github shows only wiring to motor and motor lcd cable. Where should I connect wires from throttle.
We'll implement walk assist without having to use the throttle very soon :wink:
 
Back
Top