jbalat
10 kW
Woohoo Success !!!!!!!!!!!!!
Thank You

Thank You

What you mean? Please explain...jbalat said:Woohoo Success !!!!!!!!!!!!!
Thank You
![]()
Can you please say what changes you did? Because I can use your values for #define a 36V motor.jbalat said:Dude it's finally working exactly how I want it.
112 cadence and full power all the way to the end with graceful loss of power above 112rpm
550w at level 5 demanded and delivered by the motor at 40km/hr with a low battery and little pressure on the pedals. Awesome efficiency less than 220w at 32km/hr on a dual suspension mtb with nobby tires
And lots more![]()
The firmware can now be configured to immediately start the motor assist as soon you press the pedals OR as soon you press the pedals and you rotate a bit the pedals, this way avoid possible run away.EndlessCadence said:@casainho
Nice work! I can't wait to try it...
I don't have the Tongsheng brakes nor the hidden brake wire (whatever it is called) can I use the opensource firmware? Or do you advice against it? I'm prepared to experiment but I wouldn't like the bike to run away from me![]()
You are right, I will make it the default. I am being trying to expand the options on LCD3 and that will also be there as also the motor type: 36 or 48V motor.jbalat said:yes its fairly safe to use without brakes, works just like the original firmware. My feeling is for safety this should be the default in the firmware since most people wont have ebrakes
I recommend a full erase. On EEPROM the firmware checks for first address to have a key/specifc value and if not it will write default values to there. This means the user needs/should always configure after flashing.jbalat said:Casainho do you now recommend to erase the memory before we flash ? Is this for all tabs ?
casainho said:Don't know what you mean by tabs.
Can we configure this using the LCD3 display? I'm in the middle of converting to the LCD3 and the opensource firmware. Everything went fine so far but the bike tried to run away once, luckily I could grab the brakes but the display showed that the motor continued to deliver more then 100W! A power cycle fixed the issue but I would like to turn off MOTOR_ASSISTANCE_CAN_START_WITHOUT_PEDAL_ROTATION for safety as I don't have e-brakes. I didn't do a real ride yet but I can't wait! Need to mount everything securely first...casainho said:The firmware can now be configured to immediately start the motor assist as soon you press the pedals OR as soon you press the pedals and you rotate a bit the pedals, this way avoid possible run away.EndlessCadence said:@casainho
Nice work! I can't wait to try it...
I don't have the Tongsheng brakes nor the hidden brake wire (whatever it is called) can I use the opensource firmware? Or do you advice against it? I'm prepared to experiment but I wouldn't like the bike to run away from me![]()
Anyway, I personally prefer to use the brake sensors and they can be the most cheap and popular used on ebikes.
Yes, they are different there is a difference on motor.c when calc FOC angle.EndlessCadence said:@casainho: I've just created a PR for you which fixes the makefile for Windows. Yes, I've started developingMainly for changing some configuration for now.
Btw: what's the difference (in configuration) between the 36v and 48v hex files? I can't seem to really find this in the source...
Has something to do with the difference in characteristics due to difference in motor windings between 36v and 48v versions?
Can you elaborate a bit more if you have the time? I would like to know the correct settings for a 36v motor (and 48v battery).casainho said:Yes, they are different there is a difference on motor.c when calc FOC angle.EndlessCadence said:@casainho: I've just created a PR for you which fixes the makefile for Windows. Yes, I've started developingMainly for changing some configuration for now.
Btw: what's the difference (in configuration) between the 36v and 48v hex files? I can't seem to really find this in the source...
Has something to do with the difference in characteristics due to difference in motor windings between 36v and 48v versions?
I plan this to be configuramed on LCD3.
I hope you understand on the comments and variable names:EndlessCadence said:Can you elaborate a bit more if you have the time? I would like to know the correct settings for a 36v motor (and 48v battery).
void calc_foc_angle (void)
{
uint16_t ui16_temp;
uint32_t ui32_temp;
uint16_t ui16_e_phase_voltage;
uint32_t ui32_i_phase_current_x2;
uint32_t ui32_l_x1048576;
uint32_t ui32_w_angular_velocity_x16;
uint16_t ui16_iwl_128;
// FOC implementation by calculating the angle between phase current and rotor magnetic flux (BEMF)
// 1. phase voltage is calculate
// 2. I*w*L is calculated, where I is the phase current. L was a measured value for 48V motor.
// 3. inverse sin is calculated of (I*w*L) / phase voltage, were we obtain the angle
// 4. previous calculated angle is applied to phase voltage vector angle and so the
// angle between phase current and rotor magnetic flux (BEMF) is kept at 0 (max torque per amp)
// calc E phase voltage
ui16_temp = ui16_adc_battery_voltage_filtered_10b * ADC10BITS_BATTERY_VOLTAGE_PER_ADC_STEP_X512;
ui16_temp = (ui16_temp >> 8) * ui8_duty_cycle;
ui16_e_phase_voltage = ui16_temp >> 9;
// calc I phase current
if (ui8_duty_cycle > 10)
{
ui16_temp = ((uint16_t) ui8_adc_battery_current_filtered_10b) * ADC_BATTERY_CURRENT_PER_ADC_STEP_X512;
ui32_i_phase_current_x2 = ui16_temp / ui8_duty_cycle;
}
else
{
ui32_i_phase_current_x2 = 0;
}
// calc W angular velocity: erps * 6.3
ui32_w_angular_velocity_x16 = ui16_motor_speed_erps * 101;
// 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;
// calc IwL
ui32_temp = ui32_i_phase_current_x2 * ui32_l_x1048576;
ui32_temp *= ui32_w_angular_velocity_x16;
ui16_iwl_128 = ui32_temp >> 18;
// calc FOC angle
ui8_foc_angle = asin_table (ui16_iwl_128 / ui16_e_phase_voltage);
// low pass filter FOC angle
ui16_foc_angle_accumulated -= ui16_foc_angle_accumulated >> 4;
ui16_foc_angle_accumulated += ui8_foc_angle;
ui8_foc_angle = ui16_foc_angle_accumulated >> 4;
}
Do you recommend you settings for the 36V motor? did you use the "FOC value" that gave you more speed/pedal cadence or the one that you tested as having more torque??jbalat said:Dude it's finally working exactly how I want it.
112 cadence and full power all the way to the end with graceful loss of power above 112rpm
550w at level 5 demanded and delivered by the motor at 40km/hr with a low battery and little pressure on the pedals. Awesome efficiency less than 220w at 32km/hr on a dual suspension mtb with nobby tires
And lots more![]()
jbalat said:now with 130 foc I get 120 cadence and 550w
Thanks! This means that the coils of the motor are the only difference here (ui32_l_x1048576) ? Looking at the default settings in the firmware I must be using the wrong configuration for my 36V motor nowcasainho said:I hope you understand on the comments and variable names:EndlessCadence said:Can you elaborate a bit more if you have the time? I would like to know the correct settings for a 36v motor (and 48v battery).
Code:void calc_foc_angle (void) { uint16_t ui16_temp; uint32_t ui32_temp; uint16_t ui16_e_phase_voltage; uint32_t ui32_i_phase_current_x2; uint32_t ui32_l_x1048576; uint32_t ui32_w_angular_velocity_x16; uint16_t ui16_iwl_128; // FOC implementation by calculating the angle between phase current and rotor magnetic flux (BEMF) // 1. phase voltage is calculate // 2. I*w*L is calculated, where I is the phase current. L was a measured value for 48V motor. // 3. inverse sin is calculated of (I*w*L) / phase voltage, were we obtain the angle // 4. previous calculated angle is applied to phase voltage vector angle and so the // angle between phase current and rotor magnetic flux (BEMF) is kept at 0 (max torque per amp) // calc E phase voltage ui16_temp = ui16_adc_battery_voltage_filtered_10b * ADC10BITS_BATTERY_VOLTAGE_PER_ADC_STEP_X512; ui16_temp = (ui16_temp >> 8) * ui8_duty_cycle; ui16_e_phase_voltage = ui16_temp >> 9; // calc I phase current if (ui8_duty_cycle > 10) { ui16_temp = ((uint16_t) ui8_adc_battery_current_filtered_10b) * ADC_BATTERY_CURRENT_PER_ADC_STEP_X512; ui32_i_phase_current_x2 = ui16_temp / ui8_duty_cycle; } else { ui32_i_phase_current_x2 = 0; } // calc W angular velocity: erps * 6.3 ui32_w_angular_velocity_x16 = ui16_motor_speed_erps * 101; // 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; // calc IwL ui32_temp = ui32_i_phase_current_x2 * ui32_l_x1048576; ui32_temp *= ui32_w_angular_velocity_x16; ui16_iwl_128 = ui32_temp >> 18; // calc FOC angle ui8_foc_angle = asin_table (ui16_iwl_128 / ui16_e_phase_voltage); // low pass filter FOC angle ui16_foc_angle_accumulated -= ui16_foc_angle_accumulated >> 4; ui16_foc_angle_accumulated += ui8_foc_angle; ui8_foc_angle = ui16_foc_angle_accumulated >> 4; }
jbalat said:Yes I would recommend my settings. Very happy with them
I was aiming for max power at Max cadence
With foc 80 I could not get more than 90 cadence and 440w when I set 550w
now with 130 foc I get 120 cadence and 550w
Also Max erps is 700
and Max Pas cadence is 130 so I can achieve max PWM duty of 254
I don't know if 130 is the best but I tried 100 and I still wasn't happy so somewhere between may be slightly better but I'm happy with this.
Let's make some calculations based on other information we have:jbalat said:See my post above.
I set my power to 550w but it would only give me that power at low cadence. As I got to a higher cadence the power kept decreasing to like 440w.
Trial and error. Run a few tests for yourself and see.
I’m not planning on riding at 120 cadence since I know it won’t be efficient but I just didn’t want the motor to restrict me in any way
// 36V motor: L = 76uH
// 48V motor: L = 135uH
// ui32_l_x1048576 = 142; // 1048576 = 2^20 | 48V
// ui32_l_x1048576 = 80; // 1048576 = 2^20 | 36V