Timing scheme


Closed Thread
Results 1 to 9 of 9

Thread: Timing scheme

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Angry problems still here

    I have written the piece of code below and it works at the endpoints of 0.25 to 25 sec for the on time and 30 to 60 sec cycle time. The problem is that it does not work for numbers in between. I think my functions are not working correctly but i dont know. The other problem i see is that if You do the math to figure out the loop times they come out about 4 seconds longer than what is being seen on the hardware. This seems impossible to me, if anything they should be longer not shorter because i was not taking into account the adc reads? Anybody know of an explanation of whats going on here?


    MAIN:
    GOSUB ON_RUN
    pause 10
    GOTO MAIN


    ON_TIME:
    PAUSE 250 ' low end pause time (0.25 sec)
    for i = 0 to ON_counter step 1 ' high end pause loop time (25 sec)
    GOSUB READ_A_D_AN2
    GOSUB READ_A_D_AN3
    PAUSE 27
    nEXT I
    RETURN


    OFF_TIME_RUN:
    ' PAUSE 5000
    for K = 0 to OFF_TIME step 1 'total pause loop time
    GOSUB READ_A_D_AN3
    GOSUB READ_A_D_AN2
    GOSUB OFF_TIME_CALC
    PAUSE 33
    nEXT K
    RETURN

    ON_RUN:
    LOAD_OUT = 1
    GOSUB ON_TIME
    GOTO OFF_RUN

    OFF_RUN:
    LOAD_OUT = 0
    GOSUB OFF_TIME_CALC
    GOSUB OFF_TIME_RUN
    GOTO INITIALIZE


    OFF_TIME_CALC:
    OFF_TIME = (CYCLE_COUNTER - ON_COUNTER) '+ 100
    IF OFF_TIME < 120 THEN OFF_TIME = OFF_TIME + 150
    if OFF_TIME = 1024 THEN OFF_TIME = OFF_TIME + 180
    ' if OFF_TIME > 2000 THEN OFF_TIME = OFF_TIME - 50
    RETURN



    READ_A_D_AN2: 'used for ON Time Delay
    PAUSEUS 50 ' wait 50 microsec
    ADCIN 2, AD_AN2_VALUE ' read channel 2 to AD_AN0_VALUE
    ON_COUNTER = AD_AN2_VALUE ' set counter to AD value
    RETURN

    READ_A_D_AN3: 'used for Cycle Time Delay
    PAUSEUS 50 ' wait 50 microsec
    ADCIN 3, AD_AN3_VALUE ' read channel 3 to AD_AN3_VALUE
    CYCLE_COUNTER = AD_AN3_VALUE + 1024 ' set counter to AD value + 1024
    RETURN


    I appreciate any help that anyone may give. Thank you again.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Can you post your whole code? I am making a guess the problem is in the variable size some where. Or in the ADC setup. And the routine "INITIALIZE" seems to be missing.

    When you post code. the use of code tags helps.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jan 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Unhappy here is the code in its entirty

    '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 = %10001011 ' set as right justified and turn on AD
    ANSEL = %01001100 ' A to D on AN2 and AN3
    CMCON = %00000111 ' set all pins to digital
    TRISIO = %00011111 ' define Inputs and Outputs
    GPIO = %00000000 ' set all pin states to off
    WPU = %00000000 ' shut off weak pull ups
    'Register Initializations'


    'Variables'
    LOAD_OUT VAR GPIO.5
    OFF_COUNTER VAR WORD
    ON_COUNTER VAR WORD
    AD_AN2_VALUE VAR WORD
    AD_AN3_VALUE VAR WORD
    i var word
    K VAR WORD
    'TEST_TRIGGER VAR GPIO.3
    'TEST_COUNTER VAR WORD
    CYCLE_COUNTER VAR WORD
    OFF_TIME VAR WORD
    'Variables'

    '************************************************* ***************************
    '************************************************* ***************************

    INITIALIZE:
    GOSUB READ_A_D_AN2
    GOSUB READ_A_D_AN3

    MAIN:
    GOSUB ON_RUN
    pause 10
    GOTO MAIN


    ON_TIME:
    PAUSE 250 ' low end pause time (0.25 sec)
    for i = 0 to ON_counter step 1 ' high end pause loop time (25 sec)
    GOSUB READ_A_D_AN2
    GOSUB READ_A_D_AN3
    PAUSE 27
    nEXT I
    RETURN


    OFF_TIME_RUN:
    ' PAUSE 5000
    for K = 0 to OFF_TIME step 1 'total pause loop time
    GOSUB READ_A_D_AN3
    GOSUB READ_A_D_AN2
    GOSUB OFF_TIME_CALC
    PAUSE 33
    nEXT K
    RETURN

    ON_RUN:
    LOAD_OUT = 1
    GOSUB ON_TIME
    GOTO OFF_RUN

    OFF_RUN:
    LOAD_OUT = 0
    GOSUB OFF_TIME_CALC
    GOSUB OFF_TIME_RUN
    GOTO INITIALIZE


    OFF_TIME_CALC:
    OFF_TIME = (CYCLE_COUNTER - ON_COUNTER) '+ 100
    IF OFF_TIME < 120 THEN OFF_TIME = OFF_TIME + 150
    if OFF_TIME = 1024 THEN OFF_TIME = OFF_TIME + 180
    ' if OFF_TIME > 2000 THEN OFF_TIME = OFF_TIME - 50
    RETURN



    READ_A_D_AN2: 'used for ON Time Delay
    PAUSEUS 50 ' wait 50 microsec
    ADCIN 2, AD_AN2_VALUE ' read channel 2 to AD_AN0_VALUE
    ON_COUNTER = AD_AN2_VALUE ' set counter to AD value
    RETURN

    READ_A_D_AN3: 'used for Cycle Time Delay
    PAUSEUS 50 ' wait 50 microsec
    ADCIN 3, AD_AN3_VALUE ' read channel 3 to AD_AN3_VALUE
    CYCLE_COUNTER = AD_AN3_VALUE + 1024 ' set counter to AD value + 1024
    RETURN

    END

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Question

    Hi, Glqosec

    One good thing to know is what granularity ( resolution ) you need for ONtime and Cycle duration ...

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    I can suggest the following approch:

    Read cycle and ontime word variables
    Compare the the two variables and adjust ontime to cycle if ontime is greater then cycle

    IF ONTIME>CYCLE THEN ONTIME=CYCLE

    If you don't want offtime=0 then you can add the proper offset

    IF ONTIME>=CYCLE THEN ONTIME=(CYCLE-OFFSET)

    Set high output pin
    loop for for the cycle delay and check ontime
    when loop reach ontime value set low output pin
    continue the loop till you reach the cycle time.

    Ontime will be adjustable and always within cycle time

    Al.
    Last edited by aratti; - 6th November 2008 at 15:07.
    All progress began with an idea

Similar Threads

  1. 12F683 serout timing
    By Hobie Cat in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st December 2009, 16:57
  2. 18F2550 timing
    By sstt1976 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 22nd August 2008, 00:30
  3. PIC 12c509 - No External timing components
    By stay_aliveuk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th September 2006, 17:20
  4. Questions on timing
    By malc-c in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2006, 22:38
  5. HSEROUT buffering and timing - 16F88
    By picster in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 5th March 2006, 17:52

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts