using a pot to control a time range


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2007
    Posts
    16

    Question using a pot to control a time range

    I am relativley new to programming and am trying to make a simple timing circuit with a PIC12F675. I have written some code that uses a potentiometer and the AD converter to scroll through the time range based on the conversion.

    The only problem is i cannot control the range that the time is for(at least i couldn't figure the math out to do so).

    Is there anyone that thinks they might be able to help. I will post the code below. I appreciate any and all suggestions.

    MAIN:
    A1 = %00000000
    GOSUB READ_A_D_AN0
    LOAD_OUT = 1 ' ON FIRST TRIGGERABLE
    PAUSE 100
    BUTTON MAIN_TRIGGER, 1, 255, 0, a1, 0, RUN
    GOTO MAIN



    TIME:
    FOR DELAY = 0 TO COUNTER STEP 1
    PAUSE 10
    GOSUB READ_A_D_AN0
    NEXT DELAY
    RETURN



    RUN:
    PAUSE 10
    LOAD_OUT = 0
    GOSUB TIME
    PAUSE 10
    GOTO MAIN






    READ_A_D_AN0: 'used for Time Delay 1
    PAUSEUS 50 ' wait 50 microsec
    ADCIN 0, AD_AN0_VALUE ' read channel 0 to AD_AN0_VALUE
    COUNTER = (AD_AN0_VALUE */ 1000) >> 2

    RETURN

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Is that the whole program that you have coded?
    'cause I don't see ANY of the ADC DEFINEs as shown in the PBP manual there, not that they're really needed, but could be helpful.
    Also, are you sure the program is even running? (i.e. blinky LED?)

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Try this. I've used something similar to it on a 12F675 and had no problems. You should be able to turn on the LED for up to 255 seconds (the maximum byte value).

    CMCON = 7 'comparators off
    trisio = %11111111 'ALL INPUTS - HIGH & LOW COMMANDS CONVERT TO OUTPUTS
    DEFINE OSCCAL_1K 1 'Set OSCCAL for 1K device
    POTVALUE VAR BYTE 'POTENTIOMETER VALUE VARIABLE
    LEDTIMER VAR BYTE 'LED TIMER VARIABLE

    START:
    LET LEDTIMER = 0 'RESET TIMER TO 0
    Low GPIO.4 'TURN OFF LED ON GPIO.4
    PAUSE 5000 'STAY OFF FOR AT LEAST 5 SECONDS
    ADCIN 1,POTVALUE 'READ VALUE OF POT
    IF POTVALUE = 0 THEN START 'STAY HERE OFF UNTIL POT IS TURNED

    LEDON:
    High GPIO.4 'TURN ON LED FOR 1 SECOND INCREMENTS
    PAUSE 1000
    LET LEDTIMER = (LEDTIMER + 1) 'COUNT SECONDS
    ADCIN POTVALUE 'READ POT VALUE
    IF POTVALUE > LEDTIMER THEN LEDON 'STAY HERE ON UNTIL LEDTIMER = POTVALUE
    GOTO START 'LEDTIMER = POTVALUE GOTO START & RESET
    Last edited by peterdeco1; - 17th June 2008 at 19:14. Reason: FORGOT LINE

  4. #4
    Join Date
    Jan 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Question timing issues

    no this is not the entire programs i have my defines set as follows

    'Definitions'
    DEFINE OSC 4
    DEFINE ADC_BITS 10 ' set number of bits in result
    DEFINE ADC_CLOCK 3 ' set clock source
    DEFINE ADC_SAMPLEUS 50 ' set sampling time for microseconds
    'Definitions'

    'Register Initializations'
    ADCON0 = %10000011
    ANSEL = %00000011 ; A to D on AN0 and AN1
    'ANSELH = %00001100
    CMCON = %00000111
    TRISIO = %00011111 ; define Inputs and Outputs
    GPIO = %00000000 'set all pin states to off
    'OPTION_REG = %11100000
    WPU = %00000000
    'Register Initializations'


    'Variables'
    LOAD_OUT VAR GPIO.5
    DELAY VAR WORD
    COUNTER VAR WORD
    AD_AN0_VALUE VAR WORD
    MAIN_TRIGGER VAR GPIO.2
    A1 var Byte
    i var word


    im trying to achieve multiple time ranges. for example 0.5 sec to 5 sec, and i want to use the pot to adjust in that range.

    But when i do the AD conversion it is giving me a number between 0 and 1024. But inorder to get my specific range i need a value of 50 to 500.

    I am basically trying to figure out a way to spread the 50 to 500 range out over the full 0 to 1024 range so i get the same resolution and get my two endpoints of 50 and 500.

    I have also changed thge code as follows.

    MAIN:
    A1 = %00000000
    GOSUB READ_A_D_AN0
    LOAD_OUT = 1 ' ON FIRST TRIGGERABLE
    PAUSE 100
    BUTTON MAIN_TRIGGER, 1, 255, 0, a1, 0, RUN
    PAUSE 100
    GOTO MAIN


    TIME:

    for i = 1 to counter step 1
    FOR DELAY = 1 TO 10 STEP 1
    PAUSE 1
    GOSUB READ_A_D_AN0
    NEXT DELAY
    next i
    RETURN

    RUN:
    PAUSE 10
    LOAD_OUT = 0
    GOSUB TIME
    PAUSE 10
    GOTO MAIN

    I appreciate the help, thank you very much.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking K.i.s.s. ...

    Hi,

    The simplest way :

    Time = ( ADC result >> 1 + 50 ) MIN 500 ...

    or better

    Time = ( ADC Result >> 1 + 50 ) * 8 / 9

    Applause ... Thanks !

    Alain
    Last edited by Acetronics2; - 17th June 2008 at 20:17.
    ************************************************** ***********************
    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. 16F877 elapsed time control
    By BerkayT in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 12th February 2009, 17:23
  2. servo control via pot ?
    By n0oxv in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 1st March 2007, 07:11
  3. Control unlimited servos at the same time
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 19th September 2006, 14:14
  4. Button pressed time control
    By tanero in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 15th August 2005, 15:17
  5. trying the pot command to control delay
    By reddogtj in forum mel PIC BASIC
    Replies: 2
    Last Post: - 20th May 2005, 12:50

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