Adcin or Pot


Closed Thread
Results 1 to 19 of 19

Thread: Adcin or Pot

Hybrid View

  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 19: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 22: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 10: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.

Similar Threads

  1. Using the Pot command.
    By timseven in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 17th August 2009, 20: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, 22:23
  3. Replies: 4
    Last Post: - 24th January 2007, 22:20
  4. Using ADCIN or POT/RCTIME?
    By TonyA in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 16th April 2006, 18:37
  5. pot controlled pwm -- help
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 29th January 2006, 12:29

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