AD conversion


Closed Thread
Results 1 to 9 of 9

Thread: AD conversion

  1. #1
    Join Date
    May 2011
    Posts
    17

    Default AD conversion

    Hello

    Does anyone know what is the maximum and minimum value of variable at 8 bit AD conversion (PIC 16f877A)

    For example:

    pw var byte

    adcin 0, pw "read AD value on pin 0 and store it at variable pw"

    now I am wondering what is the max and min value of that AD
    is it 0 and 255 since variable is Byte or there is some formula to count that

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: AD conversion

    Bingo! 0-255 it is.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: AD conversion

    then why this doesnt work:

    I have a potentiometer on pin 0 (AD), and when I turn that pot to one end (left or right) my values of variable should be 0 or 255. And when I wrote IF function nothing happens

    for example:

    start:
    ADCIN 0, pw
    if pw = 0 then
    Pulsout portd.2, 220
    else
    goto start
    endif
    goto start

    when ever I wrote pw = 255 or pw = 0 it doesnt do anything, but when I wrote If pw > 220 then it works ????

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: AD conversion

    For debugging purpose I always suggest people use a LCD, ICD or use PC Terminal to see what's happen INSIDE the PIC.

    Also, post your PIC model, whole code so we see your ADC DEFINES. Is the ADC result left or right justified, stuff like that.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    May 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: AD conversion

    I am using PIC 16f877A

    this is the code


    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50
    ADCON1 = 0 ' PORTA is analog
    pw VAR BYTE
    TRISA = 255
    TRISD = 0

    start:

    ADCIN 0,pw

    if (pw > 220) and (pw<252) then
    pulsout portd.3,220
    else
    goto start
    endif
    goto start

    This program works, when I move Joypad to the right motor move to the coresponding postion, I wanna know what is the right value of variable pw, when my joypad is moved al the way to the right and al the way to the left??

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: AD conversion

    OK, so you have the results left justified, it should work. BUT maybe you have some nifty noise on the line or something like that. Allow a certain error margin.



    test 0
    If pw<5 then

    test 255
    if pw>250 then


    still stucked?!? well let's try a variant of it

    Test 0
    if ADRESH<5 then

    test 255
    if ADRESH>250 then

    about now?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    May 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: AD conversion

    So this ADRESH is the adress where AD save it's value ?

    what if I have two, three or four AD, is it all stored in same adress ?

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: AD conversion

    Yup they all have the same register.

    ADCIN select the channel, perform the conversion, then read it from ADRESH/ADRESL register, then dump it to your variable.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    May 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: AD conversion

    thx Steve

    I will probably have few questions, now I will contion on my work

    thx

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