Skip to content

Commit

Permalink
EBB Firmware version 2.5.1 - fixed bug in LM command so that we can u…
Browse files Browse the repository at this point in the history
…se negative values for StepAddInc parameter. Also tweaked 25KHz ISR rate so that it is much closer to 25KHz now.
  • Loading branch information
EmbeddedMan committed Jan 18, 2017
1 parent 29d2472 commit b2b1350
Show file tree
Hide file tree
Showing 22 changed files with 15,885 additions and 5,983 deletions.
Binary file added EBB_firmware/EBBUpdater/EBBUpgraderGUI_v251.exe
Binary file not shown.
447 changes: 447 additions & 0 deletions EBB_firmware/EBBUpdater/EBBUpgraderGUI_v251.tbasic

Large diffs are not rendered by default.

3,055 changes: 3,055 additions & 0 deletions EBB_firmware/EBBUpdater/EBF_v251.hex

Large diffs are not rendered by default.

Binary file added EBB_firmware/Releases/app/EBF_v251.zip
Binary file not shown.
3,055 changes: 3,055 additions & 0 deletions EBB_firmware/Releases/app/EBF_v251/EBF_v251.hex

Large diffs are not rendered by default.

Binary file not shown.
3,265 changes: 3,265 additions & 0 deletions EBB_firmware/Releases/combined/EBF_v251_BL.unified/EBF_v251.unified.hex

Large diffs are not rendered by default.

3,400 changes: 1,699 additions & 1,701 deletions EBB_firmware/app.X/dist/EBBv13_with_bootloader/production/EBF.X.production.map

Large diffs are not rendered by default.

Binary file not shown.
4,280 changes: 2,140 additions & 2,140 deletions EBB_firmware/app.X/dist/EBBv13_with_bootloader/production/app.X.production.hex

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion EBB_firmware/app.X/nbproject/Makefile-genesis.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
#Sun Jan 08 17:35:26 CST 2017
#Wed Jan 18 17:27:41 CST 2017
EBBv13_XC8_with_bootloader.com-microchip-mplab-nbide-toolchainXC8-XC8LanguageToolchain.md5=8ca5a2607d753baa0cc4f860edd494dd
EBBv13_no_bootloader.languagetoolchain.version=3.47
EBBv13_with_bootloader.languagetoolchain.version=3.47
Expand Down
1 change: 1 addition & 0 deletions EBB_firmware/app.X/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/D:/Projects/EggBot_GitHub/EBB_firmware/app.X/source/main.c</file>
<file>file:/D:/Projects/EggBot_GitHub/EBB_firmware/app.X/source/ebb.c</file>
<file>file:/D:/Projects/EggBot_GitHub/EBB_firmware/app.X/source/ebb.h</file>
<file>file:/D:/Projects/EggBot_GitHub/EBB_firmware/app.X/source/UBW.c</file>
Expand Down
2 changes: 1 addition & 1 deletion EBB_firmware/app.X/source/UBW.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const rom char st_LFCR[] = {"\r\n"};
#elif defined(BOARD_EBB_V12)
const rom char st_version[] = {"EBBv12 EB Firmware Version 2.2.1\r\n"};
#elif defined(BOARD_EBB_V13_AND_ABOVE)
const rom char st_version[] = {"EBBv13_and_above EB Firmware Version 2.5.0\r\n"};
const rom char st_version[] = {"EBBv13_and_above EB Firmware Version 2.5.1\r\n"};
#elif defined(BOARD_UBW)
const rom char st_version[] = {"UBW EB Firmware Version 2.2.1\r\n"};
#endif
Expand Down
24 changes: 13 additions & 11 deletions EBB_firmware/app.X/source/ebb.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@
// special case just un-does the change for issue #71 for these
// short moves)
// 2.5.0 01/09/17 - Added LM (low level move) command to allow PC to do all math
// 2.5.1 01/18/17 - Fixed LM command to take negative and positive StepAddIncs
// Fixed 25KHz ISR to be much closer to 25KHz

#include <p18cxxx.h>
#include <usart.h>
Expand Down Expand Up @@ -314,8 +316,8 @@ void high_ISR(void)
{
// Clear the interrupt
PIR1bits.TMR1IF = 0;
TMR1L = TIMER1_L_RELOAD; // Set to 120 for 25KHz ISR fire
TMR1H = TIMER1_H_RELOAD; //
TMR1L = TIMER1_L_RELOAD; // Reload for 25KHz ISR fire

OutByte = CurrentCommand.DirBits;
TookStep = FALSE;
Expand Down Expand Up @@ -395,9 +397,9 @@ void high_ISR(void)
if (CurrentCommand.StepsCounter[0])
{
StepAcc[0] = StepAcc[0] + CurrentCommand.StepAdd[0];
if (StepAcc[0] > 0x80000000)
if (StepAcc[0] & 0x80000000)
{
StepAcc[0] = StepAcc[0] - 0x80000000;
StepAcc[0] = StepAcc[0] & 0x7FFFFFFF;
OutByte = OutByte | STEP1_BIT;
TookStep = TRUE;
CurrentCommand.StepsCounter[0]--;
Expand All @@ -417,9 +419,9 @@ void high_ISR(void)
if (CurrentCommand.StepsCounter[1])
{
StepAcc[1] = StepAcc[1] + CurrentCommand.StepAdd[1];
if (StepAcc[1] > 0x80000000)
if (StepAcc[1] & 0x80000000)
{
StepAcc[1] = StepAcc[1] - 0x80000000;
StepAcc[1] = StepAcc[1] & 0x7FFFFFFF;
OutByte = OutByte | STEP2_BIT;
TookStep = TRUE;
CurrentCommand.StepsCounter[1]--;
Expand Down Expand Up @@ -649,15 +651,15 @@ void EBB_Init(void)
FIFOEmpty = TRUE;

// Set up TMR1 for our 25KHz High ISR for stepping
T1CONbits.RD16 = 0; // Set 8 bit mode
T1CONbits.RD16 = 1; // Set 16 bit mode
T1CONbits.TMR1CS1 = 0; // System clocked from Fosc/4
T1CONbits.TMR1CS0 = 0;
T1CONbits.T1CKPS1 = 1; // Use 1:4 Prescale value
T1CONbits.T1CKPS1 = 0; // Use 1:1 Prescale value
T1CONbits.T1CKPS0 = 0;
T1CONbits.T1OSCEN = 0; // Don't use external osc
T1CONbits.T1SYNC = 0;
TMR1L = TIMER1_L_RELOAD; // Set to 120 for 25KHz ISR fire
TMR1H = TIMER1_H_RELOAD; // (note, unused in 16-bit mode)
TMR1H = TIMER1_H_RELOAD; //
TMR1L = TIMER1_L_RELOAD; // Reload for 25Khz ISR fire

T1CONbits.TMR1ON = 1; // Turn the timer on

Expand Down Expand Up @@ -1187,10 +1189,10 @@ void parse_LM_packet (void)
// Extract each of the values.
extract_number (kULONG, &StepAdd1, kREQUIRED);
extract_number (kLONG, &StepsCounter1, kREQUIRED);
extract_number (kULONG, &StepAddInc1, kREQUIRED);
extract_number (kLONG, &StepAddInc1, kREQUIRED);
extract_number (kULONG, &StepAdd2, kREQUIRED);
extract_number (kLONG, &StepsCounter2, kREQUIRED);
extract_number (kULONG, &StepAddInc2, kREQUIRED);
extract_number (kLONG, &StepAddInc2, kREQUIRED);

// Bail if we got a conversion error
if (error_byte)
Expand Down
16 changes: 10 additions & 6 deletions EBB_firmware/app.X/source/ebb.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,16 @@ typedef struct

// Reload value for TIMER1
// We need a 25KHz ISR to fire, so we take Fosc (48Mhz), divide by 4
// (normal CPU instruction rate of Fosc/4), then use the TIMER1 prescaler
// to divide by 4 again. Then we use a reload value of 120 to give us
// a rate of 48MHz/4/4/120 = 25KHz.
// Note Timer1 is used in 8 bit mode, so H_RELOAD value is not used
#define TIMER1_L_RELOAD (255 - 113) // Note, the 113 is based on tiral and error
#define TIMER1_H_RELOAD (255)
// (normal CPU instruction rate of Fosc/4)
// Then we use a reload value of 480 (0x1E0) to give us
// a rate of 48MHz/4/480 = 25KHz.
// Note that because we can't reload the timer _exactly_ after it fires,
// we have to decrease our 480 value by a few to account for the instructions
// that happen after the timer fires but before we can reload the timer with new
// values.
// The values here are hand tuned for 25KHz ISR operation
#define TIMER1_L_RELOAD (61)
#define TIMER1_H_RELOAD (254)
#define HIGH_ISR_TICKS_PER_MS (25) // Note: computed by hand, could be formula


Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MPLINK 5.00, LINKER
Linker Map File - Created Sun Jan 08 20:56:09 2017
Linker Map File - Created Wed Jan 18 17:27:26 2017

Section Info
Section Type Address Location Size(Bytes)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
#Sun Jan 08 17:35:29 CST 2017
#Wed Jan 18 17:27:41 CST 2017
46J50.languagetoolchain.version=3.47
conf.ids=46J50,45J50
45J50.com-microchip-mplab-nbide-toolchainC18-C18LanguageToolchain.md5=9dcf4e78c5f3f3a1c5abbecc04eb7cbf
Expand Down
5 changes: 4 additions & 1 deletion EBB_firmware/bootloader.X/nbproject/private/private.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
<group>
<file>file:/D:/Projects/EggBot_GitHub/EBB_firmware/bootloader.X/source/main.c</file>
</group>
</open-files>
</project-private>
8 changes: 8 additions & 0 deletions docs/EBBReleaseNotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ <h4>2.5.0 &mdash; 01/14/17</h4>
</ul>
</p>

<h4>2.5.1 &mdash; 01/18/17</h4>
<p>
<ul>
<li>Fixed LM command to take negative and positive StepAddIncs</li>
<li>Fixed 25KHz ISR to be much closer to 25KHz</li>
</ul>
</p>

<p/>
<hr/>
<p/>
Expand Down
74 changes: 68 additions & 6 deletions docs/ebb.html
Original file line number Diff line number Diff line change
Expand Up @@ -718,28 +718,68 @@ <h4><a name="LM"></a> "LM" &mdash; Low level Move</h4>
<li><span style="font-weight: bold;">Execution:</span> Added to FIFO motion queue</li>
<li><span style="font-weight: bold;">Arguments:</span>
<ul>
<li><i>StepAdd1</i> and <i>StepAdd2</i> are unsigned 31 bit integers in the range from 0 to 2147483648. They get added to step accumulator every 40nS.</li>
<li><i>StepsCounter1</i> and <i>StepsCounter2</i> are signed 24 bit integers in the range from -8388607 to 8388607, giving movement distance in steps.</li>
<li><i>StepsAddInc1</i> and <i>StepsAddInc2</i> are signed 32 bit integers in the range from -2147483647 to 2147483647. This value is added to StepsAdd every 40nS.</li>
<li><i>StepAdd1</i> and <i>StepAdd2</i> are unsigned 31 bit integers in the range from 0 to 2147483648. They represent step rates for axis 1 and 2, and get added to each axis' step accumulator every 40nS to determine when steps are taken.</li>
<li><i>StepsCounter1</i> and <i>StepsCounter2</i> are signed 24 bit integers in the range from -8388607 to 8388607, giving movement distance in steps for axis 1 and axis 2.</li>
<li><i>StepsAddInc1</i> and <i>StepsAddInc2</i> are signed 32 bit integers in the range from -2147483647 to 2147483647. These values are added to their respective StepAdd every 40nS and control acceleration or deceleration during a move.</li>
</ul>
<li>
<span style="font-weight: bold;">Description:</span>
<p>
Use this command to make the motors move. Acceleration and deceleration can be performed, and because the parameters are passed directly into motion control system of the EBB, no time is lost doing any math operations or limit checking, so maximum command throughput can be achieved.
</p>
<p>
There is a 32 bit accumulator for each axis. At the beginning of each move, the accumulator is zeroed. Every 40 &mu;S (25 KHz) the <i>StepAdd</i> value is added to the accumulator. Whenever the accumulator is greater than 0x80000000, a step is taken on that axis, and 0x8000000 is subtracted from the accumulator. If the <i>StepAdd</i> value is 2147483648, then a step is taken every 40 &mu;S. If the <i>StepAdd</i> value is 1, then a step is taken every 85899 seconds. If the <i>StepAdd</i> value is 0, then no steps are taken on that axis. (Make sure that at least one axis has non-zero StepAdd and StepsCounter values, or the move will never finish.) Each time a step is taken, the StepsCounter for that axis is decremented. Once both move counters reach zero after a step, the move is considered complete.
There is a 32 bit accumulator for each axis. At the beginning of each move, the accumulator is zeroed. Every 40 &mu;S (25 KHz) the <i>StepAdd</i> value is added to the accumulator. Whenever the accumulator is greater than 0x80000000, a step is taken on that axis, and 0x8000000 is subtracted from the accumulator. For example, if the <i>StepAdd</i> value is 2147483648, then a step is taken every 40 &mu;S. If the <i>StepAdd</i> value is 1, then a step is taken every 85899 seconds. If the <i>StepAdd</i> value is 0, then no steps are taken on that axis. (Make sure that at least one axis has non-zero StepAdd and StepsCounter values, or the move will never finish.) Each time a step is taken, the StepsCounter for that axis is decremented. Once both move counters reach zero after a step has been taken, the move is complete.
</p>
<p>
The sign of <i>StepsAddCounter</i> represents the direction that an axis should turn. The value represents the number of steps that an axis should take for this move.
The sign of <i>StepCounter</i> represents the direction that an axis should turn. The value represents the number of steps that an axis should take for this move.
</p>
<p>
The <i>StepsAddInc</i> value is added to <i>StepsAdd</i> every 40 &mu;S. It can be positive or negative. This is used to cause an axis to accelerate or decelerate during a move.
Note that because you independently specify a step rate and a number of steps for each axis, it is easy to have the two axes finish stepping at different times. Because the move doesn't end until both step counters are zero, this means that at the end of the move, one axis may not be stepping at all. If you don't want this to happen, be careful to compute your parameters correctly so that both axes step continuously throughout the whole move.
</p>
<p>
The equation for computing StepAdd given a number of steps (StepCounter) and a duration is as follows (where Duration is the length of the move in milliseconds):
</p>
<p>
StepAdd = (StepCounter << 31)/(25 * Duration)
</p>
<p>
This division should be performed as a floating point operation, or at least as a 64 bit divide, since StepCounter shifted left by 31 bits may take up to 63 bits.
</p>
<p>
The equation for computing StepAdd given a step rate (StepRate) in Hz is:
</p>
<p>
StepAdd = (2^31 * StepRate)/(25000)
</p>
<p>
The <i>StepsAddInc</i> value is added to <i>StepAdd</i> every 40 &mu;S. It can be positive or negative. This is used to cause an axis to accelerate or decelerate during a move.
</p>
<p>
To compute the StepAddInc values, calculate the desired starting and ending step speed using the above StepAdd formula, then divide the difference up by the number of 25 kHz ISRs that will happen during the move. See the Move Time formula below to get the amount of time the move will take.
</p>
<p>
To compute the total time of a move involving acceleration/deceleration (where StepsAddInc is non-zero), use the average step rate. For example, if we have a starting step rate (in Hz) of SR1 and an ending step rate of SR2, and the move is Steps steps long:
</p>
<p>
Move Time = Steps/((SR1 + SR2)/2)
</p>
<p>
Example: Let's say we wanted to start moving an axis at 45 steps/second, and end at 250 steps/second, and go for a total of 60 steps. By the above formulas, we know that our starting StepAdd is 3865470, our ending StepAdd is 21474836, and our Move Time is 60/((45 + 250)/2) = 0.4068 seconds. So we want to get from a StepAdd of 3865470 at the beginning of the move to a StepAdd of 21474836 at the end, so we need to add a total of (21474836 - 3865470) = 17609366 to our initial StepAdd over the course of the move. Because the move takes 0.4068 seconds, and we will be adding StepsAddInc to StepAdd 25000 times/second, we divide 17609366 by the total number of adds (0.4068 * 25000) to get 17609366/(0.4068 * 25000) = 1732. So if we use a StepsAddInc of 1732, then we will get from 45 steps/second to 250 steps/second in 0.4068 seconds and 60 steps. You would then use the following LM command:
</p>
<p>
<code>LM,3865470,60,1732,0,0,0</code>
</p>
<p>
Notice that we're only using axis 1 in this example. You can of course use both axes at the same time, but you need to be careful that the times for each axis match up or you won't be drawing a straight line (since one axis would then finish before the other).
</p>
<p>
This command is a low level version of the <code>SM</code> and <code>XM</code> commands. The EBB firmware does no limit checking on the parameters, it simply parses them (converts them from human readable ASCII to binary) and then pushes them into the motion FIFO. See <a href="https://github.com/evil-mad/EggBot/issues/73">GitHub issue #73</a> for more information.
</p>
</li>
<li>
<span style="font-weight: bold;">Example:</span> <code>LM,3865481,1000,0,0,0,0\r</code>
This simple example will move axis 1 at a constant speed of 45 steps/second for 1000 steps. Axis 2 does not move.
</li>
<li>
<span style="font-weight: bold;">Example:</span> <code>LM,85899346,10,0,17179869,2,0\r</code>
This example will cause a 10ms long move, where axis 1 takes a step every 1ms, and axis 2 takes a step every 5ms. Axis 1 will step for 10 steps, and axis 2 will step for 2 steps, and they will both finish together at the end of the 10 ms. No accel or decel on either axis.
Expand All @@ -748,6 +788,28 @@ <h4><a name="LM"></a> "LM" &mdash; Low level Move</h4>
<span style="font-weight: bold;">Example:</span> <code>LM,85899346,10,0,85899346,2,0\r</code>
This example will step both axis at a 1ms/step rate, and axis 1 will step for 10 steps and axis 2 will step for 2 steps. Note that you normally don't want this - you normally want both axis to be stepping for the whole length of the move. No accel or decel on either axis.
</li>
<li>
<span style="font-weight: bold;">Example:</span> <code>LM,17179869,6,0,57266231,20,0\r</code>
This example will create a 30ms long move, with axis 1 stepping 6 times and axis 2 stepping 20 times. No accel or decel on either axis.
</li>
<li>
<span style="font-weight: bold;">Example:</span> <code>LM,42949573,50,25769804,0,0,0\r</code>
This example will start with axis 1 stepping at 500 steps/second, end with axis 1 stepping at 800 steps/second, and will take 50 steps. Axis 2 will not move. The move will take 77ms to complete.
</li>
<li>
<span style="font-weight: bold;">Example:</span> <code>LM,17179869,75,-687,8589934,75,687\r</code>
This example will start with axis 1 at 200 steps/second, and axis 2 at 100 steps/second. Over the course of 75 steps each, they will end at a speed of 100 steps/second for axis 1 (note this is deceleration) and 200 steps/second for axis 2. The move will take 500ms.
</li>
<li>
<span style="font-weight: bold;">Version History:</span>
Added in v2.5.0
<p>
In v2.5.0, this command had a bug in where it would not accept negative StepAddInc. This meant no deceleration was possible.
</p>
<p>
In v2.5.1 and beyond, StepAddInc can be negative or positive and will properly decelerate or accelerate the axis.
</p>
</li>
</ul>

<hr class="short" />
Expand Down

0 comments on commit b2b1350

Please sign in to comment.