ADC with Potentiometers - Help!


Closed Thread
Results 1 to 3 of 3
  1. #1
    seejayjames's Avatar
    seejayjames Guest

    Question ADC with Potentiometers - Help!

    I'm having trouble getting more than just one ADC pin to work on my P16877A. I can get pin 2 (A0) to work just fine, but none of the others. I think I'm not setting up the parameters right. Also, do I need to reset something after each sample?

    I eventually want to have eight 8-bit dials hooked up to the 8 ADC inputs and sample them constantly (to control music parameters in Max/MSP

    Here's the relevant parts of the code. Thanks in advance to whoever has some info!

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

    define osc 20
    INCLUDE "modedefs.bas"

    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 4
    DEFINE ADC_SAMPLEUS 20

    TRISA = 255
    ADCON1 = %00000010

    '------------------------------------------------------------------

    pot_pin_2 var PORTA.0 'set potentiometer to go in pin 2 (A0)
    pot_pin_3 var PORTA.1 'set potentiometer to go in pin 3 (A1)

    'vars for potentiometer info
    var_pot_2 var byte
    var_pot_3 var byte

    main_loop:

    ADCIN pot_pin_2, var_pot_2 ' Read pin 2 to var_pot_2
    var_pot_2 = (255 - var_pot_2) ' Invert result to match dial direction L/R

    serout serial_out_pin,T9600,["Sending POT PIN 2... ",#var_pot_2,10,13]

    pause 700

    '----------------------------------------------------------

    ADCIN pot_pin_3, var_pot_3 ' Read pin 3 to var_pot_3
    var_pot_3 = (255 - var_pot_3) ' Invert result to match dial direction

    serout serial_out_pin,T9600,["Sending POT PIN 3... ",#var_pot_3,10,13]

    pause 700

    goto main_loop

  2. #2
    Patrick's Avatar
    Patrick Guest


    Did you find this post helpful? Yes | No

    Talking 2 Pots,2 Servo's

    Played a bit

    Here is a working example on a 16F876

    '==========================================
    'P van Biljon
    'Servo test program
    'Text for two servo,s
    '29 June 2006
    'Pic 16F876-04
    'Good for two Servo's
    '==========================================

    potCW1 var portc.0
    potccw1 var portc.1
    Servo1 var portc.2

    potCW2 var portc.3
    potccw2 var portc.4
    Servo2 var portc.5

    rcrt1 var word
    rclf1 var word
    Pos1 var word

    rcrt2 var word
    rclf2 var word
    Pos2 var word
    '==========================================
    DEFINE LOADER_USED 1 ' If using bootloader to program pic

    Init:

    adcon1 = 7
    trisc = %00000000

    Main: gosub pot1
    gosub pot2

    pot1:
    HIGH potcw1
    HIGH potccw1


    pause 5

    rctime potcw1,1,rcrt1
    rctime potccw1,1,rclf1
    rcrt1 = rcrt1 */ $0068 max 250
    rclf1 = rclf1 */ $0068 max 250
    pos1 = rcrt1 - rclf1
    pulsout servo1,(200 + pos1)
    pause 5
    return
    Pot2:
    HIGH potcw2
    HIGH potccw2

    Pause 5

    rctime potcw2,1,rcrt2
    rctime potccw2,1,rclf2
    rcrt2 = rcrt2 */ $0068 max 250
    rclf2 = rclf2 */ $0068 max 250
    pos2 = rcrt2 - rclf2
    pulsout servo2,(200 + pos2)
    pause 5

    goto main


    with .1qF caps on pot connected to +5 Volts

    Patrick

  3. #3
    seejayjames's Avatar
    seejayjames Guest


    Did you find this post helpful? Yes | No

    Cool ADC - Potentiometers

    Thanks Patrick! Will definitely try out the code on my chips. I think it was something to do with the pauses, or perhaps the rctime. Hope to get it working so I can utilize those ADC's.

    Thanks again!
    -CJ

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  3. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  4. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

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