hi, i have written a program for adc. i am going to feed the a/d samples to the timer for the pwm module which is next... my project is " MICROCONTROLLER BASED PWM FOR SOLAR PHOTO VOLTAIC POWER SYSTEM. THE PROGRAM written below is simulated using MPLAB 6.13 version. building is suceeded .....but problem is it gets into an infinite loop 'ADC' in the last part....i am not able to trace the problem especially in the last...i have set go/done bit and checked if it is cleared at the end of adc conversion.. if yes it skips goto adc statement.....if no it continues to go to loop. i have another two modules to do ...by the end of this month ..pleaase help me.. list pf675 ; list directive to define processor #include <p12f675.inc> ; processor specificvariabledefinitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ;***** VARIABLE DEFINITIONS w_temp EQU 0x20 ; variable used for context saving status_temp EQU 0x21 ; variable used for context saving ;********************************************************************* * ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt ; remaining code goes here cmcon equ 19h gpio equ 05h status equ 03h trisio equ 85h adcon0 equ 1fh ansel equ 9Fh adresl equ 9Eh adresh equ 1Eh pir1 equ 0Ch bcf status,5 clrf gpio movlw 07h movwf cmcon bsf status,5 movlw 60h movwf trisio bcf status,5 movlw 3Fh movwf gpio bsf ansel,6 bsf ansel,5 bsf ansel,4 bsf adcon0,7 ADC bsf adcon0,1 btfsc adcon0,1 goto ADC bcf pir1,6 ; initialize eeprom locations ORG 0x2100 DE 0x00, 0x01, 0x02, 0x03 END ; directive 'end of program' |
|
please help me with adc program for pic12f675 using mplab
Started by ●February 26, 2004
Reply by ●February 26, 20042004-02-26
> THE PROGRAM written below is simulated using MPLAB 6.13 version. > building is suceeded .....but problem is it gets into an infinite I assume "building is suceeded" means is assembled OK. The code as presented here will not assemble error free. The main label is missing. Other comment notes below..... When you run the simulation open the File Register window to see the results of register operations. > > list pf675 ; list directive to define processor > #include <p12f675.inc> ; processor specificvariabledefinitions > > errorlevel -302 ; suppress message 302 from list file > > __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & > _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT > > ; '__CONFIG' directive is used to embed configuration word > within .asm file. > ; The lables following the directive are located in the > respective .inc file. > ; See data sheet for additional information on configuration word > settings. > > > ;***** VARIABLE DEFINITIONS > w_temp EQU 0x20 ; variable used for context saving > status_temp EQU 0x21 ; variable used for context saving > ;******************************************************************* ** > * > ORG 0x000 ; processor reset vector > goto main ; go to beginning of program > ORG 0x004 ; interrupt vector location ;*** start here ******* > movwf w_temp ; save off current W > register contents > movf STATUS,w ; move status register into > W register > movwf status_temp ; save off contents of > STATUS register > ; isr code can go here or be located as a call subroutine elsewhere > movf status_temp,w ; retrieve copy of STATUS > register > movwf STATUS ; restore pre-isr STATUS > register contents > swapf w_temp,f > swapf w_temp,w ; restore pre-isr W > register contents ;*** end here ***** ; What does the above code do? Is it needed? > retfie ; return from interrupt > > > ; remaining code goes here ;*** start here *** > cmcon equ 19h > gpio equ 05h > status equ 03h > trisio equ 85h > adcon0 equ 1fh > ansel equ 9Fh > adresl equ 9Eh > adresh equ 1Eh > pir1 equ 0Ch ;*** end here **** ; really do not need to have this code section. Why? > > > bcf status,5 > clrf gpio > movlw 07h > movwf cmcon > bsf status,5 > movlw 60h ; cannot put 0x60 into TRISIO > movwf trisio ; need to set TRISIO for input on pins ; to be used as analog inputs. This code ; does not do it. > bcf status,5 > movlw 3Fh > movwf gpio ; Why do this? ;*** start here *** > bsf ansel,6 ; sets ADC clock source to FRC > bsf ansel,5 ; the internal 4MHz system clock > bsf ansel,4 ; is selected above in _CONFIG ; read Table 7-1 notes for why ; this code is wrong ;*** end here *** > bsf adcon0,7 > ADC bsf adcon0,1 ; the ADC has not been turned on yet > btfsc adcon0,1 ; so the bit will never be cleared > goto ADC > bcf pir1,6 > ;*** start here *** > ; initialize eeprom locations > > ORG 0x2100 > DE 0x00, 0x01, 0x02, 0x03 ;*** end here *** ;What is this code for? > > > END ; directive 'end of program' |
|
Reply by ●February 26, 20042004-02-26
Pat, why are you using an ISR for the ADC? Bala --- In , "Patrick Reitelbach" <preitelbach@y...> wrote: > > THE PROGRAM written below is simulated using MPLAB 6.13 version. > > building is suceeded .....but problem is it gets into an infinite > > I assume "building is suceeded" means is assembled OK. The code as > presented here will not assemble error free. The main label is > missing. > > Other comment notes below..... > > When you run the simulation open the File Register window to see the > results of register operations. > > > > > list pf675 ; list directive to define processor > > #include <p12f675.inc> ; processor > specificvariabledefinitions > > > > errorlevel -302 ; suppress message 302 from list file > > > > __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & > > _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT > > > > ; '__CONFIG' directive is used to embed configuration word > > within .asm file. > > ; The lables following the directive are located in the > > respective .inc file. > > ; See data sheet for additional information on configuration word > > settings. > > > > > > > > > > ;***** VARIABLE DEFINITIONS > > w_temp EQU 0x20 ; variable used for context > saving > > status_temp EQU 0x21 ; variable used for context saving > > > > > > > > > > > > ;******************************************************************* > ** > > * > > ORG 0x000 ; processor reset vector > > goto main ; go to beginning of program > > > > > > ORG 0x004 ; interrupt vector location > > ;*** start here ******* > > movwf w_temp ; save off current W > > register contents > > movf STATUS,w ; move status register into > > W register > > movwf status_temp ; save off contents of > > STATUS register > > > > > > ; isr code can go here or be located as a call subroutine elsewhere > > > > > > movf status_temp,w ; retrieve copy of STATUS > > register > > movwf STATUS ; restore pre-isr STATUS > > register contents > > swapf w_temp,f > > swapf w_temp,w ; restore pre-isr W > > register contents > ;*** end here ***** > ; What does the above code do? Is it needed? > > > retfie ; return from interrupt > > > > > > > > > > ; remaining code goes here > > ;*** start here *** > > cmcon equ 19h > > gpio equ 05h > > status equ 03h > > trisio equ 85h > > adcon0 equ 1fh > > ansel equ 9Fh > > adresl equ 9Eh > > adresh equ 1Eh > > pir1 equ 0Ch > ;*** end here **** > ; really do not need to have this code section. Why? > > > > > > > bcf status,5 > > clrf gpio > > movlw 07h > > movwf cmcon > > bsf status,5 > > > movlw 60h ; cannot put 0x60 into TRISIO > > movwf trisio ; need to set TRISIO for input on pins > ; to be used as analog inputs. This code > ; does not do it. > > > bcf status,5 > > > movlw 3Fh > > movwf gpio ; Why do this? > > ;*** start here *** > > bsf ansel,6 ; sets ADC clock source to FRC > > bsf ansel,5 ; the internal 4MHz system clock > > bsf ansel,4 ; is selected above in _CONFIG > ; read Table 7-1 notes for why > ; this code is wrong > ;*** end here *** > > > bsf adcon0,7 > > ADC bsf adcon0,1 ; the ADC has not been turned on yet > > btfsc adcon0,1 ; so the bit will never be cleared > > goto ADC > > bcf pir1,6 > > > > ;*** start here *** > > ; initialize eeprom locations > > > > ORG 0x2100 > > DE 0x00, 0x01, 0x02, 0x03 > ;*** end here *** > ;What is this code for? > > > > > > > END ; directive 'end of program' |
Reply by ●February 26, 20042004-02-26
I have to assume some of the program is missing. The other problem you will find is that in your status checking loop, you jump back 2 intructions to bsf ADCON0,1. This will restart the AtoD each time. Better to jump $-1. I have a 12F675 program using AtoD if you need. Chad --- Patrick Reitelbach <> wrote: > > THE PROGRAM written below is simulated using MPLAB 6.13 > version. > > building is suceeded .....but problem is it gets into an infinite > > I assume "building is suceeded" means is assembled OK. The code as > presented here will not assemble error free. The main label is > missing. > > Other comment notes below..... <<< snip >> ===== My software has no bugs. Only undocumented features. __________________________________ |
|
Reply by ●February 27, 20042004-02-27
--- In , Chad Russel <chadrussel@y...> wrote: > I have to assume some of the program is missing. The other problem you > will find is that in your status checking loop, you jump back 2 > intructions to bsf ADCON0,1. This will restart the AtoD each time. > Better to jump $-1. > > I have a 12F675 program using AtoD if you need. > > Chad > > --- Patrick Reitelbach <preitelbach@y...> wrote: > > > THE PROGRAM written below is simulated using MPLAB 6.13 > > version. > > > building is suceeded .....but problem is it gets into an infinite > > > > I assume "building is suceeded" means is assembled OK. The code as > > presented here will not assemble error free. The main label is > > missing. > > > > Other comment notes below..... > <<< snip >> > ===== > My software has no bugs. Only undocumented features. > > __________________________________ > |