PIC16F818 ADC Problem


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116

    Default PIC16F818 ADC Problem

    Hi,

    I am using a pic16f818, and am having trouble with the a/d convertor. I just have a pot & an LED, here is the program:

    define OSC 8
    define adc_bits 10
    define adc_sampleus 50
    TRISA = 255
    ADCON0 = 193
    ADCON1 = 128

    led var portb.1
    value var word

    start:
    adcin 0, value
    if value = 0 then value = 1
    high led
    pause value
    low led
    pause value
    goto start
    end

    When I turn the pot I get a delay of 1, 2, or 3 mS. I would expect a delay of upto 1023mS. Can anyone please help?

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Hi Bob. This is how I use the 818 & 819. I prefer the easier 255 step ADC but used the 1024 in the past with no problem.

    OSCCON = $60 'set int osc to 4mhz
    'USE OSCCON = $70 for 8mhz
    adcon1 = 7 ' set inputs to digital. adcin command will convert to analog
    MYVAR VAR BYTE

    'uncomment & use the following 4 lines for 1024 step conversion INSTEAD of 'var byte
    'MYVAR VAR WORD
    'DEFINE ADC_BITS 10 ' Set number of bits in result
    'DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
    'ADCON1.7 = 1 'RIGHT JUSTIFY RESULT

    @ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON

  3. #3
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default

    Thanks, but I just tried that & still get the same results, a maximum of 3 as the a/d result. I have tried chips from different batches, various settings for the adc clock, I am using a 8MHz resonator for the clock. I have measured the voltage on the pin (pin 17), and it varies from 0 to 5V. I have used the 818 in the past with no problems. That time I had a 20MHz osc, so I used clock / 64, i.e. ADCON0 = 129, ADCON1 = 206 and it worked fine. I just cant see why it wont work.

    Oh well I'll keep trying....

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Try not using your ADCON statements. I've never used them & always worked for me. Also try the internal oscillator @ 4MHZ. Your program looks like it should work.

  5. #5
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default

    Thanks for your help.

    I have got rid of the ADCON commands, and fitted an lcd display, it now works, kind of. It will work as an 8 bit a/d. Very strange, as I said I have used the 10 bit a/d of an 818 before. 8 bits will do though, in this case.

    Regards
    Bob...

Similar Threads

  1. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  2. Mutliple ADC problem with PIC16F877
    By andyto in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd October 2007, 17:47
  3. Problem getting PIC16f818
    By jjohannson in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th March 2007, 17:03
  4. ADC problem with PIC16F917
    By eetech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th March 2007, 21:22
  5. 16F876 ADC problem
    By Douwe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th June 2006, 19:38

Members who have read this thread : 0

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