Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 31, 2024, 11:50:21 23:50


Login with username, password and session length


Pages: [1]
Print
Author Topic: Smart battery charger with PIC  (Read 13572 times)
0 Members and 1 Guest are viewing this topic.
dkopya
Guest
« on: November 30, 2007, 05:20:23 17:20 »

Hi everyone this is my first message so sorry for my faults....

I am looking for a battery charger circuit controlled with pic( 16fxxx series) but i can not find in the net a suitable one. I want to charge a lead acid battery. (12V) .  I need a pic controlled charger because i also want to use this circuit for control a TEC peltier device. Thanks  for you attention
Logged
Trishool
Active Member
***
Offline Offline

Posts: 113

Thank You
-Given: 9
-Receive: 9



« Reply #1 on: December 01, 2007, 08:18:03 08:18 »

Hi everyone this is my first message so sorry for my faults....

I am looking for a battery charger circuit controlled with pic( 16fxxx series) but i can not find in the net a suitable one. I want to charge a lead acid battery. (12V) .  I need a pic controlled charger because i also want to use this circuit for control a TEC peltier device. Thanks  for you attention

It would be difficult to sense battery current , with resistance etc , I would reccomend you to use some Battery managemant ICs from manufacturers like LTC, Maxim , Fuel gauges(TM) . To ease your situation,. Otherwise you would have to sense the battery voltage and current, and try to limit the charging current by switching the current waveform with a MOSFET or other such a device. But the question it will be a headache measuring battery current , I mean charging.

Ts
Logged
dihoc
Newbie
*
Offline Offline

Posts: 22

Thank You
-Given: 43
-Receive: 6


« Reply #2 on: December 02, 2007, 08:36:17 08:36 »

go to maxim-ic web site. they are a lot of application notes and ic which you can sample
Logged
awarapunshee
Guest
« Reply #3 on: December 02, 2007, 01:22:25 13:22 »

Here is PIC Power supply Unit, you can use it for the battery charging too. OR you can modify it for charging. There are many circuit available for the charger. (but not with PIC).

Regards
Logged
bbarney
Moderator
Hero Member
*****
Offline Offline

Posts: 2429

Thank You
-Given: 405
-Receive: 545


Uhm? where did pickit put my mute button


« Reply #4 on: December 02, 2007, 04:33:33 16:33 »

this psu uploaded by awarapunshee was pulled off the net by the author because it wasn't working properly but if you search the forum you will find a fix for it on another thread just can't remember where Grin
Logged

Ever wonder why Kamikaze pilot's wore helmet's ?
free
Active Member
***
Offline Offline

Posts: 115

Thank You
-Given: 71
-Receive: 13


« Reply #5 on: December 02, 2007, 07:40:58 19:40 »

There is in microchip's application notes website.
Logged

Some dream to escape reality, some to change it forever.
- Soichiro Honda -
Trishool
Active Member
***
Offline Offline

Posts: 113

Thank You
-Given: 9
-Receive: 9



« Reply #6 on: December 04, 2007, 06:07:54 06:07 »

Here is PIC Power supply Unit, you can use it for the battery charging too. OR you can modify it for charging. There are many circuit available for the charger. (but not with PIC).

Regards

awarapunshee ,He seems to need a smart battery charger ,PSU doesnt seems to be a good Idea as the topologies are different , I mean to say what will one do in events of when the battery is fully drained . I would suggest a CVT and a full bridge rectifier and a fat Aluminium electrolyte capacitor at the output  for charging a battery instead od a PSU though Smiley
« Last Edit: December 04, 2007, 06:11:30 06:11 by Trishool » Logged
donat
Guest
« Reply #7 on: December 05, 2007, 05:18:56 17:18 »

Hey you might want to check this out.

I'ts an application note from maxim with guidelines on how to build the hardware parts aswell as the software.

http://www.maxim-ic.com/appnotes.cfm/an_pk/680

Greets D.
Logged
dkopya
Guest
« Reply #8 on: December 07, 2007, 08:55:01 20:55 »

thanks for your attention.
I am living in Turkey and sometimes it is very difficult to find specific IC(But i can buy it from farnell).

Trishool, why it is difficult to sense the charcing currunt with resistor. May I  use 1 ohm resistor and read the voltage with ADC ? or will be there problem.
Logged
frasenci
Translator
Active Member
***
Offline Offline

Posts: 171

Thank You
-Given: 142
-Receive: 85


« Reply #9 on: December 08, 2007, 01:22:44 01:22 »

May I  use 1 ohm resistor and read the voltage with ADC ? or will be there problem.

I think you are in the right path if you want it simple, really simple.

Big problem when you want to charge a battery is to know how much current you are putting in it.
A good solution is to charge with CONSTANT current.
And there is a very cheap , easy to get IC that does this, an LM317 programmable Voltage regulator. ( US$ 1 )

Attached is a Proteus simulation showing 2 LM317 s connected in differente ways.
Both are powered by an DC Voltage source ( in this case I used a 24 V Battery but could be any other DC voltage source , like Notebook adaptor , etc )

In the IC at top , it is connected as Voltage regulator , with 720 ohm resistor in Adj leg wich will give a good steady 5 Volt output ( for example a PIC power )
The other Resistor between Output leg and Adj leg 240 ohm is only to mantain a minimal current and the regulator active.
BUT , the important thing is that LM317 will ALWAYS try to mantain the VOLTAGE between Adj and Output legs in a value = 1.25 Volt . ALWAYS ! By design.
You can read the flowing current in the simulation an do the math for the 240 ohm resistor , Voltage acrosss it = 1.25 Volt , ALWAYS.

So , if , as you can see in the LM317 at bottom , you connect a 10 Ohm resistance between Output leg and Adj leg , the Voltage across it will be EXACTLY 1.25 Volt , and the current flowing = 0.125 A or 125 mA.  Beware that the power dissipated at this resistance can be high , Power = Volt x Current . If using an 1 ohm resistance you will have 1.25 A flowing and power will be 1.25 x 1.25 = 1.56 W.
Yo simply connect the Battery to charge , in SERIES with that particular resistance. ( use those big ceramic types )
There you have it , a CONSTANT current charger.

From there on you can monitor your charger with the PIC.
1.- Monitor battery voltage
2.- Monitor voltage across series resistance ---> gives you the current , etc.    I = V / R

Yo know the capacity of the battery you are charging so you can use a timer to control total charging time ( total current )
You can experiment voltage behaviour of particular battery as it is been charged and control charging time according to it , as an alternative.

For power sources I have succesfully used leftovers from audio equipment, pulled them out + Rectifying bridge + fat capacitor as mentioned above. This transformers will usually give you two outputs , 22 VAC and 15 VAC. and well above 1.5 A of LM317 capacity.

Hope this helps you.
Greetings


 


Logged
belinao
Newbie
*
Offline Offline

Posts: 16

Thank You
-Given: 1
-Receive: 12


« Reply #10 on: December 09, 2007, 07:34:28 07:34 »

do you have a regulated dc input supply? If u donĀ“t then i think that the output current will be the most important aspect to be taken into account. If u could please especify this aspects we could help u better...

Logged
margo
Junior Member
**
Offline Offline

Posts: 52

Thank You
-Given: 38
-Receive: 33


« Reply #11 on: December 09, 2007, 03:53:49 15:53 »

perhaps a L200c regulator, orginally designed for lead acid charging

http://www.st.com/stonline/books/pdf/docs/1318.pdf

easy to measure I and V with a pic,, NOTE: do NOT put a lage capacitor on the output of any lead acid charger ( its the ripple current that does the charging, just look at your car charger, big transformer but no cap, or altinator big rectifer but no cap)
does not require constant current and or voltage
most 12v lead acid batteries will be damaged in no time if you discarge them below say 9v,( the plates buckle),if this is likely use a 'leasure' battery designed for deep cycle use
Logged
Wizpic
Global Moderator
Hero Member
*****
Offline Offline

Posts: 1200

Thank You
-Given: 550
-Receive: 409



« Reply #12 on: December 09, 2007, 09:13:08 21:13 »

What about this one from here and it's wrote in basic and should be easy to port over to Proton or PBP or just just the compiler that come with oshonsoft pic simutlator IDE. Look very good

http://www.oshonsoft.com/picchargerlcd.html

I did convert this to Protn but when computer crashed I lost the file,  Angry may be I should back up more often

wizpic
Logged

When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
Bart
Guest
« Reply #13 on: December 10, 2007, 10:52:47 10:52 »

Her is a nicd/nimh charge I'm playing with ...note the led's on gpio4/5 are not now used as these signals now
feed a 74hct164 shift reg that feeds 4 line LCD in nibble mode...
this is still undergoung changes.....MIKROBASIC

1> test charger
2> insert/wait for battery
3> precharge
4> charge
5> trickle


program ChargLCD19
' MIKROBASIC 5.0.2 DEMO VERSION     PROGRAM BY MIKE WARDLOW[XTAL]
'-------------------------------------------------------------------------------
'             POWER TOOL BATTERY CHARGER  9.6*   14.4   18*
'
'  B+ ---|----------------------o-----[LM317]-------------------------R
'         R 100                           |+             |                             1ohm R  Rc
'           |          +5V              ===             |                  1K                R
'       [7805] ---o---o-----|       |               |----------RRRR------------|
'           |        |      |       R    xxxx             |                                   Diode
'           |        |    ===     R 470                 |                      |-----------| +
' xxxxxxxxx       |      |       R                       |                     R                |
'                     |  xxxx      | +                   |/                10K R                |
' o---------o-o--  | ------|                -----| 2n2222a          R             -------
' |             |  |     R   + D    L            |       |\                     |               ---                                      |
' R 1K         R  R    R      E    E            R          v       |--------o            -------
' R     510   R  R    R      L    D +          R 1k      |       |           |               ---
' R             R  R    |470        |            R          |       |          R                 |         Battery
' |             |   |    |                 |--o-----|     xxxxx   |          R                 |
' |------|    L   L   xxxx             |                             |        2.2K R            |
' O        |    E   E    |                |                             |          |                 |
'  | SW  |    D   D    |--->    |1   |   8|<-- +5V            |       xxxxxxxxxxxxxxxxxxxxxxx
' O        |    |    |---gp5--> |2   |   7|<--   GP0 ----O-< ADC
' |         |    |-----gp4-->   |3   |   6|<--   GP1 --< Temp nu
' XXXX   |--------gp3-->    |4   |---5|<--   GP2 --> 0=charge 1=not
'                         12F683
'
'-------------------------------------------------------------------------------
''    GP4 is CLK-P
''    GP5 is Databit
'-------------------------------------------------------------------------------
'  want to use adc counts/4 = volts  ie  100 / 4 = 25  ==>  2.5 volt
'                                        400 / 4 = 100 ==> 10.0 volt
'  if possible                           1024 / 4 = 256 ==> 25.6 volt max
'-------------------------------------------------------------------------------
symbol LED4_ON = gpio.4 = 1         ' Status Led
symbol LED4_OFF = gpio.4 = 0
symbol LED5_ON = gpio.5 = 1         ' Charge Led
symbol LED5_OFF = gpio.5 = 0
symbol BATT = gpio.0                      ' battery input
symbol TEMP = gpio.1 = 1                  ' Temperature Input
symbol SWITCH_IN = GPIO.3                 ' for switch input
symbol CHARGER_ON = gpio.2 = 0            ' charger output
symbol CHARGER_OFF = gpio.2 = 1
symbol eClock = gpio.5=1:gpio.5=0
symbol sClock = gpio.5=1:gpio.5=0
symbol Testcharg = $00                 'test charger
symbol InstBatt = $10                  ' inst battery
symbol ONx = $20   symbol OFF = $25
symbol slowc = $30                     ' L-3  slowc
symbol normc = $38                     ' L-3  normc
symbol fastc = $40                     ' L-3  fastc
symbol trickle = $48                   ' L-3  trklc
symbol Precharg = $60                  ' L-3  precharge
symbol Ccell = $70                     ' L-4 charge    cells
symbol Finish = $80                    ' finish
symbol AdjCelCnt=$90                   ' ADJ CELL CNT XX
symbol ERRORX = $a0                    ' ERROR
symbol OK = $B0                        ' OK
symbol ERRx = $B8                      ' ER  ERROR
symbol RmvBatt = $C0                   ' L-2  remove battery
symbol Press_sw = $D0                  ' L-3  Press switch
symbol charging = $F0                  ' L-1  CHARGING
'-------------------------------------------------------------------------------
DIM np1,maxvolts,minvolts,volts AS WORD
DIM DB,Factor,F6,cells,ColCtr,pass,pct,chrgdat,termC,pctw AS BYTE
dim BatteryVolts, BON_Volts,BVONMAX as word
dim B1v1,B1v2,B1v3,B1v4,B1v5, cool as word     ' voltage readings
dim x2,y as byte
dim VFC,VRC,VSC,nibh,nibl,N1,N2,N3,sectr,hrs,mins,secs   as byte
dim ctime as integer
dim xx,aa,bb,cc,dd,N1W,N2W as word
dim ee,ff,gg,hh as byte
'-------------------------------------------------------------------------------
' using 10k/2.2k  ADC = volts*2200/61
' max CHARGE volt = 1.7/cell
' max discharged = .7 / cell
' voltconst = #cells * volts/cell * 2200/61
''const v12L as word = 1*7*220/61         '  1 * .7 *2200 / 61
''const v12H as word = 1*17*220/61        '  1 * 1.7 *2200 / 61

const MaxTime as integer = 2400         '  4hr = 14400 sec / 6 = 2400

'const Initx as byte[6] = (0x33,0x32,0x28,0x0c,0x06,0x01)
'=====================================================
'sub function Eread(dim N01 as byte) as byte
'   EEADR= N01
'   EECON1.RD = 1      ' read it
'   result = EEDATA
'end sub
'====================================================
sub procedure Clr6
gpio.5=0 for x2=1 to 6  gpio.4=0  gpio.4=1  next x2
end sub
'============================================================
sub procedure DLY5    delay_ms(5)    end sub
sub procedure DLY10   delay_ms(10)   end sub
sub procedure DLY50   delay_MS(50)   end sub
sub procedure DLY100  delay_ms(100)  end sub
sub procedure DLY300  delay_ms(300)  end sub
sub procedure DLY500  delay_MS(500)  end sub
sub procedure DLY700  delay_ms(700)  end sub
sub procedure DLY900  delay_ms(900)  end sub
sub procedure DLY2k   delay_ms(2000) end sub
'============================================================
sub procedure delays(dim N01 as byte)
    for xx=1 to N01
      DLY10
    next xx
end sub
'============================================================
sub procedure hexbcd(dim N01 as word)
aa=N01 bb=aa div 10 cc=aa div 100 dd=aa div 1000
ee=aa mod 10 or $30   ff=bb mod 10 or $30
gg=cc mod 10 or $30   hh=dd mod 10 or $30
end sub
'============================================================
sub procedure hextime(dim N01 as word)
  N2W = N01
  N1W = N2W div 60
  secs = N2W mod 60
  mins = N1W mod 60
  hrs = N1W div 60
end sub
'============================================================
SUB FUNCTION PROCESS(dim chnl as byte) AS WORD
          delay_ms(2)                    ''delay_ms(1)
          ADCON0 = (0x81 or chnl << 2)   ' RIGHT JUSTIFY VDD REF CHANNELX
          Delay_US(100)                  ' WAIT 100US AFTER ADON / CHNL CHANGE
          ADCON0.GO = 1                  ' START CONVERSION
         WHILE ADCON0.GO WEND
         NP1 = ADRESH * 256 + ADRESL    ''   NP1 = ADRESH << 8 + ADRESL
         RESULT = NP1                   ' current average battery voltage
END SUB
'===============================================================================
sub procedure MemUp          ' v0==>v1==>v2==>v3==>v4==>v5
  B1v5=B1v4 B1v4=B1v3 B1v3=B1v2  B1v2=B1v1  B1v1 = BatteryVolts
end sub
'======================================================
sub procedure LnClkNIB(dim N01 as byte) '   N01  =  _ _ RS d7 d6 d5 d4 E
  y = N01                               ' sr-bit    0 1 2  3  4  5  6  7
  gpio.5=0
  for x2 = 1 to 6                       ' clock  nibble into Sreg bit
    if Y.0=1 then gpio.5=1 end if
      Y = Y >> 1  gpio.4=0  gpio.4=1  gpio.5=0
    next x2
  gpio.5=0                              ' shift in x - x & D/Eclock
  gpio.4=0  gpio.4=1  gpio.4=0  gpio.4=1 gpio.5=1  gpio.5=0
  Clr6  delay_us(150)                  '  clear out sr and wait 150
end sub
'=====================================================
sub procedure SendCmd(dim N02 as byte)
  nibh = (N02 >> 3 and $1E)or 1    nibl = (N02 << 1 and $1E) or 1
  LnClkNIB(nibh)    LnClkNIB(nibl)
end sub
'=====================================================
sub procedure SendData(dim N02  as byte)
  nibh = (N02 >> 3 and $1E)or $21    nibl = (N02 << 1 and $1E) or $21
  LnClkNIB(nibh)    LnClkNIB(nibl)
end sub
'===============================================
sub procedure DispEprom(dim N01 as byte)
  EEADR = N01
    While 1
      EECON1.0=1   N1=EEDATA
      IF N1=0 then exit end if
      IF   (N1 < 128) then SendData(N1) else SendCmd(N1) end if
      EEADR = EEADR + 1
    wend
end sub
'==============================================
sub procedure clr(dim N01 as byte)
   select case N01
     case 1 xx=$80 case 2 xx=$C0 case 3 xx=$90 case 4 xx=$D0
   end select
   SendCmd(xx)
   for xx=1 to 16
     SendData(" ")
   next xx
end sub
'===============================================
sub procedure DispASCII(dim N01 as byte)
  N1=N01>>4  N2=N01 and 15
   if N1>9 then N1=(N1-9) or $40 else N1=N1 or $30 end if
   if N2>9 then N2=(N2-9) or $40 else N2=N2 or $30 end if
   SendData(N1) SendData(N2)
end sub
'====================================================
sub procedure DispVolts(dim N01 as word)
  ''N3=hi(Batteryvolts) DispASCII(N3) N3=lo(Batteryvolts) DispASCII(N3)
    hexbcd((N01*10)/37)    ''SendData(hh)
    SendData(gg)  SendData(ff)  SendData(".")  SendData(ee)
end sub
'====================================================
sub procedure DispASCword(dim N01 as word)
  N3=hi(N01) DispASCII(N3) N3=lo(N01) DispASCII(N3)
end sub
'-------------------------------------------------
'sub procedure DispString(dim byref N01 as string[16])
'    z2=0
'    while N01[z2] <> 0
'     z1=N01[z2]
'     if z1 >127 then
'      SendCmd(z1)      ' set position
'     else
'      SendData(z1)     ' display data
'     end if
'       z2=z2+1
'    wend
'end sub
'====================================================
sub procedure DispBattVolts(dim N01 as byte)
  SendCmd(N01) DispVolts(BatteryVolts)
end sub
'====================================================
sub procedure DispONOFF(dim N01 as byte) ' L1-$80 L2-$C0 L3-$90 L4-$D0
  SendCmd(N01)
  DispEprom(ONx)  DispVolts(BON_Volts)  SendData(" ")
  DispEprom(OFF)  DispVolts(BatteryVolts)
end sub
'======================================================
sub procedure PCTP
    if pct< 25 then pct=pct+5 end if
end sub
'=====================================================
sub procedure PCTM
    if pct>5 then pct=pct-5 end if
end sub
'=====================================================
sub procedure PCTS
    if pct>5 then pct=pct-1 end if
end sub
'====================================================
sub procedure VCHECK
 if BatteryVolts = B1v5 then  '------------------------------ BV =B1V5 SAME
  chrgdat = "S"  VFC=3  VRC=3  VSC=VSC-1 PCTS
  if VSC = 0 then  Factor = 6 termC="S" end if  goto VCENDB
 end if
 VSC=10
 if BatteryVolts < B1v5 then '------------------------------- BV < B1v5 FALLING
  chrgdat="F"  VRC=3  VFC=VFC-1 PCTP
  if VFC=0 then  factor=6 VFC=3 termC="F"  end if   '
 else '------------------------------------------------------ BV > B1V5 RISING
  chrgdat="R"  VFC=3  VRC=VRC-1  PCTM
  if VRC=0 then VRC=3 if factor<5 then factor=factor+1  end if  end if
 end if
VCendB: if PROCESS(1)>0x3ff then cool=180 F6=Factor end if   ' 3 minutes cooling
VCendA: if ctime<=0 then ctime=4*60*60  F6=Factor Factor=9 termC="T" end if
 SendCmd(ColCtr) if pass=1 then SendData(chrgdat) else SendData(chrgdat or $20) end if
end sub
'===============================================================================
sub function charge() as byte
pctw=100-pct
if cool=0 then
  charger_on
  select case Factor
    case 3 DLY300 case 4 DLY700 case 5 DLY900
    case 6
      'select case pct case 25 DLY100 DLY100  dly50          ' 25 %
      '                case 20 DLY100 DLY100                  ' 20%
      '                case 15 DLY100 DLY50                 ' 15 %
      '                case 10 DLY100                        ' 10%
      '                case 5 DLY50                          ' 5%
      'end select
      delays(pct)
  end select
      BON_volts = PROCESS(0)  charger_off
      if BON_volts > BVONMAX then Factor = 99 exit end if
  select case Factor
    case 3 DLY700 case 4 DLY300 case 5 DLY100 case 6 delays(pctw) 'DLY900
  end select
else
  DLY100   DLY900   cool = cool -1
end if
BatteryVolts = PROCESS(0)
  if sectr = 0 then
    MemUp  sectr=30 ColCtr=colctr+1
    if ColCtr=$A0 then ColCtr=$9A  pass = pass xor 1   end if
      VCHECK
  end if
ctime=ctime-1  sectr=sectr -1  result=Factor


SendCmd($80) '' DispASCword(ctime)   SendData(" ")        ' Line-1   ctime
hextime(ctime)
hexbcd(hrs)  SendData(ee)  SendData(":")
hexbcd(mins) SendData(ff)  SendData(ee)  SendData(":")
hexbcd(secs) SendData(ff)  SendData(ee)  SendData(" ")

'''DispASCii(sectr)  SendData(" ")           '          sectr
'hexbcd(sectr) SendData(ff) sendData(ee)  SendData(" ")
DispASCii(VFC)  SendData(" ")
DispASCii(VRC)  SendData(" ")
DispASCii(VSC)
DispONOFF($90)                   ' display on/off battery volts on line
SendCmd($D0)
SendData("T") SendData("=") SendData(termC)
end sub
'===============================================================================
' Check the three state inputs
'-------------------------------------------------------------------------------
'SUB FUNCTION PINSTATE(DIM PINX AS BYTE) AS WORD    ' PORT A/B  5/6
'       TRISB.PINX = 0 ' SET AS OUTPUT
'       PORTB.PINX = 0 ' SET PIN LO
'       TRISB.PINX = 1 ' SET PIN AS INPUT
'       IF PORTB.PINX = 1 THEN ' STRAPPED HI ?
'          RESULT = 2000
'       ELSE
'          TRISB.PINX = 0 ' SET AS OUTPUT
'          PORTB.PINX = 1 ' SET PIN HI
'          TRISB.PINX = 1 ' SET AS INPUT
'          IF PORTB.PINX = 0 THEN ' STRAPPED LO
'             RESULT = 1000
'          ELSE
'             RESULT = 1500
'          END IF
'       END IF
'END SUB
'===============================================================================
sub function TestCharger() as byte                   '361 => 10volts Charger ok
  Charger_OFF  DLY100    BatteryVolts = PROCESS(0)   ' get charger off voltage
  if BatteryVolts < 93 then Charger_ON   DLY50   BON_Volts = PROCESS(0)     '93
    if BON_Volts > 361 then
     DispEprom(OK)  RESULT = "I"  BVONMAX = BON_Volts - 25
    else  DispEprom(ERRx)   RESULT = 99   end if             ' ERROR
  else                             ' press sw after batt removed  ' goto MAIN1
    if BatteryVolts<972 then
      DispEprom(RmvBatt)
      while switch_in=1 wend
      Result=98
    else
      DispEprom(ERRx)
      RESULT = 99
    end if             ' ERROR
  end if
  Charger_OFF  DLY900
end sub
'==============================================+++++++++++++++++++++++++++++++++
sub function CHARGER_ERR() as byte                 ' 27 volts *2200/61 = 974
  CHARGER_OFF  clr(4)                              ' clear Line 4
  while switch_in=1
    SendCmd($D0)                                    ' Line 4
    if pass=1 then  DispEprom($A0) else   DispEprom($50)  end if
    pass=pass xor 1  DLY100  DLY100
  wend
  Result = 98    ' press Sw  ' goto main1
end sub
'===============================================================================
sub function Wait4Battery() as byte
  BatteryVolts = 0  b1v1 = 0  b1v2 = 0   b1v3 = 0  b1v4 = 0   b1v5 = 0
  Charger_off                                  ' WAIT4BATTERY
W4B:  BatteryVolts = PROCESS(0)                '  VOLTS * 2200 / 61 = ADC value
  DispONOFF($C0)
  if BatteryVolts>93 then goto W4A end if   ' 75
  if Switch_in = 0 then  goto W4A end if
  DLY100
  goto W4B
W4A: RESULT = "P"                                 '  PRECHARGE
  DLY300
  SendCmd($8D) DispEprom(OK)
  DLY700
end sub
'===============================================================================
sub procedure DispQsec(Dim N01 as word,dim N02 as byte)
   hexbcd(N01/4)
   SendCmd(N02) SendData(gg) SendData(ff) SendData(ee) ' L-3 pass # / 4 = seconds
end sub
'===============================================================================
' After detecting a battery connected determine # of cells and use switch
' to adjust....update battery readings every 200 MS for 1 minute after
' last switch press..
' CELL COUNT [Press Switch - observe count] 1 - 15 cells.......
'-------------------------------------------------------------------------------
sub function PRECHARGE() as byte
PRECHARGE:
  for xx=1 to 360                                         ' 360/4 = 90 seconds
   charger_on DLY50  BON_Volts=PROCESS(0)  charger_off  DLY100 DLY100
   BatteryVolts=PROCESS(0)   MemUp
   DispONOFF($C0)                                          ' L-2
   DispQsec(xx,$9d)                                        ' L-3 seconds
  next xx                                                 ' adc*61/(2200*1.25)
  cells = BatteryVolts *61 / 2970                         ' 1.35*2200=2970
  if cells>15 then cells=15 end if                        ' 1.25*2200=2750
  xx=300
  cellcount:
    xx=xx-1  hexbcd(cells)  DispEprom(AdjCelCnt)  SendData(ff)  SendData(ee)
    DispQsec(xx,$9d)                                        ' L-3 seconds
    BatteryVolts = PROCESS(0)
    DispONOFF($C0)                                        ' L-2
     if Switch_in = 0 then                                ' pressed = 0
       while Switch_in = 0 wend                           ' debounce
       cells = cells+1
       if cells >= 16 then cells = 1 end if
       xx = 300 goto cellcount                            ' reset counter
     end if
     DLY100
    if xx > 0 then goto cellcount end if
    minvolts = cells*8*220/61                             ' #cells * .8 * 2200/61
    volts = cells*15*220/61
    maxvolts = cells*17*220/61                            ' ?charging volts
    ctime = 2*60*60                                       ' set 2 hour timer = 7200 sec
    cool = 0                                              ' set cooling = off
    RESULT = 3
    clr(1)                                          ' clear Line 1 for stat disp
    clr(3)                                                ' L-3 clear line
end sub
'===============================================================================
MAIN: OSCCON = 0X70           ' 8 MHZ INTERNAL         .75% PER STEP
      OSCTUNE = 0             '0X1D     ' 0X0F MAX FREQ
                              ' 0E 0D 0C 0B 0A 09 08 07 06 05 04 03 02 01
                              ' 0X00 CENTER FREQ
                              ' 0X1F MIN 1E 1D 1C 1B 1A 19 18 17 16 15 14 13 12 11
                              ' 0X10 MIN FREQ
                              ' SLOW 8US/300US = 2.6% = 3.5 STEPS TRY 0X03
                              ' FAST 6US/300US = 2.0% = 2.6 STEPS TRY 0X12
      CCP1CON = 0
      'CMCON = 7
      'PORTA = 0
      'PORTB = 0
      'TRISA = %00100001
      'TRISB = %11111111
      trisio = %00001011      ' gp0=adc GP1 = ADC  gp3=in
'====================================================================
'  STOP THE TIMERS     USING 8MHZ BASE FREQ  OSC/4 = 2MHZ  .5US/CYC
'--------------------------------------------------------------------
  'OPTION_REG = 1              ' PRESCALE 1:4 2US RESOLUTION   12F683/16F88
  INTCON.T0IE = 0              '  BLOCK    TMR0     INTERRUPT
  T1CON = 0X10                 ' 1:2=1US RESOLUTION  & STOPPED 0X01=RUN
                               ' B7=0=  2 8-BIT WRITES HI/LO
  T2CON = 0X05                 ' 1:4=2US RESOLUTION  & STOPPED 0X04=RUN
'===================================================================
' ENABLE INTS                  '
'  setbit(pie1,adie)           ' ENABLE ADC CONVERSION INTERRUPT
'  setbit(pie1,tmr2ie)         ' ENABLE TIMER 2 INTERRUPT
'   setbit(pie1,tmr1ie)         ' ENABLE TIMER 1 INTERRUPT
'  setbit(intcon,T0IE)         ' ENABLE TIMER 0 INTERRUPT
'  setbit(intcon,peie)          ' ENABLE PERIPHERAL INTERRUPTS
 '''' setbit(intcon,gpie)      ' ENABLE PINCHANGE INTERRUPTS
 ' PIR1.TMR1IF = 0              ' CLEAR ANY PEND T1 INT
 ' setbit(intcon,gie)           ' ENABLE ALL INTERRUPTS
'===============================================================================
MAIN1: '''ANSEL = 0X7F           ' FOSC/16[8MHZ CLOCK] chn 0,1,2,3
       ANSEL = 0x53              ' fosc/16[8mhz] chan 0,1
       ADCON0 = 0X01             '      C C C GO ON
       cells = 15
      ' ADCON1 = %01111110       '0X00 1 ANALOG INPUTS AN0
      ' ADCON2 = %10101101       ' RJ TAD16 FOSC/16
       CHARGER_OFF
'-------------------------------------------------------------------------------
        PIR1.TMR1IF = 0                       ' CLEAR ANY PEND T1 INT
 '--------------------------------------------
gpio.4=1         ' set initial cloxk state
Clr6             ' clear shift reg
Clr6
delay_ms(50)     ' power on wait
'==============================================================
'  Intitalize LCD to 4 bit
'--------------------------------------------------------------
LnClkNIB(7)      ' 3 N01  =  _ _ RS d7 d6 d5 d4 E
DLY5
LnClkNIB(7)      ' 3  N01  =  _ _ RS d7 d6 d5 d4 E
delay_ms(1)
LnClkNIB(7)      ' 3  N01  =  _ _ RS d7 d6 d5 d4 E
DLY5
LnClkNIB(5)      ' 2  N01  =  _ _ RS d7 d6 d5 d4 E
SendCmd($0E)     ' cursor underline
MAIN2:
  SendCmd($01)     ' Clr display
  DLY5
  Factor = "T"
'=============================================================
' Test Leds / Outputs
'-------------------------------------------------------------
  sectr = 1        ' preset second counter
  cool = 0         ' preset cooloff time in seconds
  ColCtr = $99     '
  pass=0
  termC="x"
  BON_Volts=0
  VFC=3  VRC=3  VSC=10 pct=15
while 1
Select case factor
   case "T"
     clr(1)
     DispEprom(Testcharg)       ' Line 1 - display "Test Charger"
     DLY2k
     factor = TestCharger    ' TestCharger returns  1=charger ok   99=error
   case "I"
     clr(1)
     DispEprom(InstBatt)       ' Line 2 - "install batt"
     factor = Wait4Battery   ' Wait4Battery returns Factor code 2=precharge
   case "P"
     DispEprom(Precharg)     ' Line 3 - "PRECHARGE"
     Factor = PRECHARGE      ' PRECHARGE returns 3= slow charge
   case 3
     DispEprom(slowC)        ' slow charge 30%
     DispASCII($30)
     SendData("%")
     charge
   case 4
     DispEprom(normC)        ' normal charge 70%
     DispASCII($70)
     SendData("%")
     charge
   case 5
     DispEprom(fastC)        ' fast charge 90%
     DispASCII($90)
     SendData("%")
     charge
   case 6
    ' SendCmd($C0)
    ' DispEprom(finish)       ' L-2 FINISH
     DispEprom(Trickle)      ' L-3 TRKL xx%
     hexbcd(pct)
     SendData(ff) SendData(ee)
     SendData("%")
     charge                  ' goto charge_fin
   case 7
   case 8
   case 9
     cool = 1
     charge
     if ctime<=5 then ctime=2*60*60 Factor=F6 end if       ' Trickle
   case 98
     goto MAIN2
   case 99
     factor = Charger_Err
end select

wend


END.
''''----------------EPROM FILE .eep
0x00 80 54 45 53 54 20 43 48 41 52 47 45 52 20 00 FF
0x10 80 49 4E 53 54 20 42 41 54 54 45 52 59 20 00 FF
0x20 C0 4F 4E 20 00 C8 4F 46 46 20 00 FF FF FF FF FF
0x30 90 53 4C 4F 57 43 20 00 90 4E 4F 52 4D 43 20 00
0x40 90 46 41 53 54 43 20 00 90 54 52 4B 4C 43 20 00
0x50 20 20 20 20 20 20 20 20 20 20 45 52 52 4F 52 00
0x60 90 50 52 45 43 48 41 52 47 45 20 00 FF FF FF FF
0x70 D0 43 45 4C 4C 53 20 00 FF FF FF FF FF FF FF FF
0x80 46 49 4E 49 53 48 20 00 20 20 20 20 20 20 20 00
0x90 D0 41 44 4A 20 43 45 4C 4C 20 43 4E 54 20 00 FF
0xA0 45 52 52 4F 52 20 20 20 20 20 20 20 20 20 20 00
0xB0 4F 4B 00 FF 52 42 00 FF 45 52 00 FF FF FF FF FF
0xC0 C0 52 45 4D 4F 56 45 20 42 41 54 54 45 52 59 20
0xD0 90 50 52 45 53 53 20 53 57 49 54 43 48 20 20 00
0xE0 90 41 44 4A 55 53 54 20 43 45 4C 4C 20 00 FF FF
0xF0 80 20 20 20 20 43 48 41 52 47 49 4E 47 00 FF FF
« Last Edit: December 10, 2007, 11:24:56 11:24 by Bart » Logged
shailesh5
Translator
Junior Member
***
Offline Offline

Posts: 41

Thank You
-Given: 56
-Receive: 3


« Reply #14 on: December 10, 2007, 01:08:06 13:08 »

Bart,
 are  you charging batteries with the program you have written ? by the way its seems to be a nice program you have written , i was doing one with a pic16f877 but i stopped as lack of time. do you have the circuit in proteus format?
thank shailesh
« Last Edit: December 10, 2007, 01:42:08 13:42 by shailesh5 » Logged
shailesh5
Translator
Junior Member
***
Offline Offline

Posts: 41

Thank You
-Given: 56
-Receive: 3


« Reply #15 on: December 11, 2007, 02:08:04 14:08 »

i have just tried to use ure design of charger but i get errors, can u post the design again thanking you in advance
shailesh
Logged
EDSONCT
Junior Member
**
Offline Offline

Posts: 36

Thank You
-Given: 72
-Receive: 5


WWW
« Reply #16 on: December 11, 2007, 06:08:33 18:08 »

Texas has a good project for MS430 with source code, maybe help you do make by pic
Logged
Wizpic
Global Moderator
Hero Member
*****
Offline Offline

Posts: 1200

Thank You
-Given: 550
-Receive: 409



« Reply #17 on: December 11, 2007, 08:36:03 20:36 »

Here is another good link with chargers on it and other stuff a very good site, you can even monitor it with PC

http://www.seven-segments.com/index.php?action=pageshow&id=54&idcat=33

wizpic

Logged

When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
jorge7458
Newbie
*
Offline Offline

Posts: 27

Thank You
-Given: 7
-Receive: 14


« Reply #18 on: December 12, 2007, 05:33:58 17:33 »

Hi:
http://www.oshonsoft.com/picchargerlcd.html
Its great proyect
Jorge
Logged
yugal
Junior Member
**
 Warned
Offline Offline

Posts: 60

Thank You
-Given: 919
-Receive: 73


« Reply #19 on: December 16, 2007, 01:41:52 13:41 »

Hi,
     Here is a good lead acid charger circuit controlled by pic micro.
          EPE-January 2007 & february2007
                                                          regards.
                                                                      yugal
Logged
madmax
Newbie
*
Offline Offline

Posts: 15

Thank You
-Given: 10
-Receive: 1


« Reply #20 on: January 16, 2008, 05:02:50 17:02 »

Here is an app note from Microchip for a programable Lead Acid battery Charger. http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en025786

-MadMax
Logged
Walkura
Active Member
***
Offline Offline

Posts: 123

Thank You
-Given: 56
-Receive: 82


« Reply #21 on: April 20, 2008, 07:13:18 07:13 »

Micrichip has in this serie of processors a specialised processor .
There is also software for it i think it was called powertool 200 .
http://ww1.microchip.com/downloads/en/AppNotes/01015a.pdf
I didnt build this charger myself (yet) .
But i bumped into it doing some research about charging with microchip .
There are 3 different processors for lead acid ,nickel & lithium ion battery's .

Good luck .
Logged
Walkura
Active Member
***
Offline Offline

Posts: 123

Thank You
-Given: 56
-Receive: 82


« Reply #22 on: April 22, 2008, 05:22:11 17:22 »

You can measure current with an acs750 .
Its a current sensor based on the hall principia .
A low ohm resistor is ofcourse possible but you will have to write a routine to compensate the voltage over the resistor .
Something like , Vbatt = Vmeasured - (r * Imeasured)
Cheap dirty and a lil dissapative but if the power isnt to high its not much of a problem .
Personaly i use the acs whenever i need ampere readings to my micro's but thats personal i guess Smiley

Good luck .
Logged
ucup
Newbie
*
Offline Offline

Posts: 9

Thank You
-Given: 4
-Receive: 2


« Reply #23 on: April 25, 2008, 03:34:42 03:34 »

You can build a circuits by yourself, you can use a programmable regulator with LM2576-adj. find a datasheet of LM2576 on the internet and repleacement R2 with digital potensiometer like DS1267. Now U can just program it by PIC to chargeing a lead acid battery

ucup
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC