LP5562-RK
Public Member Functions | Protected Attributes | Static Protected Attributes
LP5562Program Class Reference

Class for programming the LP5562 directly. More...

#include <LP5562-RK.h>

Public Member Functions

 LP5562Program ()
 Construct a programming object. This is the program for a single engine. More...
 
virtual ~LP5562Program ()
 Destructor.
 
bool addCommandWait (bool prescale, uint8_t stepTime, int atInst=-1)
 Add a wait command (ramp/wait with increment of 0) More...
 
bool addCommandRamp (bool prescale, uint8_t stepTime, bool decrease, uint8_t numSteps, int atInst=-1)
 Add a ramp. More...
 
bool addCommandSetPWM (uint8_t level, int atInst=-1)
 Set a specific PWM level. More...
 
bool addCommandGoToStart (int atInst=-1)
 Go to start of program (instruction 0) More...
 
bool addCommandBranch (uint8_t loopCount, uint8_t stepNum, int atInst=-1)
 Loop and branch. More...
 
bool addCommandEnd (bool generateInterrupt, bool setPWMto0, int atInst=-1)
 End program (instead of repeating) More...
 
bool addCommandTriggerSend (uint8_t engineMask, int atInst=-1)
 Send a trigger to other engines. Used to synchronize the three engines. More...
 
bool addCommandTriggerWait (uint8_t engineMask, int atInst=-1)
 Wait for a trigger from another engine. Used to synchronize the three engines. More...
 
bool addCommand (uint16_t cmd, int atInst=-1)
 Low level addCommand that takes a specific opcode. Normaly you'd use the high leve interface. More...
 
bool addDelay (unsigned long milliseconds)
 Add a delay in milliseconds. More...
 
void clear ()
 Clear the current program.
 
uint8_t getStepNum () const
 Get the current step number. More...
 
const uint16_t * getInstructions () const
 Get access to the instruction buffer (16x 16-bit instruction words)
 

Protected Attributes

uint8_t nextInst = 0
 The next instruction to write to, or after all have been written, the number of instructions in this program. Will always be 0 <= nextInst <= MAX_INSTRUCTIONS.
 
uint16_t instructions [MAX_INSTRUCTIONS]
 The array of program instructions. Each instruction is a 16-bit word.
 

Static Protected Attributes

static const size_t MAX_INSTRUCTIONS = 16
 Maximum number of instructions is 16, imposed by the hardware.
 

Detailed Description

Class for programming the LP5562 directly.

You'll need to read the datasheet to understand this, probably. There are a bunch of hardware limitations and a very small program size of 16 instructions to work with.

Constructor & Destructor Documentation

◆ LP5562Program()

LP5562Program::LP5562Program ( )

Construct a programming object. This is the program for a single engine.

This object is small (36 bytes) so it's OK to allocate one on the stack.

Member Function Documentation

◆ addCommand()

bool LP5562Program::addCommand ( uint16_t  cmd,
int  atInst = -1 
)

Low level addCommand that takes a specific opcode. Normaly you'd use the high leve interface.

Parameters
cmd16-bit program instruction word.
atInst(can omit) Normally instructions are added at the current end of the program but you can use the atInst parameter to set a specific instruction (0 - 15) in the program.

◆ addCommandBranch()

bool LP5562Program::addCommandBranch ( uint8_t  loopCount,
uint8_t  stepNum,
int  atInst = -1 
)

Loop and branch.

Parameters
loopCountThe number of times to loop (1 - 63)
stepNumThe step number to go to when looping (0 - 15)
atInst(can omit) Normally instructions are added at the current end of the program but you can use the atInst parameter to set a specific instruction (0 - 15) in the program.

After loopCount is reached, then the next statement is executed.

Loops can be nested for loops larger than 63.

One common thing is to put a wait in a loop, which allows you to wait up to 62 seconds.

◆ addCommandEnd()

bool LP5562Program::addCommandEnd ( bool  generateInterrupt,
bool  setPWMto0,
int  atInst = -1 
)

End program (instead of repeating)

Parameters
generateInterruptGenerate a software interrupt when reached if this parameter is true
setPWMto0If true, set the PWM to 0. If false, leave it unchanged.
atInst(can omit) Normally instructions are added at the current end of the program but you can use the atInst parameter to set a specific instruction (0 - 15) in the program.

This puts the engine into HOLD mode and stops execution of this engine.

◆ addCommandGoToStart()

bool LP5562Program::addCommandGoToStart ( int  atInst = -1)

Go to start of program (instruction 0)

Parameters
atInst(can omit) Normally instructions are added at the current end of the program but you can use the atInst parameter to set a specific instruction (0 - 15) in the program.

This opcode is 0x0000, which is also what the uninitialize program bytes are set to. So as long as your program is 15 or fewer instructions, you don't need to add this to make your program auto-repeat.

◆ addCommandRamp()

bool LP5562Program::addCommandRamp ( bool  prescale,
uint8_t  stepTime,
bool  decrease,
uint8_t  numSteps,
int  atInst = -1 
)

Add a ramp.

Parameters
prescalefalse = 0.49 ms cycle time; true = 15.6 ms cycle time
stepTimeWait this this many cycles (1 - 63)
decreasefalse = step up, true = step down
numStepsNumber of times the PWM is increased by 1.
atInst(can omit) Normally instructions are added at the current end of the program but you can use the atInst parameter to set a specific instruction (0 - 15) in the program.

Step times vary depending on prescale. With prescale = false, .49 ms to 7.35 ms. With prescale = true, 15.6 ms to 982.8 ms.

The starting and ending point of the ramp depend on the current PWM value when you start, when you are incrementing or decrementing, and the number of steps.

◆ addCommandSetPWM()

bool LP5562Program::addCommandSetPWM ( uint8_t  level,
int  atInst = -1 
)

Set a specific PWM level.

Parameters
levelThe level (0 = off, 255 = full brightness)
atInst(can omit) Normally instructions are added at the current end of the program but you can use the atInst parameter to set a specific instruction (0 - 15) in the program.

◆ addCommandTriggerSend()

bool LP5562Program::addCommandTriggerSend ( uint8_t  engineMask,
int  atInst = -1 
)

Send a trigger to other engines. Used to synchronize the three engines.

Parameters
engineMaskA mask of the engines to send to. Logical OR the values MASK_ENGINE_1, MASK_ENGINE_2, and MASK_ENGINE_3. You will only send to one or two, you should not send to yourself!
atInst(can omit) Normally instructions are added at the current end of the program but you can use the atInst parameter to set a specific instruction (0 - 15) in the program.

When you send a trigger, this instruction will block until the engines you sent to have hit a wait instruction. It will work if they hit the wait before you send, as well.

◆ addCommandTriggerWait()

bool LP5562Program::addCommandTriggerWait ( uint8_t  engineMask,
int  atInst = -1 
)

Wait for a trigger from another engine. Used to synchronize the three engines.

Parameters
engineMaskA mask of the engines to wait on. MASK_ENGINE_1, MASK_ENGINE_2, and MASK_ENGINE_3 can be logically ORed together. You should not wait on your own engine. In most cases you should have one engine be the trigger sender and wait on the two other engines since you cannot simultaneously send and wait.
atInst(can omit) Normally instructions are added at the current end of the program but you can use the atInst parameter to set a specific instruction (0 - 15).

◆ addCommandWait()

bool LP5562Program::addCommandWait ( bool  prescale,
uint8_t  stepTime,
int  atInst = -1 
)
inline

Add a wait command (ramp/wait with increment of 0)

Parameters
prescalefalse = 0.49 ms cycle time; true = 15.6 ms cycle time
stepTimeWait this this many cycles (1 - 63)
atInst(can omit) Normally instructions are added at the current end of the program but you can use the atInst parameter to set a specific instruction (0 - 15) in the program.

Wait times vary depending on prescale. With prescale = false, .49 ms to 7.35 ms. With prescale = true, 15.6 ms to 982.8 ms. You can make even longer wait times by putting a wait in a loop. Since a loop can be executed up to 63 times, you can get a 62 second delay.

◆ addDelay()

bool LP5562Program::addDelay ( unsigned long  milliseconds)

Add a delay in milliseconds.

Parameters
millisecondsThe number of milliseconds to delay (1 - 61916).

There is no atInst option for this method because depending on the delay, it may add two instructions: a wait (for up to 1000 milliseconds), or a wait and a loop. Since it has a variable number of instructions, it can't be inserted into arbitrary code, only added at the end.

When the delay is > 1000 milliseconds, the resolution is 1 second.

◆ getStepNum()

uint8_t LP5562Program::getStepNum ( ) const
inline

Get the current step number.

Use this before you add a new command (like addCommandSetPWM) to remember the step number you are about to write. This can be used to overwrite the instruction using the atInst optional parameter.

This is most commonly done so you can modify a program that's run on multiple engines with different PWM values.

Also used to get the number of instructions after the last command has been written.


The documentation for this class was generated from the following files: