LP5562-RK
|
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. | |
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.
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.
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.
cmd | 16-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. |
bool LP5562Program::addCommandBranch | ( | uint8_t | loopCount, |
uint8_t | stepNum, | ||
int | atInst = -1 |
||
) |
Loop and branch.
loopCount | The number of times to loop (1 - 63) |
stepNum | The 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.
bool LP5562Program::addCommandEnd | ( | bool | generateInterrupt, |
bool | setPWMto0, | ||
int | atInst = -1 |
||
) |
End program (instead of repeating)
generateInterrupt | Generate a software interrupt when reached if this parameter is true |
setPWMto0 | If 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.
bool LP5562Program::addCommandGoToStart | ( | int | atInst = -1 | ) |
Go to start of program (instruction 0)
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.
bool LP5562Program::addCommandRamp | ( | bool | prescale, |
uint8_t | stepTime, | ||
bool | decrease, | ||
uint8_t | numSteps, | ||
int | atInst = -1 |
||
) |
Add a ramp.
prescale | false = 0.49 ms cycle time; true = 15.6 ms cycle time |
stepTime | Wait this this many cycles (1 - 63) |
decrease | false = step up, true = step down |
numSteps | Number 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.
bool LP5562Program::addCommandSetPWM | ( | uint8_t | level, |
int | atInst = -1 |
||
) |
Set a specific PWM level.
level | The 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. |
bool LP5562Program::addCommandTriggerSend | ( | uint8_t | engineMask, |
int | atInst = -1 |
||
) |
Send a trigger to other engines. Used to synchronize the three engines.
engineMask | A 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.
bool LP5562Program::addCommandTriggerWait | ( | uint8_t | engineMask, |
int | atInst = -1 |
||
) |
Wait for a trigger from another engine. Used to synchronize the three engines.
engineMask | A 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). |
|
inline |
Add a wait command (ramp/wait with increment of 0)
prescale | false = 0.49 ms cycle time; true = 15.6 ms cycle time |
stepTime | Wait 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.
bool LP5562Program::addDelay | ( | unsigned long | milliseconds | ) |
Add a delay in milliseconds.
milliseconds | The 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.
|
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.