Stable ADC readings


Closed Thread
Results 1 to 40 of 91

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    i am so disapointed because it doesn't work on test real card and works on simu.
    strange...
    i have microcode studio with 15 days trial .(compiler 3.0.0.1)

    TRISA = %00001111 ' RA0 et RA1 en entrée

    TRISB = 255 ' Disconnect all resistor from the circuit (Haute impédance)

    PORTB = 0 '

    '

    ' ADC

    ' ---

    DEFINE ADC_BITS 10 ' Set number of bits in result

    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)

    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in

    ADCON1 = %10000010 ' RA0 à RA3 and RIGHT JUSTIFIED



    '

    ' Software Variable

    ' =================

    ADCRes VAR WORD ' ADC Reading

    btn var byte ' Data to be scan

    i VAR BYTE '

    j var bit

    ADCChannel VAR byte '

    ADCButton VAR word [3]'

    '

    ' Software constant

    ' =================

    j = 0

    ADCSafety CON 10 ' min/max range for ADC Reading

    '

    ADCNone CON 814 - ADCSafety '

    ADCButton[0] = 90 ' button 1,7 or 4,10

    ADCButton[1] = 164 ' button 2,8 or 5,11

    ADCButton[2] = 270 ' button 3,9 or 6,12



    Start:

    TRISB = 255

    ADCIN ADCChannel,ADCRes ' Read ADC

    '

    if (ADCRes < ADCNone) Then ' Any button down?!?

    ' - Yes!

    FOR i = 2 TO 0 STEP -1 ' Loop through all 3 calculated posibilities

    ' Test against calculated ADCresult

    ' and allow a range of +/- ADCSafety

    IF (ADCRes > (ADCButton[i]-ADCSafety)) AND (ADCRes < (ADCButton[i]+ADCSafety)) THEN

    ' Valid ADC result, clear the coresponding I/O

    btn = ((DCD i) << (ADCChannel*3)) ^255

    if (ADcchannel = 3 and btn = 255) then btn = ((btn - (3*adcchannel)) << i)

    gosub choix

    pause 200

    i=0 ' and getOut of here

    ENDIF '

    NEXT '

    else ' - NO!

    ADCChannel = ADCChannel + 1 'Switch to the other ADC channel

    if ADCchannel = 4 then adcchannel = 0

    ENDIF

    GOTO Start

    choix:

    select case btn

    ' premier bloc de 6 boutons
    case %11111011 ' AN0-270 --- 47k and 5k = 4.6k

    TRISB.0 = 0 ' 5k and 5k = 2.5k

    TRISB.1 = 0

    case %11111101 ' AN0-164 --- 47k and 10k = 8.2k

    TRISB.1 = 0 ' 5k and 5k = 2.5k

    TRISB.2 = 0 ' 47k and 47k = 22k

    case %11111110 ' AN0-90 --- 47k and 22k = 15k

    TRISB.2 = 0

    TRISB.3 = 0 ' 10k and 10k = 5k

    case %11011111 ' AN1-270 --- 47k and 2.2k = 2.1k

    TRISB.3 = 0 ' 47k and 15k = 11.3k

    case %11101111 ' AN1-164 --- 100k and 22k = 18k

    TRISB.4 = 0 '

    TRISB.0 = 0 '

    case %11110111 ' AN1-90

    TRISB.5 = 0

    TRISB.1 = 0

    TRISB.3 = 0

    ' deuxième bloc de boutons

    case %11111111 ' AN2-270 --- 47k and 5k = 4.6k

    TRISB.7 = 0 ' 5k and 5k = 2.5k

    TRISB.6 = 0

    case %01111111 ' AN2-164 --- 47k and 10k = 8.2k

    TRISB.5 = 0 ' 5k and 5k = 2.5k

    TRISB.4 = 0 ' 47k and 47k = 22k

    case %10111111 ' AN2-90 --- 47k and 22k = 15k

    TRISB.2 = 0

    TRISB.3 = 0 ' 10k and 10k = 5k

    case %11011000 ' AN3-270 --- 47k and 2.2k = 2.1k

    TRISB.7 = 0 ' 47k and 15k = 11.3k

    case %11101100 ' AN3-164 --- 100k and 22k = 18k

    TRISB.5 = 0 '

    TRISB.0 = 0 '

    case %11110110 ' AN3-90

    TRISB.5 = 0

    TRISB.7 = 0

    TRISB.3 = 0

    end select

    return

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


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Dunno buddy, replace your resistor with LED to Vdd and see what happen, Code seems to be OK.

    On your PIC16F877, make sure you have all VDD and VSS pin connected, MCLR to VDD and the right capacitor around the crystal. If you're using an >4MHz one, set the HS_OSC fuse. Always make sure you also disable LVP in the configuration fuse too.
    Steve

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

  3. #3
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Dunno buddy , your program Code works very well with some resistors and one led on my PIC Hardware platform test .
    With it , the intensity varies according to different buttons .
    Perhaps microcode studio with 15 days trial .(compiler 3.0.0.1) ?
    my programmer is willem with winpic800 .

  4. #4
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    i 've just try compiler 2.60 plus patch 2.60c under microcode studio 3.0.0.5
    and verify fuse under willem (hs) , always the same .
    arg , no understand why if the code is good .........................../

  5. #5
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    STUPID I AM , no pull-up resistors for RA2 and RA3....

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Post #52

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    ----======----



    ----======----
    Steve

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

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