Download PIC846 - Maxim Integrated

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Stray voltage wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Voltage optimisation wikipedia , lookup

Mains electricity wikipedia , lookup

Alternating current wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Buck converter wikipedia , lookup

Metadyne wikipedia , lookup

Emulator wikipedia , lookup

Opto-isolator wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Transcript
; MAXIM MAX846 CHARGER DEMONSTRATION AND TEST CODE
; Maxim Engineering Journal 28- Oct 1997 example #1
;********************************************************************
; ...............................................................
; . note: this document was distributed with the file extension .
; . ".doc" for compatibility with our web environment.
.
; . The extension would preferably be ".asm" in a more standard .
; . environment. The file format is plain ascii however. .
; ...............................................................
;********************************************************************
; FIRMWARE NOTES
;
; This software implements an LED user interface and a charge
; termination timer for the Maxim MAX846 or MAX745 using an 8
; pin microchip PIC processor.
The same code will operate with
; few changes on any PIC family member and testing was done with
; the 16C54 and 12C508. The Engineering Journal article shows a
; schematic of the MAX846 with a note that the MAX745 can be
; used also. The MAX846 or MAX745 differ somewhat in operation,
; though the software supports both with no changes. The MAX745
; has an additional output that can be used to get a better
; picture of charge status with no additional components. The
; MAX846 can also be adapted for similar operation as described
; below. Note that these chargers are basically stand-alone and
; the processor is just augmenting operation by giving a maximum
; timeout and lighting some status LED's. The MAX745 and MAX846
; application details are as follows:
;
; MAX745 Application
; The MAX745 has an output called "STATUS". This output is low
; in current regulation mode and is high Z in voltage mode, or
; pulled up high to Vl here. As described in the article, the
; software monitors this pin and terminates charging 125 minutes
; (the article said " 5 minutes") after the Lithium Ion voltage
; limit is reached. This allows 5 minutes more than the two
; hours that should be required for a full charge at a 1/2C
; rate.
It also terminates charging after a fixed time of 165
; minutes. These values are software constants and can be changed.
;
; MAX846 Application
; The MAX846 does not have a status pin or the equivalent, so a
; simple method of sensing current mode/float is not possible.
; the code simply turns off the charger after a fixed total
; time. This time is 165 minutes. Timing starts from each
; reset.
; Alternatively, the voltage on the Iset can be monitored if
; operation like the MAX745 application is desired. The Iset
; pin can be monitored with a comparator/reference such as
; the MAX921 or MAX836. In constant current mode, this point
; will regulate at 1.65V, full scale. The voltage detector
; trips at 1.25, which is about 75% of the full current value
; which is well into the constant voltage mode. A constant
; time like 125 minutes beyond this point can be used.
The
; current can also be monitoired for a very low value such as
; 5% of the limit value with a little extra circuitry.
;
; Note that the fault LED is not implemented in this code. In
; either application, it can time the ammount of time required
; to reach constant voltage mode. A fault can be generated if
; this takes too long. A simple temp sensor such as the MAX6501
; temperature reset can also be attached to the battery and
; a fault can be generated for an over temperature error.
;
; This code makes use of the paced loop structure without
; interrupts as described in the article. It is primarily
; intended as a simple firmware template and structure example
; for the PIC processors.
;********************************************************************
;
; "PIC" and "Microchip" are trademarks of Microchip Technology
;
; This software should be considered experimental. It is
; offered for demonstration and test purposes, "as-is" only.
;
;********************************************************************
; Maxim Integrated Products
; Applications Engineering
; 120 San Gabriel Drive
; Sunnyvale, CA 94086
; (800) 998-8800 x4000 applications hotline
;
; Author Contact:
; John Wettroth, Maxim Southeast Apps
; (919) 303-5733 [email protected]
;
;********************************************************************
;REVISION HISTORY
; *** rev 0- 6/6/97 *** wettroth
; Operation with the 16C54 with emulator- test of features
;
; *** rev 1- 6/15/97 *** wettroth
; port to 12c508 processor- test/OK
;
; *** rev 2- 9/12/97 *** wettroth
; cleanup, comments/header, some testing
;
;********************************************************************
; BUILD NOTES
;
; Assembled under Parallax Assembler PASM V2.4 1994 for compatibility
; with 16C54 emulator, this assembler doesn't support the 12C508.
; Final 12C508 code assembled with with SPASM V4.7 1996. Emulator
; used was the Parallax PEP downloader (1994). SW Tools are available
; from the Parallax BBS/FTP Site- BBS (916) 624-7101
;********************************************************************
; KNOWN BUGS
; none known- code should be considered experimental only without
; any formal testing or verification.
;********************************************************************
;BEGIN DIRECTIVES
;********************************************************************
; PIC Processor Options are 12C508 (8 pin) or 16C54 (18 pin)
; the larger parts were used for emulation and are fully compatible
; memory map details are noted below
; DEVICE PIC16C54,XT_OSC,WDT_OFF,PROTECT_OFF
DEVICE PIC12C508,IRC_OSC,WDT_OFF,PROTECT_OFF
;RAM LOCATIONS- compatibility between 16c54 and 12c508
;12c508 has 25 bytes ram (12c509 has 41- 25+16 bank2)
;
; mapping- 12c508
16c5X
Notes
;---------------------------------------------------; 0 ind reg (@fsr)
ind
; 1 tmr0
rtcc
; 2 pcl
pcl
; 3 status
status
; 4 fsr (pointer)
fsr
; 5 oscal
porta
** avoid
; 6 gpio (6 bits)
portb
; 7-1f
gp reg's
ram
; 30-3f gp reg's (509)
ram
;
; *** I/O Equates
;outputs
;GPIO EQU
06
;used for 16c54 emulation Port B
;
;with old assembler
DNLED EQU
0
;gpio 0/out- done- green (active low)
CHLED EQU
1
;gpio 1/out- charge- orange (active low)
FTLED EQU
2
;gpio 2/out- fault- red (active low)
; note gp3 is an alternate function of mclr- reset input
; the external MCLR function is enabled so this function
; is not available- this is optional if a pin is neeeded
ONOUT EQU
4
;gpio 4/out- charge enable (active high)
MDIN EQU
5
;gpio 5/in- mode input- high V mode
;
;port values
GPDEF EQU
15H
;port B/GPIO default value- charging
DNPRT EQU
06H
;port B/GPIO done value- done led
;
;tris value for GPIO/RB
TRSVL EQU
28H
;io's as above- gp3 is input only
OPTVL EQU
07H
;rtcc internal/prescale=256
;debug option value below- change before final code
;OPTVL
EQU
01H
;faster option for debug prescale=1
;this makes minutes=seconds (64xfaster)
;* when programming- disable wdt/enable intRC osc/code protect *
;
;*** RAM Equates
TICK EQU
10H
;count of 15.25 hz ticks- to 4 seconds
MINCT EQU
11H
;count of 4 seconds- to 1 minute
TOTM EQU
12H
;total timer- to 255 minutes
HITM
EQU
13H
; *** constants
TOTM0 EQU
165
HITM0 EQU
125
;hi timer- to 255 minutes
;total timeout value- 165 minutes
;hi timeout value- 125 minutes
; *** Literals
; constants/literals
Cy
EQU
0
;carry bit
Zr
EQU
2
;zero bit
;f
EQU
1
;destination value - "d"- old asm only
;********************************************************************
;SUBROUTINE AREA
;(subs must be in low page- 9 bit stack- 12C508 only has one page)
;********************************************************************
; Start Jump
; the 12C508 starts at address 0, the 16C5x start at 1FFORG
0H
;reset vector- 12C508
GOTO START
;
;
; ** NO SUBS **
;
;************************************************************
;END SUBROUTINES
;****************************************************************
;MAIN ROUTINE- PSEUDO CODE
;****************************************************************
;THROUGHOUT CODE- THESE LABLE ARE COMMENTED WITH "***" FOR REF
;
; start: initialize all
;
green led on
//charging if just started
; top : while not 1 minute{} //top of timer loop (no irq's)
;
reset minute timer
; pace : total_time++
//inc total timer- minutes
;
if input low
//check input
;
{reset hi_time}
//reset hi timer if in low
;
else
;
hi_time++
//bump hi timer
;
if hi > limhi
//check hi time limit
;
goto done
//done- hi limit
;
if hi > limtot
//check total time limit
;
goto done
//done- hi limit
;
go top
//loop top
; done: charger off
//kill charger
;
green led off
//charge led off
;
orange led on
//done led on
; hang: goto hang
//wait for a reset
; actual implementation varies- timers all count down, etc
;************************************************************
;BEGIN MAIN CODE
;****************************************************************
; *** start: initialize all
START MOVLW GPDEF
;init port B/GPIO
MOVWF GPIO
;output to port register
MOVLW TRSVL
TRIS GPIO
;initial io's
;set it-
MOVLW OPTVL
OPTION
; init timers/countersMOVLW TOTM0
MOVWF TOTM
MOVLW HITM0
MOVWF HITM
; done initializations
;option register value
;put in option register
count down timers
;inital countdown value- total time
;total timer
;inital countdown value- hi time
;total timer
;****************************************************************
; *** top : while not 1 minute{} //top of timer loop (no irq's)
TOP
MOVLW 61
;init tick timer- 16 ms * 61 = 4sec
MOVWF TICK
;
MOVLW 15
;init minute timer
MOVWF MINCT
;
WTRTH BTFSS RTCC,7
;wait for msb of rtcc set
GOTO WTRTH
;wait
WTRTL BTFSC RTCC,7
;wait low
GOTO WTRTL
;wait
DECFSZ
TICK,F
;dec ticks
GOTO WTRTH
;loop ticks for 4 seconds
MOVLW 61
;reset ticks- each 4 seconds
MOVWF TICK
;
DECFSZ
MINCT,F
;dec min counter
GOTO WTRTH
;loop ticks for 4 seconds
;get here once per minute- paced loop below
;****************************************************************
; *** pace : total_time++
//inc total timer- minutes
PACE DECFSZ
TOTM,F
;PIC doesn't have inc/test
GOTO CKINP
;if not total time- continue
GOTO DONE
;if total time then done
CKINP BTFSC
GOTO
MOVLW
MOVWF
GOTO
GPIO,5
DOHT
HITM0
HITM
TOP
;check input from charger
;"inc" hi timer
;inital countdown value- hi time
;total timer
;not done- do another minute
DOHT
DECFSZ
HITM,F
;dec timer
GOTO TOP
;not done- do another minute
;****************************************************************
; *** done: charger off
//kill charger
DONE MOVLW DNPRT
;DNPRT- load done port value
MOVWF GPIO
;move to port- done
;****************************************************************
; *** hang: goto hang
//wait for a reset
HANG GOTO HANG
; end of code
;housekeeping
;********************************************************************
; VECTOR - start
; this is for 16c54 only- 12c508 starts at 0
;
ORG
1FFH
;reset vector
;
GOTO START
;
END