Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

EEPROM Data Assembly Code Question

Status
Not open for further replies.

ejjohnso

Newbie
Newbie level 2
Joined
Jul 1, 2021
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
23
Years ago, a friend created a charge controller for my students to build, but it always seemed buggy, and not knowing anything about Assembly Language, I was not able to troubleshoot for potential issues. So it sat for years relatively unused. This summer I decided to set out and learn the language with the hopes of finding the problem. I think I've pretty much understood everything except the last bit of code. The idea of the controller is the take 4 preset voltage values (14.7, 12.6, 12.2 and 11.6) and execute some function at each point. Essentially relays are triggered if these values are met. Can someone tell me if the following code for the EEPROM is correctly input? I have included the code in question as well as the entire code if context is needed. I've also included the schematic if, for example, voltage divider values are needed.

Thank You in Advance

Code in Question:

; EEPROM Data
EE CODE 0x2100
DE 0x48, 0x5C, 0x67, 0x93
END ; directive 'end of program'

Entire Code:
#define __12F675

include <p12f675.inc>

errorlevel -302

__CONFIG _CP_OFF & _CPD_OFF & _BODEN_ON & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT

CBLOCK 0x020

count ; blink counter
delay1 ; inner delay loop
delay2 ; outer delay loop
relaystate ; relay states (bits 4 & 5)
loadoff ; load off voltage level
chrgoff ; charge off voltage level
loadon ; current load on value
chrgon ; current charge on value
battval ; current battery level

ENDC

ORG 0x000 ; processor reset vector
GOTO MAIN ; go to beginning of program

ORG 0x004

; Main code starts here

MAIN: BCF STATUS, RP0 ; set file register bank to 0
CLRF GPIO ; turn ports off
CLRF IOC
MOVLW b'00000111'
MOVWF CMCON ; turn comparator off
MOVLW b'1000001'
MOVWF ADCON0
BSF STATUS, RP0 ; set file register bank to 1
MOVLW b'00110111' ; Int A/D, GPIO3 digital GPIO0-2 analog
MOVWF ANSEL
MOVLW b'00001111' ; GP4-5 to output GP0-3 as input MOVWF TRISIO
CLRW ; select to read loadoff from memory
CALL ReadEE ; get loadoff into W
MOVWF loadoff ; store it in RAM
MOVLW 1 ; select to read chrgoff from memory
CALL ReadEE ; get loadon into W
MOVWF loadon ; store it in RAM
MOVLW 2 ; select to read chrgoff from memory
CALL ReadEE ; get chrgon into W
MOVWF chrgon ; store it in RAM
MOVLW 3 ; select to read chrgoff from memory
CALL ReadEE ; get chrgoff into W
MOVWF chrgoff ; store it in RAM
BCF STATUS, RP0 ; select Bank 0
BTFSS GPIO, 3 ; test jumper
GOTO Normal ; start normal routine if off

; Calibration Code

MOVLW 3 ; signal user for (MinLL)
CALL Blink
pause0: BTFSC GPIO, 3 ; check jumper port
GOTO pause0 ; wait until jumper removed
CALL GetBv ; get battery voltage
MOVWF loadoff ; save it in load off
MOVLW 2 ; signal user for(MaxLL)
CALL Blink

Pause1: MOVLW b'00010000' ; turn on Load LED
MOVWF GPIO
MOVLW 10
MOVWF count

Pause2: CALL GetLo ; read A-D
MOVWF loadon ; save loadon
ANDLW b'11111110'
MOVWF battval ; save nearest even number
CALL GetBv ; read Battery Voltage
ANDLW b'11111110' ; convert to nearest even number
SUBWF battval, W ; compare
BTFSS STATUS, Z ; skip if zero (same)
GOTO Pause1 ; wait until equal
CLRW ; turn off load LED
MOVWF GPIO
MOVWF delay2
CALL Wait1 ; wait for stable V+
DECFSZ count, F
GOTO Pause2 ; go see if still equal
MOVLW 2 ; signal user for (MinCL)
CALL Blink

Pause3: MOVLW b'00100000' ; turn on Charged LED
MOVWF GPIO
MOVLW 10
MOVWF count

Pause4: CALL GetHi ; read A-D
MOVWF chrgon ; save Chargeon voltage level
ANDLW b'11111110'
MOVWF battval ; battval as nearest even number
CALL GetBv ; read Battery Voltage
ANDLW b'11111110' ; convert to nearest even number
SUBWF battval, W ; compare
BTFSS STATUS, Z ; skip if zero (same)
GOTO Pause3 ; wait until equal
CLRW ; turn off Load LED
MOVWF GPIO
MOVWF delay2
CALL Wait1 ; wait a short bit so voltage can stabilize
DECFSZ count, F
GOTO Pause4 ; go see if still equal
MOVLW 2 ; signal user for (MaxCL)
CALL Blink
MOVLW b'00110000' ; turn on both LED's
MOVWF GPIO

Pause5: BTFSS GPIO, GP3 ; check jumper port
GOTO Pause5 ; wait until jumper restored
CALL GetBv ; get battery voltage
MOVWF chrgoff ; save it
CLRW ; Signal done...
MOVWF GPIO
CALL Wait

Pause6: BTFSC GPIO, GP3 ; check jumper port
GOTO Pause6 ; wait until jumper removed
BSF STATUS, RP0 ; select Bank 1
CLRW ; clear W
MOVWF EEADR ; load address EE+0
MOVF loadoff, W ; Get loadoff value
CALL WritEE ; Save it
BSF STATUS, RP0 ; select Bank 1
MOVLW 0x03
MOVWF EEADR ; load address EE+3
MOVF chrgoff, W ; Get chargoff value
CALL WritEE ; save it
Update: BSF STATUS, RP0 ; select Bank 1
MOVLW 0x01
MOVWF EEADR ; load address EE+1
MOVF loadon, W ; Get loadon value
CALL WritEE ; save it
BSF STATUS, RP0 ; select Bank 1
MOVLW 0x02
MOVWF EEADR ; load address EE+2
MOVF chrgon, W ; Get chargon value
CALL WritEE ; save it
BCF STATUS, RP0 ; select Bank 0
MOVLW 2 ; signal user all done
CALL Blink

; Normal operation loop

Normal: CALL GetBv ; read A-D
MOVWF battval ; save battval
Htest: MOVF chrgoff, W ; get charge off value
SUBWF battval, W ; carry set if battval >= chrgoff
BTFSS STATUS, C ; charge off if battval >= chrgoff
GOTO ChgOn
ChgOff: BSF relaystate, 5 ; set to turn charge off (relay on)
GOTO Ltest
ChgOn: MOVF chrgon, W ; get charge on value
SUBWF battval, W ; carry set if battval >= chrgon
BTFSC STATUS, C ; charge on if battval < chargon
GOTO Ltest
BCF relaystate, 5 ; set to turn charge on (relay off)
Ltest: MOVF loadoff, W
SUBWF battval, W ; carry set if battval >= loadoff
BTFSC STATUS, C ; load off if battval < loadoff
GOTO LOn
LOff: BCF relaystate, 4 ; set to turn load off
GOTO SetRL
LOn: MOVF loadon, W ; get load on value
SUBWF battval, W ; carry set if battval >= loadon
BTFSS STATUS, C ; load on if battval >= loadon
GOTO SetRL
BSF relaystate, 4 ; set to turn load on
SetRL: MOVF relaystate, W ; load relay states
MOVWF GPIO ; turn relays on or off as set
SkpRL: CALL Wait ; wait a little while
CALL Wait
BTFSS GPIO, GP3 ; check jumper port for field update
GOTO Normal ; loop
CALL GetLo ; read A-D
MOVWF loadon ; save lowset
CALL GetHi ; read A-D
MOVWF chrgon ; save highset
GOTO Update ; do it again

; Subroutine to Get Lo, Hi pot settings and current Battery Voltage

; Value from low bits of Analog/Digital converter is returned in W
GetLo: MOVLW b'10000011' ; set to read channel 0 (loweset)
GOTO Getval

GetHi: MOVLW b'10000111' ; set to read channel 1 (highset)
GOTO Getval

GetBv: MOVLW b'10001011' ; set to read channel 2 (battery voltage)
Getval: BCF STATUS, RP0 ; select Bank 0
MOVWF ADCON0 ; set AD channel and GO

ADtst: BTFSC ADCON0, GO_DONE ; wait for AD to read
GOTO ADtst
BSF STATUS, RP0 ; select Bank 1
MOVF ADRESL, W
BCF STATUS, RP0 ; select Bank 0
RETURN

; Subroutine to pause for a short time

Wait: MOVLW d'255' ; set outer delay
MOVWF delay2
Wait1: MOVLW d'255' ; set inner delay
MOVWF delay1

Wait2: DECFSZ delay1, F
GOTO Wait2 ; loop through inner
DECFSZ delay2, F
GOTO Wait1 ; loop through outer

RETURN ; return

; Subroutine to blink both LED's a number of times set in W

Blink: MOVWF count ; store how many times to blink

Blink1: MOVLW b'00000000' ; all LED off
MOVWF GPIO
CALL Wait ; pause for effect
MOVLW b'00110000' ; all LED on
MOVWF GPIO
CALL Wait ; pause for effect
MOVLW b'00000000' ; all LED off again
MOVWF GPIO
DECFSZ count, F ; quit if blink count zero
GOTO Blink1 ; keep blinking

RETURN

; Subroutine to read data from EEPROM at address in W,
; Data is returned in W

ReadEE: BSF STATUS, RP0 ; select Bank 1
MOVWF EEADR ; address to read
BSF EECON1, RD ; EE read
MOVF EEDATA, W ; move data to W
BCF STATUS, RP0 ; select Bank 0

RETURN

; Subroutine to write data to EEPROM at address in W,

; Address to be written is located in EEADR

WritEE: MOVWF EEDATA ; move W to eeprom
BSF STATUS, RP0 ; select bank 1
BSF EECON1, WREN ; enable write
BCF INTCON, GIE ; disable interrupts
MOVLW 055h ; unlock write
MOVWF EECON2 ; required code
MOVLW 0AAh ; required code
MOVWF EECON2 ; required code
BSF EECON1, WR ; start the write
BSF INTCON, GIE ; Enable interrupts
BCF EECON1, WREN ; Disable write
CALL Wait ; Be sure write is complete

RETURN

; EEPROM Data

EE CODE 0x2100

DE 0x48, 0x5C, 0x67, 0x93

END ; directive 'end of program'
 

Attachments

  • Charge Controller Schematic.pdf
    211.2 KB · Views: 104

The lines you ask about is just a table in EEPROM with 4 entries.
It is probably the voltage limits, and data in EEPROM can be changed without reprogramming the software.

Some obvious problem in the schematic:
The Zener diode and the capacitor in parallel with the 5.6k resistor seem to be reversed, and no voltage specified for the diode.
There are no freewheeling diodes across the relay coil connections.
 

The lines you ask about is just a table in EEPROM with 4 entries.
It is probably the voltage limits, and data in EEPROM can be changed without reprogramming the software.

Some obvious problem in the schematic:
The Zener diode and the capacitor in parallel with the 5.6k resistor seem to be reversed, and no voltage specified for the diode.
There are no freewheeling diodes across the relay coil connections.
Thank you... I will make these changes and hopefully see a cleaner working controller.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top