Switching NiMh Battery Charger

Switching NiMh Battery Charger

Hope you guys are doing great.

Ever since I published my first blog post discussing the design and implementation of temperature gradient cut-off ATtiny24 smart charger for NiMh batteries I wasn’t fully satisfied with the power or the actual charging circuit, initially I decided to build the charger controller and the power circuit separately since I knew that I’d be making changes in the design as I go along.

For those of you who are lost at this point, here’s a link to my first post discussing the design of the my smart NiMh charger.

https://lonetechnologist.wordpress.com/2016/04/25/designing-a-delta-tempdelta-time-temperature-gradient-charge-termination-smart-charger-for-nimh-battery-pack/

Although I am fairly comfortable at this point with the control circuit but the power circuit has one obvious problem, it’s too bulky for my liking! the LM350 dissipates a lot of heat, I had to mount a fan on top of it to cool it off and since only recently I was beginning to think that I should get a case made for the project it just didn’t seem that the final version would look elegant owing exclusively to the big foot print.

I haven’t had any experience with using a switching regulator but anyone with basic electronics training would know that high current designs based around switching regulators are comparatively smaller in size to a regular linear regulator design and this comes due to the fact that switching regulators are efficient and hence waste less heat as compared to linear regulators and therefore require a much smaller heat sink and possibly no fan to remove the wasted heat. Secondly since we will be making a switching constant current charger/power circuit therefore it’s worth mentioning that in order to bias an LM350 as a constant current regulator for high currents approaching to 2 Amps you need big power resistors which in my case took most of the area on the perf-board but for a switching regulator we’ll be using a feedback technique that allows for usage of normal sized resistors saving up a lot of space in the process.

And yes for those of you who might argue probably the biggest reason an SMPS is lighter and smaller than a simple linear voltage supply is because high frequency ferrite core transformers are smaller and add a lot to the size reduction of the design, however in my case I have mentioned the aspects that have allowed me to make my circuit smaller.

Choosing a Switching Regulator

The obvious selection criteria for an LM350 replacement is to look for a regulator that can handle 3 Amps, is adjustable and can easy handle input voltages of around 35 volts (the more the better). After doing a little online search I found the LM2576-ADJ as a reasonable choice. The LM2576-ADJ is a buck regulator meaning you can have an output voltage of your choice which is lower than the input voltage.

LM2576-adj
The LM2576-Adjustable

Looking at the LM2576 you see it has two more pins than your usual linear regulators, the pin 5 is a normal TTL logic level ON and OFF signal that can enable or disable the chip at will while the fourth feedback pin might be new to you who haven’t worked with a switching regulator before, like me.

Essentially since a switching regulator regulates the internal oscillator’s duty cycle (PWM) in order to regulate its voltage output to a desired level therefore it needs to know what voltage is at the output pin, this is where the feedback pin comes into use.

For an explanation of how the DC-DC buck convertor works, check out Afrotechmods comprehensive video on the subject.

 

The Circuit Design

Fortunately Texas Instrument has a very well written literature (# snva557) on how a constant current charger power circuit can be designed using an LM2576 regulator and this is what I have based my design on.

snva557 charger
The original circuit as presented in Texas Instruments literature # snva557

The above is used for a 12 volt NiMh battery to be charged at a constant current of 2.2 Amps, I have modified the above circuit slightly in order to get selectable current levels of 700 mA and 1.8 Amp staying true to the specifications of the original LM350 based charging circuit.

The Op-Amp is a wonderful component as you’ll find out that just by selecting different feedback resistor values I have managed to get the required current output.

new
The Modified Circuit Design for 700 & 1800mA Current Outputs

Please ignore the crudity of the diagram, here just by adding two 12 volt relays (yes I can’t help using them!) I have managed to switch between 700 mA and 1.8 Amp, well in actual it’s around 1.73 Amps since my calculations were a bit off but it’s still good enough for me, the controller can select between the two current levels depending on what’s required for the charging process, also not shown in the above diagram I have added a red LED fed from 12 volts through a 1K ohm resistor as well and in case you are wondering I have only used the 0.1 ohms resistor instead of the 0.05 ohm because it was easily available.

The Code Upgrade

Well I was hoping the new power circuit will be fully compatible with the code that’s already on the ATtiny24 but unfortunately that is not the case, I had to do some minor adjustments in the code which will work with this power circuit.

void setup()
{
pinMode (3, OUTPUT); //Indication LED
pinMode (2, OUTPUT); //Relay control
pinMode (10, OUTPUT);//Thermistor control
pinMode (7, OUTPUT);//E/S LED
pinMode (9, OUTPUT); //High current mode ON
pinMode (4, OUTPUT); //Moderate current mode ON
analogReference(EXTERNAL);
delay(5000);
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);//start charging
delay(2000);
if(analogRead(A6) >= 608) //if connected battery voltage equals or is greater than 16.7 volts, terminate charging with error to protect overcharge.
{
digitalWrite(2,LOW);
for(;;)
{
digitalWrite(3,HIGH);
delay(500);
digitalWrite(3,LOW);
delay(500);
}}
}
//int cycle = 0;
byte Count = 0;
void loop()
{
unsigned long Temp_C=0, Temp_N=0, x=0, y=0, TempN=0, TempC=0, b=0;
byte a=0, i = 0;
//int volts1, volts2;
//volts1 = analogRead(A6);
delay(1000);
if(analogRead(A6) >= 546)//When battery voltage is greater than or equal to 14.4 volts
{
digitalWrite(4, HIGH); //Turn OFF 700 mA mode
digitalWrite(9,HIGH);//Select 0.8C charging mode
}//digitalWrite(2,HIGH);//Start Charging
digitalWrite(10,HIGH);
//delay(5000);
delay(2000);
for(a=0;a<=5;a++){
Temp_C = analogRead(A1); //at 2.3V starts with 587
delay(1000);
if(Temp_C>=503)//Temp_C can be equal to 503000
{
x = 13975;
y = 9930680;
}
if(Temp_C<=502&&Temp_C>=386)
{
x = 11852;
y = 9186300;
}

  if(Temp_C<=385)//Temp_C can be equal to 385000
{
x = 9527;
y = 8144330;
}
Temp_C = Temp_C*10000; // 385*1000 = 385000
TempC = y-Temp_C; //(814433 – 385000)*10
TempC = TempC/x; //
b = b+TempC;
}
digitalWrite(10,LOW);
//b = b/6;
TempC = b/6;
a = 0;
b = 0;
if(analogRead(A6) >= 696) //when connected battery voltage at 18 volts (3.38 volts on the A6 pin) — edited on 17/4/2016 to 826 from 845, needs 3.30 volts on A6 now
{
digitalWrite(2,LOW);

for(;;)
{
digitalWrite(3,LOW);
}
//Count++;
}
while(i<=59)
{
delay(1000);
i++;
}
x=0;
y=0;
digitalWrite(10,HIGH);
delay(2000);
for(a=0;a<=5;a++){
Temp_N = analogRead(A1); //at 2.0V gets 503
delay(1000);
if(Temp_N>=503)
{
x = 13975;
y = 9930680;
}
if(Temp_N<=502&&Temp_N>=386)
{
x = 11852;
y = 9186300;
}
if(Temp_N<=385)
{x = 9527;
y = 8144330;}
if (Temp_N <= 365)//E/S when temperature is 45 degree or higher
{
digitalWrite(3,HIGH);
digitalWrite(7,HIGH);
digitalWrite(2, LOW);
for(;;){}}
Temp_N = Temp_N*10000;
TempN = y-Temp_N;
TempN = TempN/x;
b = b+TempN;
}
//digitalWrite(10,LOW);
TempN = b/6;
if(TempN > TempC)//Emergency cutoff charging
{
if(TempN-TempC >= 8)
{
digitalWrite(3, LOW); //Indicator LED
digitalWrite (7, HIGH); //E/S LED
digitalWrite(9, LOW);
//delay(2000);
digitalWrite(4,LOW);
delay(60000);
digitalWrite(2,LOW);//Relay control pin
for(;;){}
}}
Count++;
if(Count == 180) //Turn off charging after 3 hours regardless of termination conditions
{
digitalWrite(2,LOW);//Turn off charging
for(;;)
{
delay(500);
//digitalWrite(3,LOW);
digitalWrite(7,HIGH);
delay(500);
//digitalWrite(3,HIGH);
digitalWrite(7,LOW);
//delay(500);
}}
}

The Final Circuit on Perf-Board with Side by Side Size Comparisons

IMG_20160617_163814
The new switching charging circuit
IMG_20160617_163902
The LM2576 heat sinked with thermal grease
IMG_20160617_165122
The new charging circuit side by side with the old one based on the LM350, a definite size and performance advantage. Did I mention it looks a lot less uglier?

Finally here’s a short video of the complete charger circuit in action hooked up to the old controller board.

 

Final Words

All credit to the guys over at Texas Instruments for publishing such a smart and easily hackable design, well what basically started as a side project has turned out to be quite an interesting run so far, I am wondering if I can upgrade my controller circuit now, I already have an ATtiny24 but the ATmega328 isn’t that hard to accommodate on a similar sized board, I can try reducing some of the extra components, may be put in an LCD and a keypad to set battery voltage and charging current levels before charging starts and make it truly universal. Thanks for all your support and interest.

 

 

 

 

Current loop tester and pressure monitor for a 4-20mA (10 bar) analog sensor

Current loop tester and pressure monitor for a 4-20mA (10 bar) analog sensor

 

Hope you guys are doing great.

This post will discuss the design and implementation of a specialized milli-Amp meter and pressure monitor, the tester is intended to be hooked up like an amp-meter in series with a pressure sensor current loop in order to measure the milli-Amps flowing in the circuit and display the pressure in bars corresponding to the current output of the analog pressure sensor. This is designed specially to be used at a Heidelberg offset printing machine but the methods and techniques used in the design can offer help to a large number of students, professionals and hobbyists who are willing to achieve something similar.

For those of you who might be wondering, this is what a typical performance class Heidelberg Speedmaster XL 106 offset printing machine looks like.

XL106
an XL-106, 8 printing units with perfecting

some of these specific model machines require a pressure of around 7 bars to open up the compressed air inlet solenoid valve and then a stable pressure of around 6.5 bars to operate the machine at.

The pressure monitoring is done through an analog sensor with a current output of 4-20mA (two wire sensor configuration), the current is then fed directly to an analog value acquisition card which digitizes the mA’s current value for the CPU processor board. The sensor, solenoid safety valve and the pressure regulator is located at almost the far right end (beneath the feed table to be exact) in the above picture and in order to get a reading of that sensor’s current output for any given pressure at any time a technician is required to walk up to the opposite end of the machine and open up specialized service menus that show the sensor output.

The analog sensor or the current loop is fed through a 24VDC supply. The maximum load value for which the sensor can supply the specified current is given by the equation.

pressure sensor

Sensor load

This can vary from sensor to sensor depending on the manufacturing parameters. Working on this current loop offers the below challenges.

a) Quick visual pressure measurements

As mentioned, the sensor is installed at a good distance from the HMI which actually shows the sensor milli-Amps on the screen once software loads up fully. However by the time the software on the HMI (which is Windows based) loads up the machine had already gone through the pneumatic air valve actuation at 7 bar and the pressure has stabilized by the time the machine is ready to operate. Although there is a pressure gauge installed near the pressure regulator close to where the sensor is installed but due to their slow response its hard to get a quick and accurate reading. Secondly the pressure gauge is installed after the solenoid valve so one doesn’t get a pressure reading until the pressure at the sensor has reached 7 bar which would open up the valve and allow air to actually reach the gauge.

Since the pressure gauge  is inherently slow to response, therefore its difficult to draw a relation between the current output of the sensor and the pressure on the gauge in real-time troubleshooting.

b) Problem with analog input of the board is difficult to troubleshoot

Troubleshooting becomes a mess once there occurs a problem with the actual analog input of the electronic board itself, a faulty analog input results in wrong readings being transferred over to the machine computer which then resulted in unwanted malfunctions and error messages. The analog channel is of 25mA, means the ADC will saturate at 25mA, meaning any current value greater than 25 mA flowing into the analog input will be displayed as just 25 mA. As far as I know current can’t be digitized directly, it has to be converted into a voltage first which can then be converted into a digital value. I measured through simple experimentation that the input impedance of the analog input is around 100 ohms, so in order to troubleshoot if the analog input had gone bad, current going into the analog input and voltage across the input had to be measured, this is a rather tedious task and the measurements had to be repeated many times to make sure they were good enough to draw conclusions from.

Design Parameters to Counter these Issues

In addition to measuring current it was only logical to have an on-board microcontroller that could translate the real-time current value into the corresponding pressure and display  it on demand.

Since it was difficult to troubleshoot a faulty analog input on the electronic board therefore the measuring device should be designed with an input impedance that matches that of the actual analog value acquisition board so that the sensor can be disconnected from the analog input and connected directly across the measuring devices input to give a quick comparison of the milli-amps measured by the analog board on the machine and the measuring device.

The device had to be compact and easy to carry, should be able to power up from a range of voltage inputs depending on what’s available on site, any other functionality improvements will be an extra advantage.

The Actual Design

The circuit is centered around an ATtiny24 microcontroller, which quite frankly is a nice and powerful enough microcontroller for small tasks such as this one. For the display I am using three seven segments driven by the MC14511 BCD to seven segment latch/decoder. Since I am using Arduino IDE to program my ATtiny therefore the seven segment display was a logical choice since the lcd display code would have taken up a lot more code memory. The latch function of the MC14511 allows for usage of minimum number of controller pins in order to display numbers on three individual seven segment displays.

SAKtesternew
Final Circuit Diagram

since the tester will ultimately be connected in series with a 24 volt powered current loop so it was essential to build in some degree of protection in the tester to avoid damaging it in case (considering the worst case scenario) both the sensor and the analog input on the machine are shorted out, the port of the controller is protected using a 4.7 volt zener diode, a 10K ohm resistor is used as a current limiter for the analog input of the ATtiny24, a 100mA fuse is placed for further protection and in case a shorted current loop is tested it will blow out the fuse, instead of using a single 100 ohm test resistor I have used 30, 3000 ohm resistors in parallel, these are standard 0.25 watt resistors and combining them in parallel give me a wattage of over 7 watts, so even in a short circuited scenario where a maximum of 240 mA would be flowing through the 100 ohm test resistor the maximum power dissipated would be a little over 5.5 watts which won’t damage the 3000 ohm parallel resistor network, the 100 mA fuse is added to save the other protection components like the zener diode from the extra burden that a short-circuit would cause.

The LED is added to indicate if the pressure reading is above 9.99 bars in the system and is also used to as an indicator when the tester is made to operate in a special mode where it records the maximum and minimum values of pressure and milli-Amps.

The Code

The code as mentioned earlier is written using the Arduino IDE and is fairly simple and self explanatory, in order to convert the current readings into pressure, I have used a simple equation and have implemented it into the controller program.

I = 1.6*P + 4

Where I is the current in mA’s, P is the pressure in bars, it’s a simple linear relation which is in very close approximation of the relation I deduced taking pressure and current readings physically on the machine.

The seven segment displays are being updated one at a time, each three segments are being updated for new readings one after the other since I am using only four pin on the ATtiny24 to send out data to all the three seven segments. This is achieved by taking advantage of the latch functionality on the 14511 chip.

byte function, toggle = 0;
int peakValue = 0, minValue = 1023;
void setup()
{
pinMode(10,OUTPUT);
pinMode(9,OUTPUT); //Ardpin 13 – tinypin 11 D2 — D9
pinMode(8,OUTPUT); //Ardpin 12 – tinypin 10 D3 — D8
pinMode(7,OUTPUT); //Ardpin 11 – tinypin 9 D4 — D7
pinMode(6,OUTPUT); //Ardpin 10 – tinypin 8 D5 — D6
pinMode(5,OUTPUT); //Ardpin 9 – tinypin 7 D6 — D5
pinMode(4,OUTPUT); //Ardpin 8 – tinypin 6 D7 — D4
pinMode(3,OUTPUT); //Ardpin 7 – tinypin 5 D8 — D3
pinMode(2,INPUT); //Ardpin 6 – tinypin 3 D9 –D2
analogReference(EXTERNAL);
delay(500);
if(digitalRead(2) == HIGH)
{
function = 1;
}
}
void loop()
{
int currentValue;
long value;
byte segdis1, segdis2, segdis3;
if(function != 1)
{
currentValue = analogRead(A1);
value = currentValue;
delay(150);
}
if(function == 1)
{
currentValue = analogRead(A1);
delay(70);
if(currentValue > peakValue)
{
peakValue = currentValue;
}

if(peakValue >= 557)
{
if(currentValue < minValue)
{
minValue = currentValue;
}
}
if(toggle%2 == 0)
{
value = peakValue;
digitalWrite(10,HIGH);
}
if(toggle%2 != 0)
{
if(minValue == 1023)
{
if(peakValue < 1023)
{
value = 0000;
}
}
else
{
value = minValue;
}
digitalWrite(10,LOW);
}

}

value = value*2441;//800*2441 = 1952800
value = value/10000;//1952800/10000 = 195
if(digitalRead(2) == HIGH)
{
value = value – 40; //195-40 = 155
value = value*100; //155*100 = 15500
value = value/16;//155/16 = 968
if(value > 999)//maximum pressure condition
{
//segdis1 = 0;
//segdis2 = 0;
//segdis3 = 1;
digitalWrite(10,HIGH);//Maximum pressure fault LED indication
delay(20);
digitalWrite(10,LOW);
delay(20);
}

}
digitalWrite(4,HIGH);//4
digitalWrite(5,HIGH);//5
digitalWrite(3,HIGH);//3
byte k;
byte n = 9; //9
if(value >=0)
{
segdis1 = value%10; //remainder is stored e.g 20%10=0
value = value/10;
segdis2 = value%10;
value = value/10;
segdis3 = value;
}
else
{
segdis1 = 0;
segdis2 = 0;
segdis3 = 0;
}
for(k=0;k<=3;k++)
{
if(bitRead(segdis3,k)==1)
{
digitalWrite(n,HIGH);
}
if(bitRead(segdis3,k)==0)
{
digitalWrite(n,LOW);
}
n–;
}
digitalWrite(3,LOW);//3
// delay(50);
digitalWrite(3,HIGH);//3
n = 9;
//k=0;
for(k=0;k<=3;k++)
{
if(bitRead(segdis2,k)==1)
{
digitalWrite(n,HIGH);
}
if(bitRead(segdis2,k)==0)
{
digitalWrite(n,LOW);
}
n–;
}
// digitalWrite(8,HIGH);
digitalWrite(5,LOW);//5
// delay(50);

//digitalWrite(8,LOW);
digitalWrite(5,HIGH);
// delay(100);
//digitalWrite(8,HIGH);
n = 9;
//k=0;
for(k=0;k<=3;k++)
{
if(bitRead(segdis1,k)==1)
{
digitalWrite(n,HIGH);
}
if(bitRead(segdis1,k)==0)
{
digitalWrite(n,LOW);
}
n–;
}
digitalWrite(4,LOW);//4
digitalWrite(4,HIGH);

if(function == 1)
{
delay(1500);
toggle++;
}

}

The commented out text might not make much sense,since this was for my own personal reference, however the code should work without any issues if the ATtiny24 is programmed correctly.

Once again to save space and avoid floating point mathematics, I am multiplying my equations (by 10, 100, 1000 r whatever is required) to shift decimal places.

Features of the Tester

Here’s briefly what the tester is capable of doing.

1- Plug in the power and the tester is turned ON, it can measure the milli-Amps and show the corresponding pressure while the button is kept pressed.

2- Push the reset switch, keep the pressure/current switch pressed and release the reset button until the LED light’s up,the LED is now going to blink slowly at a rate of almost 2 seconds ON and 2 seconds OFF indicating that the tester has entered a maximum and minimum current and pressure recording mode, once the LED light’s up the maximum pressure measured will be displayed and when the LED turns OFF the minimum pressure measured will be shown on the segmented display. The minimum pressure monitoring only starts once the maximum pressure has gone past 6 bars since otherwise the minimum pressure would be recorded as zero every time, also the machine malfunctions only after when the minimum pressure has stayed below 6 bars for a few seconds so it’s only logical to start measuring the minimum pressure once the pressure is above 6 bars since any dips in pressure after that will be of interest since that can cause a malfunction during the production run.

The Finished Circuit of Perf-Board

I wanted the tester to be as small as possible so it can be easily carried out with my other testing gear, in order to achieve this I have implemented the design on two separate boards which can be combined creating a much smaller foot print.

IMG_20160604_223627
The display board, houses the seven segments, the BCD to segment decoder, the reset switch and the indicator LED
IMG_20160604_223729
Display board has male headers at the back through which it can be plugged onto the measuring and control board
IMG_20160604_223755
The measuring and control board, the left side shows the resistor network, the fuse and the current/pressure button, a single ATtiny24 sit at the center with female headers at either side on which the display board will be plugged on to.
IMG_20160604_223849
Soldering at the back of the measuring and control board
IMG_20160604_223925
A closer look at the resistor network, you can also see an LM7805 regulator through which the circuit will be powered (LM7805 is not explicitly mentioned in the schematic though)
IMG_20160605_163522
The board completely assembled

Here’s a link to a youtube video I have uploaded demonstrating the current and pressure measuring capabilities of the tester. The video shows a bench-top testing of the equipment giving an idea of how the instrument will perform once you are actually using it in the field.

 

Conclusion

I am having a protective case designed for this tester so I can carry it around easily without damaging it, I will update my post once the case is ready, if you found this post useful and would like to share your opinions please leave a comment, your support and interest matters a lot. Follow my blog and like my youtube channel if you’d like to support me.

Update 3rd July 2016: I had a case made for the tester, not the most elegant design but good enough for the job I guess, here are the dimensions and the final cased project,

The dimensions for the case
The dimensions for the case
IMG_20160703_123409
The final cased up project ready for field testing. Ignore my terrible hot gluing skills.