PDA

View Full Version : Battery checker



lerameur
- 29th January 2007, 01:01
hello

i wrote this program below. I am putting the Vref- on the lead of a fourth diode in series . There are 4 diode connected in series so that there is always 1.6v . I assume the Vref+ and Vref- is always 2.6 differnce. It is doingan A/D convertion on a voltage divider with a max voltage of 2.5.
The problem is that My lcd always shows me 373 (10 bit a/d) no matter what the voltage input is. Any idea what is wrong.
SO , I have a voltage divider on the battery to bring the voltage down. Right now I am reading 1.03v with a supply at 4.57 and on the 4th diode I am reading 2.98v.
My voltage divider I have Vdd -51Kohm -15Kohm- Vss

'Battery test for transmit pic

INCLUDE "modedefs.bas"
@ DEVICE PIC16F88 , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF
DEFINE OSC 20 'use external 20mhz crystal

DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

ADCON1 = %10100010
TRISA = %11111111 ' Set PORTA to all input
TRISB = %00000000

input1 var word

loop:
ADCIN 0, input1
'pause 30

Lcdout $fe, 1 'Clear screen
Lcdout "Left: ", Dec input1
Pause 100
Goto loop ' Go back to loop and blink LED forever

End

lerameur
- 29th January 2007, 01:32
I got it working but have no clue why .
If i do what is on the pic :
http://www3.sympatico.ca/lerameur/
then it works.
In this manner the output voltage also moved at the same time as the reference voltage no ?

lerameur
- 29th January 2007, 13:31
Anybody ??

Acetronics2
- 29th January 2007, 14:01
Hi,

I think ( ! ) a look to the '88 Datasheet ( ADC config ) could help you a bit ...

Alain

PS: common diodes as voltage refs ... that's a bit rock and roll ...

lerameur
- 29th January 2007, 14:29
I just changes the circuit a bit. I have new ideas this morning. night was good.
I am getting 1.06v steady on the diode as reference. My voltage divider shows me 0.7, but I am getting zero as output now.
Is it the hardware or the programming ?
I posted a new pic.
http://www3.sympatico.ca/lerameur/
also changed this line:
ADCON1 = %10010010


ken

brianwu
- 29th January 2007, 15:58
but I am getting zero as output now.
Is it the hardware or the programming ?
I posted a new pic.
http://www3.sympatico.ca/lerameur/

ken

Picture show you have both input connected to same place (ref. diode), resistor divider left unconnected.

lerameur
- 29th January 2007, 16:51
I got it going somehow. I dont even know what I was doing wrong... :)
maybe I am still sleeping
k

lerameur
- 30th January 2007, 14:14
Ok I think I know where lies the confusion.
Ihave two batteries I want to check.I can check the battery that powers the microcontroller with voltage reference. I am trying to check the second battery . There is no common ground and I dont want one because of the isolation I want to have. Therefore I think when I do an A/D, is reads as a floating value.
How do I go around this ?

Dave
- 30th January 2007, 14:29
lerameur, Why not just read the total voltage of the series connection and then the lower cell voltage. Then subtract the lower voltage from the total voltage to get the upper cell voltage? That way you only have 1 ground connection.

Dave Purola,
N8NTA

lerameur
- 30th January 2007, 15:33
the batteries are not in series. One 12v battery for the controller, and a 24v (well 2 12v battery in series) for the motors. That is if I understood you correctly
k

Dave
- 30th January 2007, 20:51
lerameur, After my reply I re-read the post and understood the grounds are not common. Is this true? Why can't you common the grounds?

Dave Purola,
N8NTA

lerameur
- 30th January 2007, 22:26
I want to isolate the circuit . There was too much harmonics on the ground, it was killing the microcontroller.
what about an opto coupler ?
I am also looking some amplifier , any thoughts on this one: ISO124

Archangel
- 31st January 2007, 03:51
I want to isolate the circuit . There was too much harmonics on the ground, it was killing the microcontroller.
what about an opto coupler ?
I am also looking some amplifier , any thoughts on this one: ISO124

Hi leramuer,
about 35 years ago I worked for a company that made audio gear for radio stations and such. I remember, talking to the engineers about ground loops and they advised using 1 common tie point for all grounds, period. You might try that for the problem you mentioned.
JS

Dave
- 31st January 2007, 12:08
lerameur, Joe S. is right.... I have been designing test systems for about 30 years and have repaired problems with systems that stemed from having multiple grounds. If I was to design the type of system you are talking about I would have 1 single ground point. The noise you are talking about (upsetting the processor) is more than likley caused by the current being drawn from the 24 volt return from the motor drive system and where you are sensing or referencing the ground. I can't beleive that the processor 12 volt supply is that noisy or is drawing that much current. If both battery system returns were tied together at the batterys this should eliminate most of your problems. How much current is the 24 volt motor supply battery required to deliver?

Dave Purola,
N8NTA

lerameur
- 31st January 2007, 12:28
so basically tieing the two grounds together? then why not use a single battery for everything, wouldn't that be the same?
I am using about 2.5A for the motor battery.
you are saying that the harmonic going back to the battery will not affect the microcontroller ?
I suppose the harmonics is g0ing back on the ground, therefore affecting all the grounds in the system ?
I dont have 35 years experience like you guys, just trying trying to learn.

Dave
- 31st January 2007, 22:01
lerameur, If your current is not exceeding more than 2.5 amps I have to ask, What gage wire are you using to supply the motor drive electronics from the battery? You could see spikes in the current if your drive electronics have crossover problems with the H switch or if you are driving a low resistance load. This is why you should have the drive electronics wired as a separate set of feeds to the battery. What type of battery and size are you using for the drive electronics and what kind and size are you using for the microprocessor electronics? I have in the past build robotic drive systems that run off of a single 12 volt battery driving the controller electronics and dual H bridge drive electronics that can supply upto 100 amps. The only thing I had to do is to place a LC network in series with the microprocessor supply to kill some of the noise as I was using the A/D convertor on board the processor with a gyro rate sensor. The battery I used was an 18 amphour 12 volt used for UPS supply's.

Dave Purola,
N8NTA

lerameur
- 1st February 2007, 13:59
hi
When i was blowing up my microcontrollers, I was using a single 12v battery at 7AH. 20Gauge wire between the battery and motor (via the h-bridge) I was actually running at 1.95Amp.
Now I added opto couplers between the microcontroller and the h-bridge. I am still working on the circuit, should be powering it up today.
k

Dave
- 1st February 2007, 22:14
lerameur, Where are the opto isolators used in the circuit?

Dave Purola,
N8NTA

lerameur
- 1st February 2007, 22:23
opto isolators (mct6) between the microcontroller and h_bridge

ken