Adcin or Pot


Closed Thread
Results 1 to 19 of 19

Thread: Adcin or Pot

  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default Adcin or Pot

    Hi, I wrote a program and I was wandering if it is better to use the Pot command or the Adcin command ?
    Also , I wrote this small program. I have two potentiometer, I connected them to the input pin and to the positive supply . Is this good ?
    I get somewhat good result with one, but when i put two, the second pot stays at 255..


    'TRANSMIT PIC
    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %00000001 ' Configure and turn on A/D Module


    TRISB = 0
    TRISA = 1
    '27
    temp var word : right var byte : left var Byte : oldright var byte : oldleft var byte
    encoded1 var word
    '
    'Leftwheel =CW : Rightwheel= CW '---- $66 = 01 10 01 10
    'Leftwheel =CW : Rightwheel= CCW '---- $56 = 01 01 01 10
    'Leftwheel =CCW : Rightwheel= CW '---- $5a = 01 01 10 10
    'Leftwheel =CCW : Rightwheel= CCW '---- $65 = 01 10 01 01
    '
    loop:

    ADCON0.2 = 1 'Start Conversion

    oldright = right 'Pot reading 1
    oldleft = left 'Pot reading 2
    ADCIN 0, right 'Read channel PORTA.0
    pause 50
    ADCIN 1, left 'Read channel PORTA.1
    pause 50

    right = (right +oldright)/2 'Reducing the fluctuating output by taking an average
    left = (left +oldleft)/2

    Lcdout $fe, 1 'Clear screen
    Lcdout "Right: ", Dec right 'Display the decimal value
    Lcdout $fe, $C0, "Left: ", DEC left 'Display the decimal value
    pause 100

    goto loop
    end
    Last edited by lerameur; - 7th January 2007 at 20:25.

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


    Did you find this post helpful? Yes | No

    Default

    Depending of your PIC, your ADCON, ANSEL setting have to be set to make AN0, AN1 as analog first. Your sampling time and clock source look fine... even if they are way too slow. Too slow is still better than to fast, so it's not your problem source here.

    Your pot have to be connected between Vdd and Vss. The wiper goes to the PIC input. It's value must be equal OR less than the maximum recommended by your datasheet. It's a good idea to filter the POT output with a capacitor (10-100 nF)
    Steve

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

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    I tend to use a 10k Lin pot with one leg connected to +ve (5v) and a 0.1uf cap between the other leg and GND - the wiper then goes to the PIN.

    Using the scale value in the POT statement you should be able to get the range right so the value is 0 at one end of the travel, to 255 at the other.

    Edit - just noticed that you have an LCD attached - then using
    Code:
    Pot PORTA.0,scale,D
    LCDOUT $FE,$C0, "Cal value " ,#D    ; where D is the varible used in the POT statement
    would show the value for the variable D in deceimal on the second line, so you can calibrate the range exactly
    Last edited by malc-c; - 7th January 2007 at 23:13.

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I barely turn the Pot and it reaches goes from 0 to 255 in no time, I mean barely, I tried all the values for the sale ranging from 0 to 255 passing through 127, it react the same way.
    My left leg of the pot is on GRD the middle is on the pin, and right leg on the Vcc. with 0.1uF cap gnd to pin.
    is that it ?

    i kept is very simple:

    INCLUDE "modedefs.bas"
    DEFINE OSC 20 'use external 20mhz crystal
    CMCON = 7 : ANSEL = 0 : ADCON1 = 7
    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000


    TRISB = 0
    TRISA = 1
    '27
    temp var word : right var byte : left var Byte : oldright var byte : oldleft var byte

    loop:


    oldright = right 'Pot reading 1
    oldleft = left 'Pot reading 2

    Pot PORTA.0,127,right
    Pot PORTA.1,127,left
    right = (right +oldright)/2 'Reducing the fluctuating output by taking an average
    left = (left +oldleft)/2

    Lcdout $fe, 1 'Clear screen
    Lcdout "Right: ", Dec right 'Display the decimal value
    Lcdout $fe, $C0, "Left: ", DEC left 'Display the decimal value
    pause 100

    goto loop
    end

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


    Did you find this post helpful? Yes | No

    Default

    if you're using POT you have it wrong. look in the PBP manual. Depending your POT impedance, the capacitor might be too low... i hate POT. your PIC have ADCs.... just use it with ADCIN and set the according i/o properly.
    Steve

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

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    My left leg of the pot is on GRD the middle is on the pin, and right leg on the Vcc. with 0.1uF cap gnd to pin.
    is that it ?
    If I read this correctly you have placed the capacitor in parallel with the left leg of the pot. If so this is wrong, you need to place it in series with the pot.

    Using a 10K lin pot and a 0.1uf capacitor and a scale of 254 I get a range of 0 - 255 in the last 30% of travel, regardless of the value of scale. However, if a lower value of scale is used, the travel range is reduced, but with a higher value I get the full range (0 - 255) within this 30% of travel. I think that the choice of potentiometer and or the value of the capacitor used is critical if you want to get a full range across 100% of the travel of the pot.
    Attached Images Attached Images  
    Last edited by malc-c; - 8th January 2007 at 11:29.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Check your statement TRISA=1. I believe you are making all PORTA as outputs except PORTA.0.

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


    Did you find this post helpful? Yes | No

    Default

    Yup but POT 'Should' do the job... As output first to charge/discharge the capacitor, then set as input to evaluate the RC plah plah.

    If the POT/Capacitors value match is not good AND the 'way to use them' is not good... of course results will be bad.
    Steve

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

  9. #9
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    In the schematic above, why the POT is connected to +5V ?

    Any particular reason?

    ------------------

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Pot

    Are you using a linear taper Pot? Audio taper pots have a logarithmic scale to their resistance and would likely present a similar responce.
    JS

  11. #11
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Well, I ordered them as Lin pots.. but knowing the numbskulls in the local shop they could well indeed be log

  12. #12
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I am using a 47K linear POT.
    I tries usin a 0.1 UF capacitor, I was barely moving the pot and it reaches 255, bu adding 2 0.1 uF in series I was getting a little bit further. Then any changes in pot values did not change a thing. Decreasing the scale also help going a bi further. I scaled it down to decimal 2 (out of 255) and 2 x 0.1 uF caps. i am only getting halfway with the pot. i would like to go all the way.... what should I try..

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    I am using a 47K linear POT.
    I tries usin a 0.1 UF capacitor, I was barely moving the pot and it reaches 255, bu adding 2 0.1 uF in series I was getting a little bit further. Then any changes in pot values did not change a thing. Decreasing the scale also help going a bi further. I scaled it down to decimal 2 (out of 255) and 2 x 0.1 uF caps. i am only getting halfway with the pot. i would like to go all the way.... what should I try..
    What are your Vref+ and Vref- settings on?

  14. #14
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    i did not set them , so they should be using the default 5v
    Is it needed fot eh POt command, i thout it was for the adcin (a/d)
    I tried it anyway , put Vref+ to 2.5v,no changes
    Last edited by lerameur; - 9th January 2007 at 20:08.

  15. #15
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    OK I've just had a further look at the manual, and there was no connection of the second leg to the +ve, however disconnecting the link between the +5v and the pot resulted in the value of D (in the above example) to 1 regardless of where the pot was set. Reconnecting the leg of the POT to +ve and the value changed back to 255 !

    Looking at the manual it states
    The resistance is measured by timing the discharge of a capacitor through the resistor (typically 5K to 50K). Scale is used to adjust for varying RC constants. For larger RC constants, Scale should be set low (a minimum value of one). For smaller RC constants, Scale should be set to its maximum value (255). If Scale is set correctly, Var should be zero near minimum resistance and 255 near maximum resistance.

    Unfortunately, Scale must be determined experimentally. To do so, set the device under measure to maximum resistance and read it with Scale set to 127. Adjust Scale until the Pot command returns 254. If 255, decrease the scale. If 253 or lower, increase the scale.
    Whats happening here is that your not measuring the voltage and then converting that analogue voltage into a digital value as per A to D convertion. The resistor charges the capacitor, which then discharges, which results in a negative going pulse on the pin. The frequency of this pulse determins the value of being stored in the variable (D in my example above). Here are some traces showing the pulse rate when D was 0, around 20 and at 255.
    Attached Images Attached Images    

  16. #16
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I am not using A/D yu are right, but it still do not work , maybe i should use the A/D and change the reference voltage

    Ok i juste tried A/D works good
    Pot sucks..
    Last edited by lerameur; - 9th January 2007 at 22:15.

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


    Did you find this post helpful? Yes | No

    Default

    Je te l'avais dit

    I told you!
    Steve

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

  18. #18
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    oui je sais caline..

  19. #19
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    oui je sais caline..
    I didn't know the specie-that-grows-but-never-reproduces had haunted this forum ... LOL

    Being serious ... FORGET the "POT" Command ... and use RCTime instead !!!
    ADC not really compulsory for numerous applications.

    Alaain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Using the Pot command.
    By timseven in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 17th August 2009, 21:23
  2. A/D, Pot, Input, A,B So lost now....
    By Helmutt in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 9th March 2008, 23:23
  3. Replies: 4
    Last Post: - 24th January 2007, 23:20
  4. Using ADCIN or POT/RCTIME?
    By TonyA in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 16th April 2006, 19:37
  5. pot controlled pwm -- help
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 29th January 2006, 13:29

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