Ramp up down? Code ideas.

+ Reply to Thread
Results 1 to 4 of 4
  1. #1

    Default Ramp up down? Code ideas.

    Code idea help please..

    I have a program that uses a 16 bit variable number between 0-4095 $000-FFF to control electric motor power.

    It also uses a flag 'F' (high nibble) in that same 16 bit variable to indicate assist or regeneration.

    So hex...

    0(000) would be 0% Assist and 0(FFF) would be 100% Assist
    F(FFF) would be 0% Regen and F(000) would be 100% Regeneration

    Assist 100%..............0%------- 0%................ 100% Regen

    Now I want to gently/smoothly swap from one to the other.

    So lets assume my OEM motor controller wants some assist but I am currently overriding it with some regeneration.

    Actual say F(999) Regenerating
    Desired by controller 0(345) Assist

    I want to change the actual in steps until it matches the desired and passes smoothly through the changeover.
    So in other words in the example above it ramps down the regeneration until it passes the null zone then (changes the flag nibble) and then ramps up the assist until it matches the desired.

    Note the code needs to be able to cope with any combination of assist/regen actual and desired values.
    So it could be assisting (Actual) and I want to go back to regen (Desired) or vice versa.
    Or it could be assisting at say 10% but the OEM wants 90% assist or vice versa etc etc etc

    Basically when I stop overriding the motor controller I want a smooth transition back to what the OEM is requesting.
    At the moment my code just goes instantly from in the worst case scenario 100% assist to 100% regen!!!
    That's a bit of a shock to the drivetrain....

    The control variable is generated every 10ms and I would like the revert to normal (desired) process to take about 1 second

    So I'm looking for code ideas as I seem to be stuck in loop staring at the screen.

    Note the (desired) target can change at any time during the revert process.
    So it has to be able to deal with moving goalposts.

    Getting actual to within say +/-10 or even 50 of desired would likely be good enough that the ramp routine could then abort and relinquish control.
    Last edited by retepsnikrep; - 24th November 2023 at 09:28.

  2. #2
    Join Date
    Nov 2005
    Bombay, India

    Did you find this post helpful? Yes | No

    Default Re: Ramp up down? Code ideas.

    Consider this.

    The error between expected and actual output be summed every second in sE

    Now, decide the correction time as Ti or error Integration time in seconds. The aim is to apply the full sE in Ti seconds from the time of Error inception.

    The fraction of E that gets applied to regen output will be sE / Ti

    sE will be reduced by the above fraction.

    To prevent a lockup condition from which your control cannot recover, you will need to put limits (both +ve and -ve) on the value of sE so that it doesn't do fancy things like rollover on addition

    The output will change at the rate you specified.

    Good luck with that and Happy thanksgiving
    Last edited by Jerson; - 25th November 2023 at 02:55. Reason: wording

  3. #3
    Join Date
    May 2013

    Did you find this post helpful? Yes | No

    Default Re: Ramp up down? Code ideas.

    if you were to use proper complementary numbers to represent your controller power then

    F(999) could be -999 and 0(345) would be 345

    ie actual = -999 desired = 345
    means desired is -1344 below required
    to get there in 100 x 10mS steps [1 second] just add 13.4 for the next 100 generations

    to go back

    means desired is 1344 over required

    to get there in 100 x 10mS steps [1 second] just subtract 13.4 for the next 100 generations

    the controller can figure if its assist or regen simply by testing bit.15

    by rounding down the incrementor you will easily get within 10% will no fuss
    never underestimate the beauty of unsigned subtractions with complementary numbers

    to convert from pos to negative number n=~n+1
    to convert from negative to pos number n=~n+1

    ps never try to divide or multiply a negative number
    inc = abs(difference)/100
    Last edited by richard; - 25th November 2023 at 05:47.
    Warning I'm not a teacher

  4. #4

    Did you find this post helpful? Yes | No

    Default Re: Ramp up down? Code ideas.

    Thanks for those.

Similar Threads

  1. Linear acceleration ramp
    By pxidr84 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th May 2012, 06:27
  2. Code optomization ideas...(link)
    By Heckler in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th February 2012, 16:07
  3. Making code more efficient, any ideas please?
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th July 2011, 13:28
  4. Make an acceleration/deceleration ramp : any ideas?
    By pxidr84 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 3rd April 2011, 23:19
  5. Ideas on ir-code for dimmer
    By tirithen in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th February 2009, 23:22

Members who have read this thread : 13

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