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.