Skip to content

Conversation

@EigenMania
Copy link
Contributor

Proposing a safer method for this computation. If the input voltage to the clamping function is too low, the direct cast to uint8_t can cause the result to wrap. But this can even happen when casting the lvc_voltage. For example:

max_voltage = 58.8; (set in GUI)
lvc_voltage = 42; (set in GUI)
full_voltage_range_x100 = 1679;
padded_voltage_range_x100 = 1410; (using default padding of 8% on each side, set in fw)
lvc_ramp_down_end_voltage_x100 = 4334;
lvc_ramp_down_start_voltage_x100 = 4475;
LVC_LOW_CURRENT_PERCENT = 20; (default in fw)

Input voltage for the MAP32 function is limited to lvc_voltage_x100, but in this case the MAP32 function would actually wrap

uint8_t tmp = (uint8_t)MAP32(4200, 4334, 4475, 20, 100);

Gives tmp = 200 since the result of MAP32 is negative.

Safer to cast to int8_t so the result is between -127 and 127, then CLAMP from 0 to 100, then cast back to uint8_t.

@Larswagner1987
Copy link

That could be it. Can someone re-upload it to version 1.5 with the changes? That would be great.

@EigenMania
Copy link
Contributor Author

No this is probably not your problem, since you're issue is LVC rampdown starting too early. The computation will work fine for higher values. You should just lower your LVC value if you want more power for longer.

@Larswagner1987
Copy link

Okay, sorry if I'm asking such a stupid question, where do I set it? Well, mine says 54.6 when the battery is full and 39v when the battery is actually empty and that's how I set it but it doesn't help because the problem starts early on. With a battery voltage of 49v I can no longer get over 1000 watts and am at around 850-940 watts. If I have the 1.4 fw on it then I can run the battery down without the performance dropping too much. With a remaining battery of 48v I have 1400 watts, which is a bit strange. I noticed the same problem with my wife's e-bike.

@EigenMania
Copy link
Contributor Author

Okay with 54.6 V full and 39 LVC, you have a full voltage range of 15.6V, a padded range of 13.1V. So 0% battery SOC would be 39+1.2=40.2V and 10% SOC would be 40.2+0.1*13.1 = 41.5V. This is when LVC should kick in (starting from 41.5V roughly).

I've checked the math in the FW, pretty sure it's fine, but lmk if you find any errors in the LVC algorithm. Could it be battery sag under load? Could be that when you hit the throttle the battery voltage under load drops below 41.5V. Remember that the displayed voltage is only updated every 2s after no power is applied, the battery voltage used for LVC is the floating minimum voltage (not sent to the controller, only updated in the FW during runtime).

@Larswagner1987
Copy link

Larswagner1987 commented Jul 10, 2025 via email

@EigenMania
Copy link
Contributor Author

Can you check the event logger in the GUI and confirm that LVC limiting is the cause of the power-loss? If this is the case you should see this warning, along with the measured voltage. Lmk how this looks for you when your pack is ~49V and you still have this issue.

@Larswagner1987
Copy link

Larswagner1987 commented Jul 10, 2025 via email

@EigenMania
Copy link
Contributor Author

Found the damn bug, the padded voltage range was not getting computed properly. This is why the LVC is kicking in way too early.

@EigenMania
Copy link
Contributor Author

EigenMania commented Jul 11, 2025

lvc_fix.zip

@Larswagner1987
Copy link

that's great thank you 💪👍

@FazzFazz
Copy link

@Larswagner1987 let me know if that is better i might also change to this fw

@Larswagner1987
Copy link

@FazzFazz @EigenMania Hello, I've tested it and now it's wonderful, everything is correct and the voltage is right again, now it's fun again 💪👍 thank you for the quick help.

@RoyMagne
Copy link

@EigenMania Thank you for the firmware, but this one gives me error code 05 (Fault with the throttle) on the BBS02.
My display is a DPC18 with a throttle.
When I revert back to version 1.5.99, the error disappears.
I’ve tried installing the firmware twice, but with the same result.

@MrHumanRebel
Copy link
Contributor

Nice!

@EigenMania
Copy link
Contributor Author

@RoyMagne it looks like I might have made a mistake and built both solutions for BBSHD by accident, try this one:
bbs-fw_BBS02.zip

@RoyMagne
Copy link

@EigenMania Thanks for the quick update! This one seems to be working as expected 😊👍

@EigenMania
Copy link
Contributor Author

@Larswagner1987, @RoyMagne and to anyone else trying the fix, please also test that LVC rampdown still works and report back in the PR request with a comment so we can know (ie just once ride the bike to empty and confirm that it still kicks in, just at the lower battery level). Technically it should start at 10% battery level, but with voltage sag it's likely that it starts earlier, I'd guess ~20% or so depending on how you ride.

@Larswagner1987
Copy link

@EigenMania Hello, my battery 🔋 has 42 volts and everything is fine so far. Now the wattage restriction is starting to work. Uphill speeds of 18 km/h are possible, the descent is about 7%. The battery does not start at 40 volts but it is no longer possible to continue driving. So I would say everything is great. To put it briefly, at 42 volts the power is reduced, which is great and works well. I have tested it with two different e-bike batteries. They did a good job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants