Linear acceleration ramp


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1

    Question Linear acceleration ramp

    Hi everyone,

    I would like to make a simple, linear acceleration ramp.
    I think that low priority DT interrupts can serve as a timebase.

    The thing I want is like that: increase linearly the value "x" to value "y" in "n" seconds.

    For example, ramp from 10 (x) to 560 (y) in 42 seconds (n).

    Time (n) is between 0 and 255 seconds.
    Values to increment (x and y) are between 10 and 1200.

    Thanks

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Linear acceleration ramp

    I don't know if it will execute quickly enough but you could use a lookup table in a for next loop where the counter VAR is the lookup VAR.
    example:
    for i = 0 to 10
    lookup i,[10,25,50, . . . . ] pulsevar
    next i
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Linear acceleration ramp

    Although you said linear, I assume you really can live with a staircase.
    If that's the case, and I understand the question correctly, then it's just simple math.

    Your example: ramp from 10 (x) to 560 (y) in 42 seconds (n).
    Suppose you want 1 step per second. In that case:
    stepsize = (y-x)/n
    output = x
    FOR QQ = 1 to n
    PAUSE 1000
    output = x + stepsize
    next QQ
    Replace the pause with a 1 second interrupt if you need to do other things.
    "output" feeds yout DAC

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Linear acceleration ramp

    Quote Originally Posted by Charlie View Post
    Although you said linear, I assume you really can live with a staircase.
    If that's the case, and I understand the question correctly, then it's just simple math.

    Your example: ramp from 10 (x) to 560 (y) in 42 seconds (n).
    Suppose you want 1 step per second. In that case:
    stepsize = (y-x)/n
    output = x
    FOR QQ = 1 to n
    PAUSE 1000
    output = x + stepsize
    next QQ
    Replace the pause with a 1 second interrupt if you need to do other things.
    "output" feeds yout DAC
    I will try that, thanks!

  5. #5
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Linear acceleration ramp

    On problem is the rounding error you will get with (y-x)/n

    In your example: (560-10)/42 = 13.09524
    But, PBP will only see 13. So, at the end of your routine, you will end up with 10 + (42*13) = 556

    You will need to put in one line at after Next QQ:

    Output = y

  6. #6
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Linear acceleration ramp

    Here is another alternative: Vary the period you increment your speed.
    This examply uses PAUSE.
    Code:
    Incr_Time_ms = (1000 * Duration) / (End_Val - Start_Val)
    Current_Val = Start_Val
    Do Until Current_Val = End_Val
       PAUSE Incr_Time_ms 
       Current_Val = Current_Val + 1
    Loop
    What would be ideal is set up a timer and add a value so that it overflows after "Incr_Time_ms". You can then use interrupts, or just poll the flag bit. increment your "Current_Val", clear the flag bit, and then add the value to set up the overflow after "Incr_Time_ms". Wash-Rinse-Repeat until "Current_Val = End_Val"

Members who have read this thread : 2

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