Timing scheme


Closed Thread
Results 1 to 9 of 9

Thread: Timing scheme

  1. #1
    Join Date
    Jan 2007
    Posts
    16

    Thumbs down Timing scheme

    i AM TRYING TO CREATE A TIMER USING A 12f675 and am having trouble doing so.

    The timer works by using two pots to control the ON time and the CYCLE time.

    In other words i use one pot to set my cycle time to lets say 1 min. and then i use the other pot to set an ON time of 5 sec. The problem that i am having is that i need it to work so that if i make my ON time larger it makes the OFF time smaller while keeping the CYCLE time the same.

    I cant figure out how to basically do two things at once.

    The final problem is that i need the ON time and the CYCLE time to be adjustable is specific time ranges.

    Any help at all would be greatly appreciated.

    I have created a timer before but i simply controlled the ON and OFF time not the CYCLE time as with this timer.

    I have thought about using the TMR0 function of the chip to run in the background but have never used it before and the datasheet is not much help.

    Thank you for any help at all.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I think what you are talking about is 'VERY VERY Very slow speed PWM'
    Is the code in your other post about the same subject still the same?

  3. #3
    Join Date
    Jan 2007
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    I had figured out how to do the other post by using the code below...

    ON_TIME:
    PAUSE 525 ' low end pause time
    for i = 1 to ON_counter step 1 ' high end pause loop time
    GOSUB READ_A_D_AN0
    PAUSEus 4750
    nEXT I
    RETURN

    OFF_TIME:
    PAUSE 525 ' low end pause time
    for i = 1 to OFF_counter step 1 ' high end pause loop time
    GOSUB READ_A_D_AN1
    PAUSEus 4750
    nEXT I
    RETURN



    I used this with AD on the two pots and then just called on time of off time when it was neccessary. But now i have to coordinate these two time ranges together as explained above. I appreciate your help.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by glkosec View Post
    The problem that i am having is that i need it to work so that if i make my ON time larger it makes the OFF time smaller while keeping the CYCLE time the same.
    8 bit ADC has 265 steps. Subtract the ON reading from 256, if the ON is reading 64 then OFF will be 192. ON is 192 then OFF will be 64...
    I cant figure out how to basically do two things at once.
    Not going to happen with software routines.
    The final problem is that i need the ON time and the CYCLE time to be adjustable is specific time ranges.
    Maybe if
    POT_TIME is > 0 and < 50 then T1
    POT_TIME is >50 and < 100 then T2
    Dave
    Always wear safety glasses while programming.

  5. #5
    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.

  6. #6
    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.

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

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


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

  9. #9
    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 : 1

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