AD conversion


Closed Thread
Results 1 to 9 of 9

Thread: AD conversion

Hybrid View

  1. #1
    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.

  2. #2
    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??

  3. #3
    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.

  4. #4
    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 ?

  5. #5
    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.

  6. #6
    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 : 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