Working now.The link has an extra .I at the end... Its been corrected now..
Has anyone had any problems,in burning the hex file used in this circuit for a power supply. The website is http://www.mondo-technology.com/Bench.html .I have tried to compile the source code and object code,both arrive at the same error .Hex file too large for pic chip used. Unless I am genuinely using a pic with insufficient memory. Software used is mplab ide latest version. Any ideas on how to optimise the code or last resort is using a bigger pic with more memory.
dexi movwf FSR ;place to put data
bcf NZ
movlw 100< ;<-- this
movwf thi
movlw 100>
movwf tlow
call digit
movlw 10<
movwf thi
movlw 10>
movwf tlow
call digit
movlw 1<
movwf thi
movlw 1>
movwf tlow
call digit
return
There is a link to a zip file on his introduction page; http://www.mondo-technology.com/index.htmlthey use an obscure Parallax one.
I have modified the code but!!! This is weird... Nigel Goodwin have you seen it before
;
; Software regulated bench power supply
;
; Full PID implementation of voltage regulation
;
LIST P=PIC16F870
include "P16F870.inc"
__config h'3f72'
#define SRDAT PORTC,1
#define SRCLK PORTC,3
#define LEDON PORTC,7
cblock 0x20
butime1
butime2
func
vsave
_data
temp
temp1
count
pwidth
lpcnt
lpxnt
offcnt
slowf
_hi
_low
zhi
zlow
thi
tlow
adjhi
adjlo
vhi
vlo
lasthi
lastlo
alo
ahi
amax
pwmhi
pwmlo
vset
xvset
shaft
del0
del1
clean
seqnr
vsegs1
vsegs2
vsegs3
asegs1
asegs2
asegs3
flag1
flag
endc
#define NZ flag,0
#define OKBUT flag,1 ;ok for next button
#define BHIT flag,2 ;button is hit
#define DOWDT flag,3 ;enable watchdog in delay loop
#define BUTON flag,4 ;button state
#define BHELD flag,5 ;button held down
#define RINC flag1,0 ;rotor increment
#define RDEC flag1,1 ;rotor decrement
org 0
goto start
org 4
reti
drvseg addwf PCL
dt 90h,0A0h,0B0h,0D0h,0E0h,0F0h
digseg addwf PCL
dt 3fh,6h,5bh,4fh,66h,6dh,7dh,7h,7fh,67h
funcs addwf PCL
dt 77h,38h,6 ;ALI
start clrf STATUS
movlw 0Ch ;set pwm mode
movwf CCP1CON
bsf STATUS,5
movlw 11111b ;set for analog inputs
movwf TRISA
movlw 7
movwf TRISB
movlw 0
movwf TRISC
movlw 255
movwf PR2 ;set pwm period
movlw 80h ;right justify 5 analog input channels
movwf ADCON1
bcf STATUS,5
movlw 4
movwf T2CON
clrf pwmlo
clrf pwmhi
clrf lasthi
clrf lastlo
clrf alo
clrf ahi
clrf seqnr
clrf _data
clrf vset
movlw 200
movwf amax
movf PORTB,w
movwf shaft
cycle clrwdt
call getvlt ;read the voltage
call efac2 ;get the proportional error
call clamp ;limit amount
call newpwm ;+/- to power
call diffi ;get the differencial error
call newpwm ;adjust power
call chekov ;check limits
call slowp ;do the integral
call setpwm ;send to the hardware
decfsz lpcnt
goto cycle
movlw 20
movwf lpcnt
call readsi ;read the input
call nxtdsp
call dispv
call calcv
call onoff
call getamp ;read amps
decfsz lpxnt
goto cycle
movlw 200
movwf lpxnt
call dispa ;display amps
goto cycle
onoff btfsc BUTON
goto byp
movf alo,w
movwf _low
movf ahi,w
movwf _hi
rrf _hi
rrf _low
movf amax,w
subwf _low,w
btfsc STATUS,C
goto off ;power off.
byp call button
btfss BHIT
return
bcf BHIT
off clrf _hi
clrf _low
call dopwm ;power off
wait clrwdt
call button
btfss BHIT
goto cont
bcf BHIT
movf PORTB,w
movwf shaft
return
cont movlw 50
call delay1
clrf vsegs1
clrf vsegs2
clrf vsegs3
clrf asegs1
clrf asegs2
clrf asegs3
bsf asegs3,7
call nxtdsp
call chkset
goto wait
button btfss PORTB,0 ;read switch
goto but ;button down - toggle state
bcf BUTON
bcf BHELD
bcf BHIT
movlw 2
movwf butime2
clrf butime1
decfsz offcnt
return
bsf OKBUT
return
but movlw 50
movwf offcnt
decfsz butime1
goto ok
decfsz butime2
goto ok
bsf BHELD
ok bsf BUTON
btfss OKBUT
return
bcf OKBUT
bsf BHIT ;button hit valid
return
chkset btfss BHELD ;check button state
return
bcf BHELD
clrf func
wait2 clrwdt
call button
btfsc BHELD
goto back
call showf
call setmax
movf amax,w
movwf _low
clrf _hi
bcf STATUS,C
rlf _low
rlf _hi
movlw asegs1
call dexi
bsf asegs1,7
call nxtdsp
bcf BHIT
movlw 50
call delay1
goto wait2
back bcf BHELD
return
showf movf func,w
addwf func,w
addwf func,w ;func x 3
movwf temp
call funcs
movwf vsegs1
incf temp
movf temp,w
call funcs
movwf vsegs2
incf temp
movf temp,w
call funcs
movwf vsegs3
return
; read shaft encoder
readsi call rotor
btfsc RINC
goto more
btfsc RDEC
goto less
ret
less movf vset ;set z flag
btfsc STATUS,Z
goto done
decf vset
goto done
more incf vset
movf vset,w
xorlw 201
btfss STATUS,Z
goto done
decf vset
done return
setmax call rotor
btfsc RINC
goto more1
btfsc RDEC
goto less1
return
less1 movf amax
btfsc STATUS,Z
return
decf amax
return
more1 incf amax
movf amax,w
xorlw 251
btfss STATUS,Z
return
decf amax
return
rotor bcf RINC
bcf RDEC
movf PORTB,w ;get quad bits
movwf temp
movwf _data
xorwf shaft,w
andlw 6 ;isolate bits
btfsc STATUS,Z ;match?
return ;yes - return z-set
movf shaft,w
rlf temp
xorwf temp
btfsc temp,2
goto up
down decf xvset
goto ok2
up incf xvset
ok2 btfss _data,1
goto skip2
btfss _data,2 ;both bits low ?
goto skip2 ;no.
movf xvset,w
xorlw 4
btfsc STATUS,Z
goto more2
movf xvset,w
xorlw -4
btfsc STATUS,Z
goto less2
goto done2
less2 bsf RDEC
goto done2
more2 bsf RINC
done2 clrf xvset
skip2 movf _data,w
movwf shaft
return
calcv movf vset,w
movwf _low
movlw 73
call mult
rrf _hi
rrf _low
rrf _hi
rrf _low
rrf _hi
rrf _low
rrf _hi
rrf _low
movf _low,w
movwf adjlo
movf _hi,w
andlw 3
movwf adjhi
return
slowp decfsz slowf ;get timeing factor
return
movlw 20
movwf slowf
movf vhi,w
subwf adjhi,w
btfsc STATUS,Z
goto chklo
chk1 btfss STATUS,C
goto dn
incf pwmlo
btfsc STATUS,Z
incf pwmhi
return
dn decf pwmlo
movf pwmlo,w
xorlw 0ffh
btfsc STATUS,Z
decf pwmhi
movf pwmlo,w
xorlw 0ffh
btfss STATUS,Z
return
clrf pwmlo
clrf pwmhi
return
chklo movf vlo,w
subwf adjlo,w
btfss STATUS,Z ;exact match?
goto chk1
return ;no - action.
diffi clrf _hi
movf vlo,w
subwf lastlo,w ;find last reading
movwf _low
btfss STATUS,C
decf _hi
movf vhi,w
subwf lasthi,w
addwf _hi
movf vlo,w
movwf lastlo
movf vhi,w
movwf lasthi
return
; get error factor in hi/low
efac1 clrf _hi
movf vlo,w
subwf adjlo,w
movwf _low
btfss STATUS,C
decf _hi
movf vhi,w
subwf adjhi,w
addwf _hi
return
efac2 call efac1
btfsc _hi,7 ;negative value?
goto neg
bcf STATUS,C
rrf _hi
rrf _low
bcf STATUS,C
rrf _hi
rrf _low
return
neg rrf _hi
rrf _low
bsf _hi,7
rrf _hi
rrf _low
bsf _hi,7
return
clamp btfsc _hi,7
return ;only process positive corrections
movf _hi,w
btfss STATUS,Z
goto max2
movf _low,w
sublw 10
btfss STATUS,C
goto max2
return
max2 movlw 10
movwf _low
clrf _hi
return
; adjust new PWM value using hi/low
newpwm movf _low,w
addwf pwmlo
btfsc STATUS,C
incf pwmhi
movf _hi,w
addwf pwmhi
return
; check PWM value for in range 0 to 3ff.
chekov btfsc pwmhi,7 ;underflow?
goto min2
movf pwmhi,w
andlw 0FCh ;overflow?
btfsc STATUS,Z
return ;no - in range
movlw 3
movwf pwmhi
movlw 0FFh
movwf pwmlo
return
min2 clrf pwmhi
clrf pwmlo
return
; sets 10 bit pwm value in CCP1CON<5,4>/CCPR1L<7-0>
setpwm movf pwmlo,w
movwf _low
movf pwmhi,w
movwf _hi
dopwm movf _low,w
movwf temp
swapf temp
movf temp,w
andlw 30h
iorlw 0Ch ;set for pwm mode
movwf CCP1CON
rrf _hi
rrf _low
rrf _hi
rrf _low ;hi 8 bits
movf _low,w
movwf CCPR1L
return
; multiply w by low into low/hi
mult movwf temp
movlw 8
movwf count
movf _low,w
movwf temp1
clrf _low
clrf _hi
movf temp,w
bcf STATUS,C
loop2 rrf temp1
btfsc STATUS,C
addwf _hi
rrf _hi
rrf _low
decfsz count
goto loop2
return
getvlt movlw 0
call atod
movf _low,w
movwf vlo
movf _hi,w
movwf vhi
return
getamp movlw 1
call atod
movf _low,w
movwf alo
movf _hi,w
movwf ahi
return
dispv movf vset,w
movwf _low
clrf _hi
movlw vsegs1
call dexi
bsf vsegs2,7
return
dispa movf alo,w
movwf _low
movf ahi,w
movwf _hi
movlw asegs1
call dexi
bsf asegs1,7
return
; decimal values up to 1000 converted directly into
; segment values
dexi movwf FSR ;place to put data
bcf NZ
movlw 0x0
movwf thi
movlw 0x64
movwf tlow
call digit
movlw 0x0
movwf thi
movlw 0xA
movwf tlow
call digit
movlw 0x0
movwf thi
movlw 0x1
movwf tlow
call digit
return
digit clrf count
dig1 call dsub
btfsc _hi,7
goto dig2
bsf NZ
incf count
goto dig1
dig2 call dadd
movf count,w
sublw 9
btfss STATUS,C
goto err2
movf count,w
call digseg ;get segment data
done4 movwf 0 ;store.
incf FSR
return
err2 movlw 49h
goto done4
dsub movf tlow,w
subwf _low
btfss STATUS,C
decf _hi
movf thi,w
subwf _hi
return
dadd movf tlow,w
addwf _low
btfsc STATUS,C
incf _hi
movf thi,w
addwf _hi
return
nxtdsp incf seqnr
movf seqnr,w
xorlw 6 ;past end of list?
btfss STATUS,Z
goto ok3
clrf seqnr
ok3 bcf LEDON ;disable all displays
movf seqnr,w
addlw vsegs1 ;base of segment data
movwf FSR
movf 0,w ;get segment data
movwf temp
movlw 8
movwf count
shft bcf SRDAT
btfss temp,7 ;hi order first
bsf SRDAT ;reverse sense
bsf SRCLK
bcf SRCLK ;shift it out
rlf temp
decfsz count
goto shft
movf seqnr,w
call drvseg
movwf temp
movf PORTC,w
andlw 0Fh
iorwf temp,w
movwf PORTC ;select new digit
return
; read atod channel set by 'w'
; result in hi/low
atod movwf temp ;get channel (0-4)
bcf STATUS,C
rlf temp
rlf temp
rlf temp ;put in place
movlw 81h ;/32 clock, power up
iorwf temp,w
movwf ADCON0
movlw 2
call delay
bsf ADCON0,2
nop
nop
chk3 btfsc ADCON0,2 ;check for conversion complete
goto chk3
bsf STATUS,5
movf ADRESL,w
bcf STATUS,5
movwf _low
movf ADRESH,w
movwf _hi
return
delay1 bsf DOWDT
delay movwf del1
d1 movwf del0
d2 btfsc DOWDT
clrwdt
decfsz del0
goto d2
decfsz del1
goto d1
bcf DOWDT
return
end
I have the original hex.... And I've disassembled it!!! so I have a working asm file
That "movlw 100< " was translated to "movlw 0x0" and "movlw 100>" was "movlw 0x64" Easier to write the constants!!!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?