Arduino Uno controlled LM2576 based current source for battery charging

I am looking to control the output current of an LM2576-ADJ switching regulator by an Arduino uno, I will be using this circuit to charge an NiMh battery, and I am looking for general advice on the topic.

In order to maintain a current level the LM2576-ADJ needs 1.2volts on it’s feedback pin when the set current is reached.

I have a 0.1 current sense resistor and I measuring the voltage across it and have fed that voltage into Arduino’s pin A0, I have the internal 1.1 V reference set on the uno to have maximum precision. (I want to control current from 700 to a max of 2.2 Amps which will depend on the value I put into my code)

The Arduino’s pin 6 generates a PWM which through a low pass RC filter (voltage buffered by an op-amp) is fed into the feedback pin of the LM2576-ADJ regulator.

when the current is lower than the set value the PWM will be such that the voltage on the LM2576 feedback pin will be less than 1.2 volts allowing for the current to increase and if the current is greater than the set current then the PWM will be such that the feedback pin of the LM2576 receives a voltage higher than 1.2 volts.

I have written a very basic code

int ON = 12;
int FB = 6;
int x = (1.5*0.1)/0.001017;
void setup() {
  analogReference(INTERNAL); // set internal reference to 1.1 V
  pinMode(ON,OUTPUT); // ON/OFF signal for LM2576
  pinMode(FB, OUTPUT); //PWM for LM2576 Feedback
  digitalWrite(ON, HIGH);
  analogWrite(FB,62);
  delay(500);
}

void loop() {
digitalWrite(ON,LOW);
    while(analogRead(A0) < x)
    {
      analogWrite(FB,51); // Output 1.0 Volt(51)
      delay(1);
      analogWrite(FB,65);// Output 1.2 volt
  }

   while(analogRead(A0) > x)
  {
    analogWrite(FB,71);//Output 1.4 Volts (71)
    delay(1);
    analogWrite(FB,65); //Output 1.2 Volts
  }
}

I wasn’t expecting much out of this code but for a crude first attempt it works reasonably ok, for a set current of 1.5 Amps I am getting a fluctuating current between 1.45 to 1.58 Amps and these are just the maximum and minimum limits the fluctuation isn’t all that crazy to be honest.

I am looking for a better way to program the circuit reduce the variation in current and bring it close to the set value with minimum variation, would appreciate if anyone can offer any help.

update: The approach works OK for resistive loads but as soon as I connect the battery pack readings are all over the place, need to have better software implementation.

Any ideas would be great.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks... Tom... :slight_smile:

Thanks for your response Tom,

I have made great progress on the problem,

First of all I have attached a rough hand drawn circuit diagram of the circuit I have hooked up, earlier today I was thinking that may be I needed a PID control for my particular problem so I started reading some documentation concerning that and also downloaded the Arduino PID library to give it a shot, due to my lack of skills I wasn’t able to get any positive results out of the PID library but all this reading did give me a hint that instead of using if’s and while’s to control my current I need to have an equation based controlling and this is the simple code I came up with.

int ON = 12;
int FB = 6;
float Actual, Error, Integral=0, Output;
float setPOINT = (0.8*0.1)/0.00107; //Amp Calculated here
void setup() {
  analogReference(INTERNAL); // set internal reference to 1.1 V
  pinMode(ON,OUTPUT); // ON/OFF signal for LM2576
  pinMode(FB, OUTPUT); //PWM for LM2576 Feedback
  digitalWrite(ON, HIGH);
  analogWrite(FB,62);
  delay(500);
}

void loop() 
{
  digitalWrite(ON,LOW);
  Actual = analogRead(A0);
  Error = setPOINT - Actual;
  Integral = Integral + Error;
  Output = -0.09*(Error) -0.006*(Integral) + 62; //PI control equation
  analogWrite(FB, Output);
   }

in essence it’s a PI controller and after tweaking the constants in the equation I was able to get great results, my earlier approach worked awfully especially at low current values below 1 Amp and just to give an idea of how this works, I have uploaded a code for 0.8 Amp and have attached a picture of my meter reading which is very close and stable. I am really excited! my first step towards building a programmable universal NiMh charger is nearly completed :slight_smile:

Failed to upload the multimeter pic for the 0.8A set point, so here it is.

Hi,
OPs circuit.
MU9hEKHgVdhAdXa7B8NM96F1 (2).jpg

Tom… :slight_smile:

Hi,

This is quite an old thread already but here's something that I wrote to help anyone who might be willing to get a constant current out of the LM2576-ADJ regulator by software control through an Arduino