16F876A ADC write and read?


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2007
    Posts
    9

    Unhappy 16F876A ADC write and read?

    I've never used an ADC function on a PIC, and am fairly inexperienced with PIC's compared to you guys,
    My question is, does anyone have a sample of code that defines and configures an ADC input, does a read, writes that variable to a place in memory, and is read some time later?

    Thank you in advance
    Jim-

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by clem View Post
    I've never used an ADC function on a PIC, and am fairly inexperienced with PIC's compared to you guys,
    My question is, does anyone have a sample of code that defines and configures an ADC input, does a read, writes that variable to a place in memory, and is read some time later?

    Thank you in advance
    Jim-
    ADC Input configuring and reading - fine example in the little green book
    EEPROM writing - little green book
    EEPROM reading - little green book

    So, what I am eluding to here, is that there is a lot of good information in the little green book.
    So, read the book, write some code and try to make it work the way you want it to.
    If and when that code doesn't work, we here in the forums will be more than happy to help you figure out why it doesn't work.

  3. #3
    Join Date
    Apr 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default the little green book

    I read the little green book and it is'nt very intuitive.
    here is the code... I keep getting a output must be a variable error message
    at ADCIN PORTA.0, 0


    PULSE VAR PORTC.2
    RL1 VAR PORTC.1
    RL2 VAR PORTC.0
    HEATIN VAR PORTA.1
    SENSIN VAR PORTA.0
    ADCON1 = 0011 'Declare A ports 0 & 1 as Analog to dig converters
    ADCON1.7 = 1 'Analog to Digital variables declared right justified
    TRISA = 255
    DEFINE ADC_BITS 10
    DEFINE ADC_SAMPLEUS 5



    loop_delay CON 500 ' adjust to tweak timing
    ms_count VAR WORD


    loop:

    FOR ms_count = 0 TO 999 ' 0 to 999mS

    IF ms_count < 14 THEN ' PULSE low 0 to 13 mS
    low PULSE
    ELSE ' PULSE and RL1 high at 14
    high PULSE
    high RL1
    high RL2
    ENDIF

    IF MS_count > 8 THEN ' RL1 low at 9 mS
    high RL2
    ENDIF

    IF ms_count > 995 THEN ' RL2 low at 995 mS, high at 0
    low RL1
    ENDIF

    IF ms_count = 997 THEN ' Read PORTA.0 ADC VALUE put in mem loc 0
    ADCIN PORTA.0, 0
    ENDIF

    PAUSEUS loop_delay ' fill in time for 1mS loop

    NEXT ms_count

    goto loop
    END

    What do you think?

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Read the ADCIN section again, 5.2.
    ADCIN PORTA.0, 0
    Where's the variable?

  5. #5
    Join Date
    Apr 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default I'm still lost

    Do I have to set aside specific memory locations?
    Do I have to declare specific variables?
    The book states:
    ADCIN channel, Var

    I'm still lost

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by clem View Post
    Do I have to set aside specific memory locations?
    Do I have to declare specific variables?
    The book states:
    ADCIN channel, Var

    I'm still lost
    Did you read section 5.2?
    You are using the command ADCIN, which reads the specific ADC channel, which is connected to a certain pin. This value which is read is put into a specifica variable. You aren't using a variable in your code, you haven't specified a place to put it. You are using variables in other spots...so why not here?

    How much PIC programming have you done so far? LED blinky? Anything like that?

  7. #7
    Join Date
    Apr 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default None

    Sorry this is my first time.
    But I did figure it out,
    thank you for the help

    Jim-

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by clem View Post
    Sorry this is my first time.
    But I did figure it out,
    thank you for the help

    Jim-
    If you're starting off with ADCIN type commands, you might want to back up a bit and play around some with some LEDs and some buttons first. Get the basics down. Dig in too deep and too hard right off the get go, and you're setting yourself up for headaches in the future.
    Just my thoughts on the process...

  9. #9
    Join Date
    Apr 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks for the advice...much appreciated

    Jim-

Similar Threads

  1. READ WRITE not working consistantly on 12f675
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th September 2009, 16:15
  2. write -read problem?
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th August 2009, 13:06
  3. Q: using MCLR for Input on 12F683
    By picster in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 31st January 2009, 15:25
  4. PIC16F684 + LCD to use the 256bytes of EEPROM - HELP
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th March 2008, 14:19
  5. Write Read And Words
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th March 2004, 23:27

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