EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

adc program pic12f675 modified

Started by vaishnavi236 February 27, 2004
hello,
keeping in mind all the suggestions i have modified the pgm for
adc...but
still the loop remains infinite .....i am not able to trace the
problem even now .....please check this program and send me ur
suggestions.....in one of the websites it was mentioned that
comparator should b disabled for adc conversion ....so cmcon is
equalised to 07h page35 in data sheets when all 3 digital i/ps o/p is
off.
i saw the adrech n adresl they r still zero
list pf675 ; list directive to define
processor
#include <p12f675.inc> ; processor specific variable
definitions

errorlevel -302 ; suppress message 302 from
list file

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

;***** 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
gpio equ 05h
pir1 equ 0ch
adresh equ 1eh
adcon0 equ 1fh
trisio equ 85h
adresl equ 9eh
ansel equ 9fh
cmcon equ 19h
status equ 03h

clrf gpio ; initializes gpio
movlw 07h ; comparator to be disabled
movwf cmcon ;all three r digital means o/p off
movlw 0fh ; 0f001111 so pin7 is selected
movwf trisio ; since bit3 is always 1
bsf adcon0,1 ;go/done is set to start
adc movlw 07h ;bit3-0 ans3:ans0 & GP0 i.e pin7
movwf ansel ;1=analog i/p &0= digital
bsf adcon0,0 ; adon=1 a/d is operating
bsf adcon0,7 ; adfm=1 a/d o/p is rght
justified
btfsc adcon0, 1 ; tests if go/done is
cleared if yes then skips next ins.
goto adc ; else if it is still
set then continues to loop
bcf pir1,6 ; adif flag is cleared
since it is set after the adc
; initialize eeprom locations

ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03 END ; directive 'end of program'




--- vaishnavi236 <> wrote:
> hello,
> keeping in mind all the suggestions i have modified the pgm for
>
> adc...but
> still the loop remains infinite .....i am not able to trace the
> problem even now .....please check this program and send me ur
> suggestions.....in one of the websites it was mentioned that
> comparator should b disabled for adc conversion ....so cmcon is
> equalised to 07h page35 in data sheets when all 3 digital i/ps o/p is
>
> off.
> i saw the adrech n adresl they r still zero
> list pf675 ; list directive to define
> processor
> #include <p12f675.inc> ; processor specific variable
> definitions
>
> errorlevel -302 ; suppress message 302 from
> list file
>
> __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF &
> _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
>
> ;***** 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

All these are set in your include file already. :-) You do not have to
define them.

> gpio equ 05h
> pir1 equ 0ch
> adresh equ 1eh
> adcon0 equ 1fh
> trisio equ 85h
> adresl equ 9eh
> ansel equ 9fh
> cmcon equ 19h
> status equ 03h
>
> clrf gpio ; initializes gpio
> movlw 07h ; comparator to be disabled

cmcon and trisio are in bank 1. Add:
bsf STATUS, RP0

> movwf cmcon ;all three r digital means o/p off
> movlw 0fh ; 0f001111 so pin7 is selected
> movwf trisio ; since bit3 is always 1

Return to bank 0 with:
bcf STATUS, RP0

> bsf adcon0,1 ;go/done is set to start

Setting bit 1 of adcon0 starts the AtoD conversion. This is the last
thing you want to do after everything is set up.

> adc movlw 07h ;bit3-0 ans3:ans0 & GP0 i.e
> pin7

each loop you are messing with the AtoD. Not good idea.

> movwf ansel ;1=analog i/p &0= digital

ansel is bank 1 again move it to bank 1 instrructions

> bsf adcon0,0 ; adon=1 a/d is operating
> bsf adcon0,7 ; adfm=1 a/d o/p is rght
> justified
> btfsc adcon0, 1 ; tests if go/done is
> cleared if yes then skips next ins.
> goto adc ; else if it is still
> set then continues to loop
only jump to the btfsc adcon0,1 instruction. $ = current program
counter. $-1 = current program counter - 1.
> bcf pir1,6 ; adif flag is cleared
> since it is set after the adc


Try something like this sequence:

clrf gpio ; initializes gpio
bsf STATUS, RP0
movlw 07h ; comparator to be disabled
movwf cmcon ;all three r digital means o/p off
movwf ansel ;1=analog i/p &0= digital
movlw 0fh ; 0f001111 so pin7 is selected
movwf trisio ; since bit3 is always 1
bcf STATUS, RP0
movlw 81h ; ensure that all of adcon0 is correct
movwf adcon0 ; adon=1 a/d is operating
bsf adcon0, 1
btfsc adcon0, 1 ; tests if go/done is cleared if
yes then skips next ins.
goto $-1 ; else if it is still set then
continues to loop

This may not be all the problems, but a start. =====
My software has no bugs. Only undocumented features.

__________________________________




At 11:08 AM 2/27/2004, Chad Russel wrote:

>cmcon and trisio are in bank 1. Add:
> bsf STATUS, RP0

Sorry, Chad - you gave wrong information. CMCON is in bank 0.

In other words, move the 'bsf STATUS, RP0' line to after the write to CMCON.

dwayne

--
Dwayne Reid <>
Trinity Electronics Systems Ltd Edmonton, AB, CANADA
(780) 489-3199 voice (780) 487-6397 fax

Celebrating 20 years of Engineering Innovation (1984 - 2004)
.-. .-. .-. .-. .-. .-. .-. .-. .-. .-
`-' `-' `-' `-' `-' `-' `-' `-' `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.



Don't be sorry, I'm sorry. I did not run a simulation, just typed
wrong or misread the data sheet. Thanks.

--- Dwayne Reid <> wrote:
> At 11:08 AM 2/27/2004, Chad Russel wrote:
>
> >cmcon and trisio are in bank 1. Add:
> > bsf STATUS, RP0
>
> Sorry, Chad - you gave wrong information. CMCON is in bank 0.
>
> In other words, move the 'bsf STATUS, RP0' line to after the write
> to CMCON.
>
> dwayne
>
> --
> Dwayne Reid <>
> Trinity Electronics Systems Ltd Edmonton, AB, CANADA
> (780) 489-3199 voice (780) 487-6397 fax
>
> Celebrating 20 years of Engineering Innovation (1984 - 2004)
> .-. .-. .-. .-. .-. .-. .-. .-. .-. .-
> `-' `-' `-' `-' `-' `-' `-' `-' `-'
> Do NOT send unsolicited commercial email to this email address.
> This message neither grants consent to receive unsolicited
> commercial email nor is intended to solicit commercial email.


=====
My software has no bugs. Only undocumented features.

__________________________________




The 2024 Embedded Online Conference