Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hex file too big for chip

Status
Not open for further replies.
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.
 
Last edited by a moderator:
Your link gives a "404 error".
JimB
 
The link has an extra .I at the end... Its been corrected now..
Working now.

I had a quick look at the HEX file, it certainly does not appear to be all that big, about 500 words of program.

Where the problem resides I do not know, I am not that clever as a software guy!

Would it be worth contacting the author, he give an email address on the introduction page of the web site.
Maybe something has got plain old corrupted when loaded to the website.

JimB
 
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.

The projects at Mondo don't use the MicroChip assembler, they use an obscure Parallax one, you have to modify the code to get it to assemble with MicroChip.
 
I have modified the code but!!! This is weird... Nigel Goodwin have you seen it before

Code:
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
 
I have modified the code but!!! This is weird... Nigel Goodwin have you seen it before

I would imagine it's an assembler instruction, presumably to load either the upper or lower bytes of a 16 bit value - although why it's been used on only an 8 bit value I've no idea?.

If you check some of the other projects they use it with a value of 10000, which makes sense for low and high bytes.
 
Regardless, of which assembler was used, the hex file should be the same.

However, I've run into problems where a hex file wouldn't load because of the line endings. It appears that this hex file uses standard DOS/Windows CRLF line endings, and you may have to change them to a single LF.


Edit:
Try the attached file.
 

Attachments

  • POWER.hex
    3.1 KB · Views: 206
Last edited:
Hello Ian . Could I be so bold as to ask for a link to your asm file please ? The firmware is literally the only thing from preventing me,from completing this power supply.I would be eternally grateful .
 
Did you try the modified hex file that I attached?
 
I cant sim it as there are too many itterations...Plus I can't sim the encoder wheel input!!

Try it!!
Code:
;
;   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
 
That "movlw 100< " was translated to "movlw 0x0" and "movlw 100>" was "movlw 0x64" Easier to write the constants!!!

Obviously it makes no sense with only an 8 bit value, but presumably the routine is one he commonly uses with 16 bit values as well?, so it makes it easier having the assembler convert it to two bytes rather than doing it manually.
 
Bob I haven't as yet tried your hex file.It is nice to have options so I will try it ASAP and give you feedback .Many thanks to everyone who has posted help ,files and suggestions.It is very much appreciated !!!
 
No problem. I was just curious whether it fixed the problem or not.

Several months ago we developed some PIC based firmware for some industrial instrumentation, and sent the hex file to the manufacturer for them to program into the onboard PIC. They couldn't get the file to work. In examining the file, I noticed that it had CRLF line endings, and I couldn't get MPLABX to work with it either. After changing the line endings to LF, it worked fine. MPLABX produces hex files with only LF line endings, but apparently someone had opened it in a text editor and then resaved it, and the text editor had changed the line endings to CRLF. I think this could be considered to be a bug in MPLABX, because it shouldn't be so fussy about how the lines end.
 
Can someone cast an eye on the schematic for me....

benchsupply.gif



as the out put can be 0 ~ 20V Will the inputs of the opamp be okay with higher voltage than the rail??
 
Hi Ian,
The current sense op amp (Pins 5, 6, 7) will not be a problem as both inputs will be very close to ground. The voltage sense op amp (Pins 1, 2, 3) will have the output voltage scaled down by R9 and R10 1.8K/(1.8K + 10K) = 1.8/11.8 = 0.1525. So when thye output is at 20 volts the input to pin 3 of the op amp will be 20 * 0.1525 = 3.05 volts.

Les.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top