Ramp up down? Code ideas.


Results 1 to 4 of 4

Threaded View

  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
    0FFF.......................0000------FFFF..................F000


    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.

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