Searching \ for '[PIC] cycling through A/D channels' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=a%2Fd
Search entire site for: 'cycling through A/D channels'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] cycling through A/D channels'
2002\08\22@191003 by Nick Stedman

flavicon
face
Hi,
I'd like to cycle through the 8 A/D Channels on a 16f877a, read each channel
and store the results in separate variables. The channel select bits are 5-3
of the ADCON0 register. So far I've come up with:

bcf/bsf ADCON0, 3
bcf/bsf ADCON0, 4
bcf/bsf ADCON0, 5

and using a different combo of bcf/bsf for each channel. It doesn't seem
very efficient though. Am I missing something? Any help would be
appreciated.
Nick

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\08\22@192736 by Sid Weaver

picon face
In a message dated 08/22/2002 19:11:39 Eastern Daylight Time,
spam_OUTnickstedmanTakeThisOuTspamSYMPATICO.CA writes:


> and using a different combo of bcf/bsf for each channel. It doesn't seem
> very efficient though. Am I missing something? Any help would be
> appreciated.
>

Nick, I don't know any thing about asembly but I write

for x = 1 to 8
adcin, x
and so on
pause 50
next

Sid

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\08\22@194000 by Andrew Warren

flavicon
face
Nick Stedman <.....PICLISTKILLspamspam@spam@mitvma.mit.edu> wrote:

> I'd like to cycle through the 8 A/D Channels on a 16f877a, read
> each channel and store the results in separate variables. The
> channel select bits are 5-3 of the ADCON0 register. So far I've
> come up with:
>
> bcf/bsf ADCON0, 3
> bcf/bsf ADCON0, 4
> bcf/bsf ADCON0, 5
>
> and using a different combo of bcf/bsf for each channel. It
> doesn't seem very efficient though. Am I missing something? Any
> help would be appreciated.

Nick:

To increment the channel number, rolling over from 7 to 0, do this:

   COMF    ADCON0,W    ;If we're already pointing to
   ANDLW   00111000B   ;channel 7, set the Z flag.

   MOVLW   00001000B   ;Assume that we aren't at 7, so prepare
                       ;to just increment the channel number.

   SKPNZ               ;If we really aren't at 7, skip ahead.

   MOVLW   -00111000B  ;Otherwise, we are already at 7, so
                       ;prepare to add negative-7 to the
                       ;channel number in order to roll it
                       ;over to 0.

   ADDWF   ADCON0      ;Perform the addition.

To load FSR with the address of the variable that's associated with
each channel (assuming that the 8 variables are in a contiguous array
from register FIRST to register FIRST+7):

   RLF     ADCON0,W    ;Move the channel number from bits 3-5
   MOVWF   FSR         ;of ADCON0 to bits 0-2 of W.
   SWAPF   FSR,W       ;
   ANDLW   00000111B   ;

   ADDLW   FIRST       ;Add the channel number to the address of the
   MOVWF   FSR         ;FIRST register, and store the result in FSR.

To store the A/D result in the register pointed to by the FSR:

   MOVF    ADRES,W     ;Grab the A/D result.
   MOVWF   INDF        ;Store it in the register pointed to by FSR.

The standard disclaimer (i.e., this code hasn't even been assembled,
let alone tested) applies to all of the above.

-Andy

=== Andrew Warren -- aiwspamKILLspamcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\08\22@195147 by Jinx

face picon face
> and using a different combo of bcf/bsf for each channel. It doesn't
> seem very efficient though

I use macros, which at least makes the text a little easier to work with,
although I'm not cycling through them 0-7. If I was, my code would look
something like

adch0  macro
        bcf    adcon0,chs0
        bcf    adcon0,chs1
        bcf    adcon0,chs2
        endm

adch1  macro
        bsf    adcon0,chs0
        bcf    adcon0,chs1
        bcf    adcon0,chs2
        endm

adch2  macro
        bcf    adcon0,chs0
        bsf    adcon0,chs1
        bcf    adcon0,chs2
        endm

adch3  macro
        bsf    adcon0,chs0
        bsf    adcon0,chs1
        bcf    adcon0,chs2
        endm

adch4  macro
        bcf    adcon0,chs0
        bcf    adcon0,chs1
        bsf    adcon0,chs2
        endm

adch5  macro
        bsf    adcon0,chs0
        bcf    adcon0,chs1
        bsf    adcon0,chs2
        endm

adch6  macro
        bcf    adcon0,chs0
        bsf    adcon0,chs1
        bsf    adcon0,chs2
        endm

adch7  macro
        bsf    adcon0,chs0
        bsf    adcon0,chs1
        bsf    adcon0,chs2
        endm

        adch0
        acquisition delay
        bsf     adcon0,go_done ;start conversion
        nop
        nop
        call    getdata
        call    do.something.with.data

        adch1
        acquisition delay
        bsf     adcon0,go_done ;start conversion
        nop
        nop
        call    getdata
        call    do_something_with_data

etc

;--------------------------

getdata

        btfsc   adcon0,go_done
        goto    $-1
        movf    adresh,w
        movwf   hi
        bank1
        movf    adresl,w
        bank0
        movwf   lo
        return

repeated for adch2 to adch7, using fsr to store the conversion data in
RAM. If you used a bit manipulation routine to cycle through the channel
select bits I'm not sure you'd gain much. It would / might take less memory
but would possibly take longer. Depends what you call "inefficient" - time
or code space ? You could integrate the "do_something_with_data"
routine into the acquisition or conversion time, which would make the
cycling "more efficient"

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\08\22@203054 by Peter L. Peres

picon face
movlw   H'80'           ;; next channel
addwf   ADCON0,f

movlw   H'80'
subwf   ADCON0,f        ;; previous but not below 0th

movlw   H'C7'
andwf   ADCON0,f        ;; 0th

movlw   H'38'
iorwf   ADCON0,f        ;; 7th

Peter (who has not tried this since he is just starting to consider 877s).

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\08\23@012704 by Bob Ammerman

picon face
   movf    ADCON0,W    ; get current value
   addlw    B'00001000'    ; point to next channel
   andlw    B'00111000'    ; extract only channel bits
   iorwf     B'xx000101'     ; setup ADCS bits and GO bit
   movwf   ADCON0        ; start the conversion

Bob Ammerman
RAm Systems

{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...