Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to compensate battery voltage drop with light PWM value #2510

Open
hamed-ta opened this issue Apr 22, 2022 · 5 comments
Open

How to compensate battery voltage drop with light PWM value #2510

hamed-ta opened this issue Apr 22, 2022 · 5 comments
Labels

Comments

@hamed-ta
Copy link
Contributor

I made custom hardware that has 5 PWM channels to control 5 light channels, this device uses a one-cell lithium battery which when is fully charged the voltage is about 4.2 volts and when it's getting empty it can go down to 3 volts. so when the user sets the light brightness to 50% when the battery is full the PWM value should be different than when the battery voltage is 3.7 and when it's 3.2. I should mention that I measure the battery voltage, current, and power of the device with a power meter sensor. so where and how do you think is the better approach to adjust the PWM value based on brightness and battery voltage?

@mcspr
Copy link
Collaborator

mcspr commented Apr 24, 2022

Could be the same approach as with colored lights? With the most basic brightness, we simply walk the existing channels and apply it as a 0...100% scaling

void _lightValuesWithBrightness(LightChannels& channels, long brightness) {
const auto Brightness = LightBrightness{brightness};
for (auto& channel : channels) {
channel.apply(Brightness);
}

// After the channel value was updated through the API (i.e. through changing the `inputValue`),
// these functions are expected to be called. Which one is chosen is based on the current settings values.
// TODO: existing mapping class handles setting `inputValue` & getting `target` value applied by the transition handler
// should it also handle setting the `value` so there's no need to refer to channels through numbers?
struct LightBrightness {
LightBrightness() = delete;
explicit LightBrightness(long brightness) :
_brightness(std::clamp(brightness, Light::BrightnessMin, Light::BrightnessMax))
{}
long operator()(long input) const {
return (input * _brightness) / Light::BrightnessMax;
}
private:
long _brightness;
};

You could either replace the implementation completely and make it dependent on the battery level at that moment, or chain another object into the 'apply()` of the light channel

(*it).apply(rgb, Brightness);

(i.e. it applies channel filtered through rgb object first, then brightness one)

And some periodic timer to force-apply channel values

@hamed-ta
Copy link
Contributor Author

ok got it, or maybe adding another module to the project called for example battery support?

any idea of the approach of adjusting the PWM value according to the battery level? when for example the nominal voltage of LEDs is 3.3 volts and the battery voltage range is between 3 to 4.2 volts? which means there should be an upper limit for PWM value according to the exceeded voltage (battery voltage - 3.3) and a limited brightness value when the battery voltage is less than 3.3 to show to the user?

@mcspr
Copy link
Collaborator

mcspr commented Apr 26, 2022

I'd think about the separation when we already have a clear api. It would also depend where are you getting the battery info; is it analog pin, is it some digital interface, etc. But if there is, sure.

re. values... just encode it as a 2-value table with specific voltage level <-> multiplier? for example, with 0.1v step (or, through experimentation, where voltage makes the most difference)

@hamed-ta
Copy link
Contributor Author

I'd think about the separation when we already have a clear api. It would also depend where are you getting the battery info; is it analog pin, is it some digital interface, etc. But if there is, sure.

re. values... just encode it as a 2-value table with specific voltage level <-> multiplier? for example, with 0.1v step (or, through experimentation, where voltage makes the most difference)

I read the voltage, current, and power by a digital power meter sensor.
a discrete value table can be a little problematic as it can cause a flickering issue, I am thinking of a continuous solution, for example calculating the PWM value that causes the exceded RSM voltage more than 3.3 volts based on battery level and subtracting the MAX PWM value by this surplus value?

@hamed-ta
Copy link
Contributor Author

Or another approach could be, as I have the current, that can be possible to store the corresponding current value when the brightness is set and then adjust the PWM value when the battery level changes but in this way, I still need to limit the MAX PWM value to prevent over current problem...!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants