I am confuse


Closed Thread
Results 1 to 20 of 20

Thread: I am confuse

Hybrid View

  1. #1
    Join Date
    Aug 2009
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    Well, first I did was to change the out pin to the LCD (Sorry I was using RA6 not RA5) to PortB.1 as for the test only. Second, I changed ADC to 8 bits and it went to zero but refuse to read any change voltage so I set it to back to 10. I wonder how can I set the AD comparators off using ADCON0. I read the 16F88 spec sheet page 114 and I don’t find a way to turn those comparators off. Please advice.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I picked up the below method of reading the ADC here
    http://www.rentron.com/PICX2.htm
    I like it much better than ADCIN.

    The below code is an example for reading ADC channel 0. Look at the example on the above link to add other channels.

    It looks like a lot of stuff to do to read the ADC, pretty much what ADCIN does behind the scenes. This way you have control.
    The "READ_AD" part is only needed once no matter how many channels you are reading (reusable).

    Use your LCD or SERIAL to see what is happening. I have this running at 2400 baud. Works OK with the internal OSC for testing.

    Code:
    [color=#000000]    '16F88 ADC TEST  FOR CHANNEL 0
        DEFINE OSC 4           
        OSCCON = %01100000
        @ __config _CONFIG1, _INTRC_IO & _WDT_OFF & _LVP_OFF & _MCLR_OFF &_CP_OFF
        ANSEL = %00001111
        TRISA = %11111111
        CHAN0  VAR WORD   'VAR TO HOLD ADC0 READING
        START:
        HIGH PORTB.3    'HEART BEAT
        PAUSE 250
        LOW PORTB.3
        PAUSE 250
        'BELOW WILL SHOW WHAT THE ADRESH AND ADRESL REGISTER HOLDS
        SEROUT2 PORTB.2, 16780, ["ADRESH ",DEC ADRESH," ADRESL ",DEC ADRESL,$a,$d]
        PAUSE 50
        'BELOW SHOWS THE 10 BIT READING OF ADC0 IN VAR CHAN0
        SEROUT2 PORTB.2, 16780, ["CHAN0 ",DEC CHAN0,$a,$d]
        GOSUB ADC_0      'STARTS THE READING OF ADC CHANNEL 0
        GOTO START
        
        ADC_0:       'READ AN0
        ADCON1 = %10000000      'SET FOR 10 BIT
        ADCON0 = %00000001      'TURNS ADC ON
        GOSUB   READ_AD
        CHAN0.HighByte = ADRESH  'PLACES THE HIGH AND LOW BYTE
        CHAN0.LowByte  = ADRESL   'INTO VAR CHAN0
        RETURN
        
        READ_AD:   'DOES THE ADC CONVERSION
        PAUSE   50
        ADCON0.2 = 1
        PAUSE   50
        RETURN  
    
    Last edited by mackrackit; - 7th April 2011 at 00:53.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You can actually improve on that Dave...

    Instead of...

    ADCON0.2=1
    PAUSE 50
    RETURN

    ... which makes the assumption that your ADC reading will complete in 50mS... well - suppose it didn't? And suppose it only took only 50uS then you've wasted a shed load of time!

    So, rather than a hit or miss approach, nail it properly...

    ADCON0.2=1
    WHILE ADCON0.2=1:WEND
    RETURN

    To find out why I've done this, read the Datasheet description for pin ADCON0.2

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Post

    A2D8.bas example program, in the SAMPLES Folder ...

    While ... Wend did not exist in those prehistoric times this example was written ...


    Still no code available from tim ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    COOL!!!

    This is what I have said. You learn by trying to help.
    Been using something like I posted all along and of course I have read that part about that bit but it never clicked...

    Maybe that is why it is called GO/DONE

    Prehistoric??? Maybe there is another message here.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Well even in prehistoric times IF was available to you...

    Code:
    	ADCON0.2=1
    ADCTIMEOUT:
    	IF ADCON0.2=1 THEN ADCTIMEOUT
    	RETURN

Similar Threads

  1. Replies: 288
    Last Post: - 25th August 2008, 16:53

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