Replaced runningaverage (uses malloc) with CircularBuffer
This commit is contained in:
@@ -22,4 +22,3 @@ build_flags = -Wl,--no-warn-rwx-segment
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
SPI
|
SPI
|
||||||
rlogiacco/CircularBuffer
|
rlogiacco/CircularBuffer
|
||||||
robtillaart/RunningAverage
|
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ void indexPulseEncoderCB1(void)
|
|||||||
encCnt++;
|
encCnt++;
|
||||||
Encoder1.indexPulse();
|
Encoder1.indexPulse();
|
||||||
}
|
}
|
||||||
#include <RunningAverage.h>
|
// #include <RunningAverage.h>
|
||||||
RunningAverage irqServeDelays(1000); // To get the max delay of the irq serve time over the last second
|
// RunningAverage irqServeDelays(1000); // To get the max delay of the irq serve time over the last second
|
||||||
|
CircularBuffer<uint16_t, 1000> irqServeDelays;
|
||||||
|
|
||||||
#include "StepGen3.h"
|
#include "StepGen3.h"
|
||||||
StepGen3 *Step = 0;
|
StepGen3 *Step = 0;
|
||||||
@@ -84,11 +85,17 @@ void handleStepper(void)
|
|||||||
oldIrqTime = irqTime;
|
oldIrqTime = irqTime;
|
||||||
|
|
||||||
uint32_t diffT = longTime.extendTime(micros()) - irqTime; // Time from interrupt was received by isr
|
uint32_t diffT = longTime.extendTime(micros()) - irqTime; // Time from interrupt was received by isr
|
||||||
irqServeDelays.add(diffT);
|
irqServeDelays.push(diffT);
|
||||||
if (irqServeDelays.bufferIsFull()) // Do max calcs, just waiting a second
|
if (irqServeDelays.isFull()) // Do max calcs, just waiting a second
|
||||||
{
|
{
|
||||||
uint16_t maxInBuffer = irqServeDelays.getMaxInBuffer();
|
uint16_t maxInBuffer = 0;
|
||||||
if (maxIrqServeTime > maxInBuffer) // Reduce by one, slowly eating up excess time
|
using index_t = decltype(irqServeDelays)::index_t;
|
||||||
|
for (index_t i = 0; i < irqServeDelays.size(); i++)
|
||||||
|
{
|
||||||
|
if (maxInBuffer < irqServeDelays[i])
|
||||||
|
maxInBuffer = irqServeDelays[i];
|
||||||
|
}
|
||||||
|
if (maxIrqServeTime > maxInBuffer) // Reduce by one, slowly eating up excess time
|
||||||
maxIrqServeTime--;
|
maxIrqServeTime--;
|
||||||
if (maxIrqServeTime < maxInBuffer)
|
if (maxIrqServeTime < maxInBuffer)
|
||||||
maxIrqServeTime = maxInBuffer;
|
maxIrqServeTime = maxInBuffer;
|
||||||
@@ -180,8 +187,6 @@ void setup(void)
|
|||||||
pinMode(PC9, OUTPUT); // Step Z
|
pinMode(PC9, OUTPUT); // Step Z
|
||||||
pinMode(PC10, OUTPUT); // Dir Z
|
pinMode(PC10, OUTPUT); // Dir Z
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
baseTimer = new HardwareTimer(TIM11); // The base period timer
|
baseTimer = new HardwareTimer(TIM11); // The base period timer
|
||||||
setFrequencyAdjustedMicrosSeconds(baseTimer, BASE_PERIOD / 1000);
|
setFrequencyAdjustedMicrosSeconds(baseTimer, BASE_PERIOD / 1000);
|
||||||
// baseTimer->setOverflow(BASE_PERIOD / 1000, MICROSEC_FORMAT); // Or the line above, This one is uncalibrated
|
// baseTimer->setOverflow(BASE_PERIOD / 1000, MICROSEC_FORMAT); // Or the line above, This one is uncalibrated
|
||||||
|
|||||||
Reference in New Issue
Block a user