2

I am making an arduino project with a single lithium ion battery, and want to be able to maintain a constant PWM voltage, even when the battery goes from 4.2-3.2v. I have been able to read the Vcc using the internal 1.1v reference, so I am wondering if I can make some sort of feedback system to increase the duty cycle when the battery discharges, in order to keep the same average voltage on the PWM. I want to be able to make it 3.2v constant, which should be attainable on Vcc from 4.2-3.2, with 100% duty cycle when the battery is at 3.2v.

3
  • 5
    That's just a math problem, and a simple one at that. Read your voltage, calculate the PWM to get the average you want, then apply that PWM. What part is sticking you?
    – Delta_G
    Sep 18 '20 at 4:50
  • That would work. Just note that the 1.1V reference can differ slightly, from chip to chip. So depending on your margin of error, you might have to do a bit of calibration. PS it sound like you already know, but just to reiterate; PWM output doesn't give out an analog voltage, despite the misleading analogWrite function name. You'd have to do some filtering to convert the PWM to a analog voltage.
    – Gerben
    Sep 18 '20 at 14:08
  • Wouldn't a voltage regulator do that better than an Arduino? Sep 18 '20 at 17:37
1

Simple: duty = (3.2 / vcc) * 255;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.