Adcin or Pot


Results 1 to 19 of 19

Thread: Adcin or Pot

Threaded 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.

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 : 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