Go Down

Topic: Battery Voltage Measurement with OP Amp (Read 9483 times) previous topic - next topic

BigBobby

Welcome to San Jose !

If you can get away long enough to visit Santana Row on Stevens Creek just East of Winchester Blvd. there's a lot of really good restaurants. My favorites are Fogo de Chou and Sino but there's lot's more (West Bank is really popular too). Bring lots of money ha ha !

FYI, I just realized I goofed on the schematic design. The Gain of 3 non-inverting amp is supposed to be right after the DAC to boost the DAC 0 to 5V signal up to the 0 to 12V range the rest of the circuit operates in. I'm fixing that now (I hope ).

Have a nice trip. You can use UBER instead of a taxi when you get here. It's cheaper and less run around.
Thanks for the tips!  My hotel is actually in Milpitas where I'll be staying for the week.  Most nights are scheduled for work stuff, but maybe I'll be able to take an Uber someplace some night this week.

raschemmel

#46
Apr 11, 2016, 11:05 pm Last Edit: Apr 18, 2016, 06:45 am by raschemmel
FYI, I used a MCP4725 I2C DAC instead of filtered PWM. For $5, why mess around with PWM when you can get a DAC for $5 ?


Quote
My hotel is actually in Milpitas where I'll be staying for the week.  
That's really not that far from where I used to work (not far from Great Mall in Milpitas).


It seems I blew up my DAC somehow by connecting it to the input of an op amp running on 12V . That shouldn't happen but it seems to be dead now. I ordered another. Maybe I'll buffer it with a voltage follower next time.

After extensive testing and some redesign and rewiring I have arrived at the following:
1-battery voltage is only accurate if a sufficient delay is inserted after turning on the relay which switches the battery "-" terminal from the mosfet DRAIN to the op amp subtractor V1 input pin. Previous error was caused by trying to measure the voltage before the relay contacts settled.
2-the relay does it's job perfectly. If the batt voltage is high enough the relay is left off and the battery cannot be charged because it is not connected to the fet.
3-the current measurement error previously was due to the voltage output of the shunt amplifier > 5.0 V. Once I discovered this I added a voltage divider and the measurements were consistent after that.


Program Output ("counts" = arduino analogRead counts)

Quote
batt_voltage counts =692.00
batt_voltage =8.49
batt_voltage counts =693.00
batt_voltage =8.50
Above Setpoint, not charging 8.49
batt_voltage counts =691.00
batt_voltage =8.48
Below Setpoint, charging...
batt_charging_led ON...
Current counts =  444
Current  =  0.27
batt_charging_led OFF...
batt_voltage counts =692.00
batt_voltage =8.49
Above Setpoint, not charging 8.49
batt_voltage counts =691.00
batt_voltage =8.48
Below Setpoint, charging...
batt_charging_led ON...
Current counts =  569
Current  =  0.34
batt_charging_led OFF...
batt_voltage counts =692.00
batt_voltage =8.49
Above Setpoint, not charging 8.48
batt_voltage counts =693.00
batt_voltage =8.50
Above Setpoint, not charging 8.49
batt_voltage counts =691.00
batt_voltage =8.48
Below Setpoint, charging...
batt_charging_led ON...
Current counts =  537
Current  =  0.32
batt_charging_led OFF...
batt_voltage counts =693.00
batt_voltage =8.50
Above Setpoint, not charging 8.49
batt_voltage counts =692.00
batt_voltage =8.49
Above Setpoint, not charging 8.50
batt_voltage counts =692.00
batt_voltage =8.49
Above Setpoint, not charging 8.48
batt_voltage counts =690.00
batt_voltage =8.47
Below Setpoint, charging...
batt_charging_led ON...
Current counts =  486
Current  =  0.29
batt_charging_led OFF...
batt_voltage counts =691.00
batt_voltage =8.48
Below Setpoint, charging...
batt_charging_led ON...
Current counts =  479
Current  =  0.29
batt_charging_led OFF...
batt_voltage counts =692.00
batt_voltage =8.49
Above Setpoint, not charging 8.50
batt_voltage counts =692.00
batt_voltage =8.49
Above Setpoint, not charging 8.50
batt_voltage counts =692.00
batt_voltage =8.49
Above Setpoint, not charging 8.48
batt_voltage counts =692.00
batt_voltage =8.49
Above Setpoint, not charging 8.49
batt_voltage counts =692.00  
Scope Screenshot Settings:
TIME/DIV: 1uS
Ch-1 : 5V/Div (gate drive signal)
Ch-2: 1V/Div  (amplified shunt voltage)


Karsten_87

Hi everybody,

Since I got so many good suggestions I wanted to post my (this time hopefully) complete circuit diagram (I will post the values for the resistors/capacitors soon). However, I made one unprofessional simplification to make it more easy to read: The orange lines to the relays: Here I just use one I/O output from the Arduino connected to all three relais to change between charge (Relay 1 closed, Relay 2 open, Relay 3 "down") and discharge (Relay 1 open, Relay 2 closed, Relay 3 "up"). I wanted to change this just with one command in the code. I hope that is alright.

To the question why I am not using a DAC I have to explain a tiny bit more about the project:

As general idea I wanted to create a battery simulator where I can create dynamic current profiles to get practical data for battery models, test state estimation etc., without the need for expensive test hardware. Since we work with MATLAB to simulate batteries, and test our algorithms, I wanted to have something simple, without the need of converting data all the time. Luckily, I quickly had reasonable results with combining the shown current controlled circuit with the MATLAB Arduino IO Package (http://www.mathworks.com/matlabcentral/fileexchange/32374-legacy-matlab-and-simulink-support-for-arduino), allowing to control the Arduino directly with matlab code (only basic commands like analog write/read etc.). So after a bit of fiddling, now I am able to create current profiles (see figure current profile generation) very simple with a Simulink model and then run a loop from matlab code that works like this:

•   Read the ith value from the Simulink current demand vector and send the corresponding integer to the Arduino microcontroller board via USB.
•   Ask for the measurement of the voltage over the power resistor, calculate the current and store the value.
•   Ask for the measurement of the battery terminal voltage, calculate the voltage and store the value.
•   Wait until the next second
•   If the battery terminal voltage is too low: STOP

The result you can see in the figure measurement (The circuit I used for that contained just the discharge function. I used six NiMH cells in series and had just a voltage devider for the terminal voltage measurement). Therefore I want to stick to the simple low pass filter and avoid the DAC, since it allows me to directly use the "matlab code".

@  BigBobby: Thank you for your general suggestions. I will try to implement R7, R19, C4 , R2 from your diagram and see whether things improve.
Regarding the 1k resistance between the OP Amp and MOSFET I have one question: I found that my current signal got really messy when I try to increase the current (see figure one OPAmp). My solution for this was to use two LT1001 in parallel to increase the current output and it worked fine.

Won't a resistor limit the current again so that there is the possibility to run into the same issue again?

@raschemmel:
Your circuit diagram looks really interesting. Thanks for all the effort you invested in this! I have one question: What is the advantage of your feedback loop, using three LT 1215 OP Amps to drive the MOSFET? The first one just amplifies when I am right. Then you have a low pass filter next to the PWM output. After that the OP Amp is clear as well. But the one directly in front of the MOSFET raises only question marks :)

Best regards
Karsten

raschemmel

op amp Integrator
Output is triangle wave.

raschemmel

So after all that why didn't you post your code ?

Karsten_87

Hi raschemmel,

the code on the Arduino is directly available from the matlab IO package I mentioned. They provide the pde file and to my knowledge it should be downloadable for free. I don't know if this is the right place to post matlab code. However, in matlab its just a simple while loop running with analogue-write and read commands anyway.

raschemmel

So all your plots came from Matlab ?

Is Matlab free ?

Karsten_87

Yes, the plots are made with Matlab. It is certainly not free. However, I am sure you can find test versions or other stuff if you want to check it out.


Go Up