micros() in irq is suspicous. Some optomization of stepper parameters. Comments.
This commit is contained in:
@@ -51,12 +51,25 @@ void StepGen::handleStepper(void)
|
|||||||
|
|
||||||
actPos(timerStepPosition / double(stepsPerMM));
|
actPos(timerStepPosition / double(stepsPerMM));
|
||||||
double diffPosition = reqPos() - actPos();
|
double diffPosition = reqPos() - actPos();
|
||||||
// Wild "tone" kludge
|
#if 1
|
||||||
if (abs(diffPosition) > 0.0005) // 60 mm/min = 0.001 mm/ms
|
// Wild "tone" kludge. map() function
|
||||||
|
#define SPEED_MIN 0.00005
|
||||||
|
#define SPEED_MAX 0.0005
|
||||||
|
#define FACT_LOW 1.0
|
||||||
|
#define FACT_HIGH 20.0
|
||||||
|
if (abs(diffPosition) < SPEED_MIN) // 60 mm/min = 0.001 mm/ms
|
||||||
{
|
{
|
||||||
pwmCycleTime = 10 * StepGen::sync0CycleTime;
|
pwmCycleTime = FACT_LOW * StepGen::sync0CycleTime;
|
||||||
}
|
}
|
||||||
|
else if (abs(diffPosition) > SPEED_MAX) // 60 mm/min = 0.001 mm/ms
|
||||||
|
{
|
||||||
|
pwmCycleTime = FACT_HIGH * StepGen::sync0CycleTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pwmCycleTime = (FACT_LOW + (FACT_HIGH - FACT_LOW) * (abs(diffPosition) - SPEED_MIN) / (SPEED_MAX - SPEED_MIN)) * StepGen::sync0CycleTime;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
uint64_t fre = abs(diffPosition) * stepsPerMM * 1000000 / double(pwmCycleTime); // Frequency needed
|
uint64_t fre = abs(diffPosition) * stepsPerMM * 1000000 / double(pwmCycleTime); // Frequency needed
|
||||||
if (fre > maxFreq) // Only do maxFre
|
if (fre > maxFreq) // Only do maxFre
|
||||||
{
|
{
|
||||||
@@ -68,9 +81,8 @@ void StepGen::handleStepper(void)
|
|||||||
// Will be picked up by the timer_CB and the timer is reloaded.
|
// Will be picked up by the timer_CB and the timer is reloaded.
|
||||||
timerNewEndStepPosition = pulsesAtEndOfCycle;
|
timerNewEndStepPosition = pulsesAtEndOfCycle;
|
||||||
|
|
||||||
if (!timerIsRunning) // no timer isn't running. start it here
|
if (!timerIsRunning) // Timer isn't running. Start it here
|
||||||
{
|
{
|
||||||
// Start the timer
|
|
||||||
int32_t steps = pulsesAtEndOfCycle - timerStepPosition; // Pulses to go + or -
|
int32_t steps = pulsesAtEndOfCycle - timerStepPosition; // Pulses to go + or -
|
||||||
if (steps != 0)
|
if (steps != 0)
|
||||||
{
|
{
|
||||||
@@ -93,8 +105,8 @@ void StepGen::timerCB()
|
|||||||
timerStepPosition += timerStepDirection; // The step that was just completed
|
timerStepPosition += timerStepDirection; // The step that was just completed
|
||||||
if (timerNewEndStepPosition != 0) // Are we going to reload?
|
if (timerNewEndStepPosition != 0) // Are we going to reload?
|
||||||
{
|
{
|
||||||
// Input for reload is timerNewEndStepPosition and timerNewEndTime
|
// Input for reload is timerNewEndStepPosition
|
||||||
// The timer has current position and current time and from this
|
// The timer has current position and from this
|
||||||
// can set new frequency and new endtarget for steps
|
// can set new frequency and new endtarget for steps
|
||||||
MyTim->pause(); // We are not at stop, let's stop it
|
MyTim->pause(); // We are not at stop, let's stop it
|
||||||
int32_t steps = timerNewEndStepPosition - timerStepPosition;
|
int32_t steps = timerNewEndStepPosition - timerStepPosition;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
|
|||||||
Obj.StepGenOut1.ActualPosition = Step1.actPos();
|
Obj.StepGenOut1.ActualPosition = Step1.actPos();
|
||||||
Obj.StepGenOut2.ActualPosition = Step2.actPos();
|
Obj.StepGenOut2.ActualPosition = Step2.actPos();
|
||||||
|
|
||||||
uint32_t dTim = nowTime - thenTime; // Debug. Getting jitter over the last 200 microseconds
|
uint32_t dTim = nowTime - thenTime; // Debug. Getting jitter over the last 200 milliseconds
|
||||||
Tim.push(dTim);
|
Tim.push(dTim);
|
||||||
uint32_t max_Tim = 0, min_Tim = UINT32_MAX;
|
uint32_t max_Tim = 0, min_Tim = UINT32_MAX;
|
||||||
for (decltype(Tim)::index_t i = 0; i < Tim.size(); i++)
|
for (decltype(Tim)::index_t i = 0; i < Tim.size(); i++)
|
||||||
@@ -119,19 +119,19 @@ void loop(void)
|
|||||||
{
|
{
|
||||||
if (serveIRQ)
|
if (serveIRQ)
|
||||||
{
|
{
|
||||||
|
nowTime = micros();
|
||||||
DIG_process(DIG_PROCESS_WD_FLAG | DIG_PROCESS_OUTPUTS_FLAG |
|
DIG_process(DIG_PROCESS_WD_FLAG | DIG_PROCESS_OUTPUTS_FLAG |
|
||||||
DIG_PROCESS_APP_HOOK_FLAG | DIG_PROCESS_INPUTS_FLAG);
|
DIG_PROCESS_APP_HOOK_FLAG | DIG_PROCESS_INPUTS_FLAG);
|
||||||
serveIRQ = 0;
|
serveIRQ = 0;
|
||||||
ESCvar.PrevTime = ESCvar.Time;
|
ESCvar.PrevTime = ESCvar.Time;
|
||||||
}
|
}
|
||||||
uint32_t dTime=micros()-nowTime;
|
uint32_t dTime = micros() - nowTime;
|
||||||
if ((dTime > 100 && dTime < 800) || dTime > 1500) // Don't run ecat_slv_poll when expecting to server interrupt
|
if ((dTime > 200 && dTime < 500) || dTime > 1500) // Don't run ecat_slv_poll when expecting to serve interrupt
|
||||||
ecat_slv_poll();
|
ecat_slv_poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sync0Handler(void)
|
void sync0Handler(void)
|
||||||
{
|
{
|
||||||
nowTime = micros();
|
|
||||||
serveIRQ = 1;
|
serveIRQ = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user