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 repeat my question :
    how tie the resistors on the side of PIC together to have a resultant resistor in parallele ?
    i agree that the other side is tie together to the radio , but on the ground ,yes
    but the +5V for PIC RBx ?

    Regards.

    Hervé

  2. #2
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    in fact , the simulator isn't reactif with adc , i must go slowly with an0/an1 choice .
    But step by step around button(i) , it works.

    I must add six other buttons in programm and .

  3. #3
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Can i use btn as word variable for a select case like 1110111111111111 ?
    (with your formule dcd(i).... )
    i can't for the moment ...
    i use adcchannel 0 to 3 .

    Regards.
    Hervé

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


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    pbp 3 manual section 2.12
    Steve

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

  5. #5
    Join Date
    Aug 2011
    Posts
    40


    Did you find this post helpful? Yes | No

    Default Re: Stable ADC readings

    Hello,

    it works all !
    great and many thanks.

    I made another "formule" in addition to yours (to work with 12 buttons and 4 channels__3 buttons on a wire)
    It is perhaps not proper .
    I add to this : PIC Simulator IDE 6.91 works great , all test with it and great.


    . btn = ((DCD i) << (ADCChannel*3))^255
    . if ADcchannel = 3 and btn = %11111111 then btn = (btn - (3*adcchannel)) << i
    . gosub choose
    ..
    ..
    ADCChannel = ADCChannel + 1 'Switch to the other ADC channel
    if ADCchannel = 4 then adcchannel = 0
    ..
    ..
    choose:
    select case btn
    ' first bloc of 6 buttons
    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
    ........


    Regards
    Hervé

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

  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

    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.

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