Each User Thread Stack is located in precious single cycle (5ns) internal memory and is 2 KBytes in length. Care should be used to limit stack usage. Overflowing the stack will likely cause KFLOP to crash. Local variables (defined within functions) and passed function parameters reside on the stack. Large variables should be defined as Global Variables or in the 8 MByte [http://www.dynomotion.com/wiki/index.php?title=KFLOP_C_Programs#Gather_Buffer Gather Buffer]
==Axis Homing and Indexing==
KFLOP doesn't provide any built in mechanism for homing. Instead a homing sequence can be performed in any manner desired using a KFLOP C Program. A number of examples are included. A typical sequence might be to:
# Jog in some direction
# wait for an input to change
# stop
# wait until fully stopped
# Zero
For standard homing the example function '''SimpleHomeIndexFunction.c''' can be used. The example moves to a proximity sensor, optionally reverses to an Index Pulse, moves a fixed distance, then zeros the Axis. Specify -1 for the Index Bit number if no Index pulse exists or is not desired to be used. Below is an example call to the Function showing the parameters to be specified:
<pre class="brush:c"> result = SimpleHomeIndexFunction(2, // axis number to home
1000.0, // speed to move toward home
-1, // direction to move toward home (+1 or -1)
138, // limit bit number to watch for
0, // limit polarity to wait for (1 or 0)
100.0, // speed to move while searching for index
-1, // index bit number to watch for (use -1 for none)
1, // index polarity to wait for (1 or 0)
5000); // amount to move inside limits
</pre>
The example '''SimpleHomeIndexFunctionTest.c''' shows an example of homing 3 axes sequentially.
Note that because homing is all performed in software any IO bits can be used. Some of the documentation lists IO bits to be used but these are only suggestions.
Index pulses from encoders are typically differential signals. The differential index pulse signal can be connected to any unused A or B differential input. Or one of the + or - differential signals can be connected to a single ended digital input. Note that KFLOP's 3.3V inputs should not be driven hard (> 10ma) above 3.8V. Most 5V differential drivers do not do this.
KFLOP User C Programs are given [http://dynomotion.com/Help/Multitasking.htm CPU Time Slices] to execute so they are guaranteed to execute on a periodic basis. With only 1 User Thread running they are guaranteed to execute every 180us. So any index pulse longer that this time period will never be missed. Also with a proximity sensor the change in state will be guaranteed to be detected withing this time period.
==Gather Buffer==