Using two AtoD channels - they're interacting?!


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default Using two AtoD channels - they're interacting?!

    Have you ever had one of those evenings where everything falls to pieces? Having used AtoD without issue for quite a while, my 12F683 is laughing at me....and now I'm not sure what I know & what I don't know wrt AtoDing!

    Previously, in my newbie ignorance (bliss?), when wanting to use more than one AtoD channel, I was simply doing this (on a 16f690)...

    Code:
    ADCIN 1, intensity
    pause 2                                                                                '
    ADCIN 3, Signal_In
    never had a problem - my AtoD (Seemingly) worked!

    Ok, now I've moved to a smaller (simpler?!) PIC - a 12f683. It's kicking my backside - two nights wasted on the seemingly very simple task of getting two AtoD channels to work correctly.

    Firstly, can I get a really basic question out of the way? (you have to promise not to laugh!)

    when moving between AtoD channels, should I be setting the ADCON register *every* time? (the PICBasic compiler suggests so, so I guess the answer is yes!)

    ie, should I actually be doing this...

    Code:
        ADCON0 = %10000111 ' select AN1
        pause 50 'wait a bit
        ADCIN 1, intensity ' 'ok, let's Ato D.
         pause 50 'wait a bit
        ADCON0 = %10001111 'now move on to a different AtoD channel - AN3
        pause 50  ' let things settle
        ADCIN 3,Signal_In
    in other word, using the ADCCON0 register to move between the different Analogue Channels?

    If so, then how the hell was I getting away with it on my 16f690?

    ok, now to my (latest) immediate problem - if I apply a variable DC level to say AN1 (just for testing to observe the results), moving the test voltage level up/down also affects the AN3 AtoD reading (& vice versa) - eh?

    Now I know you have to wait sufficient time to let things settle when moving between channels, but I'm already pausing a good while before AtoD'ing the next channel - what's going on?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Have a look at some of the MeLabs examples for the LAB-X4 board & 12F683 A/D.
    http://melabs.com/resources/samples.htm#x4pbp

    I'll bet between these and the data sheet you'll see what the difference is..;o)
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Thanks for taking the time to reply.

    I had a look, here's what I found...

    Code:
    ' ADCIN1X4.BAS
    '  For PIC12F683 and melabs PICBASIC PRO Compiler
    '
    ' Display result of 10-bit A/D conversion on LCD
    
    Include "modedefs.bas"		' Mode definitions for Serout
    
    ' Define ADCIN parameters
    Define	ADC_BITS	10	' Set number of bits in result
    Define	ADC_CLOCK	3	' Set clock source (3=rc)
    Define	ADC_SAMPLEUS	50	' Set sampling time in uS
    
    
    LCD	Var	GPIO.1		' LCD TX pin
    
    adval	Var	Word		' Create adval to store result
    
    
    	ADCON0.7 = 1		' Right justify result
    	ANSEL = %00111000	' Set AN3 analog, rest digital
    	CMCON0 = 7		' Analog comparators off
    
    	Pause 500		' Wait .5 second for LCD to init
    
    mainloop:	ADCIN 3, adval		' Read channel 3 to adval
    
    	Serout LCD, T2400, [$fe, 1]	' Clear screen
    	Serout LCD, T2400, ["Value: ", #adval]	' Display the decimal value  
    
    	Pause 100		' Wait .1 second
    
    	Goto mainloop		' Do it forever
    
    	End
    Unfortunately, that example only uses one channel.

    Pretty much after I posted, I sorted my problem (how does that always work then?!).

    Two things were the root of my issue...

    1. I'm using a sig gen, rectifying a sine wave from it & feeding into & low pass filter (the resulting extracted DC level feeds into one AtoD channel) ....I was getting over zealous with the sig gen output amplitude - and the rectified DC level breached 5V - which sends the PICs AtoD results a bit whacky (which is hardly surprising) ...one channels starts seriously impacting the sample from a totally different channel! So Hank makes amental note - be careful with the input voltage magnitude fed into an AtoD pin!

    2. The other problem was that I wasn't allowing sufficient time between using successive AtoD channels - I'm finding that in my setup, it needs at least 30ms between successive AtoD channels 'samples' - hey ho.

  4. #4
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HankMcSpank View Post
    I'm finding that in my setup, it needs at least 30ms between successive AtoD channels 'samples' - hey ho.
    This is the case with every PIC, and for each and every a/d reading. It is called the "charge time" for the sampling capacitor, and is most often the bottleneck for sampling rates. (Some PICs charge it faster.) With a single channel it is often not noticed because the sampling cap is charged while doing other things, or because you get an "old" reading from the same channel.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts