Kludge with 'tone' of steppers. Gives ferror, but nice tone
This commit is contained in:
@@ -26,7 +26,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static uint32_t sync0CycleTime;
|
static uint32_t sync0CycleTime;
|
||||||
static uint32_t pwmCycleTime;
|
volatile uint32_t pwmCycleTime;
|
||||||
|
|
||||||
StepGen(TIM_TypeDef *Timer, uint32_t timerChannel, PinName stepPin, uint8_t dirPin, void irq(void));
|
StepGen(TIM_TypeDef *Timer, uint32_t timerChannel, PinName stepPin, uint8_t dirPin, void irq(void));
|
||||||
void reqPos(double_t pos);
|
void reqPos(double_t pos);
|
||||||
|
|||||||
@@ -47,12 +47,18 @@ void StepGen::handleStepper(void)
|
|||||||
{
|
{
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
pwmCycleTime = StepGen::sync0CycleTime;
|
||||||
|
|
||||||
actPos(timerStepPosition / double(stepsPerMM));
|
actPos(timerStepPosition / double(stepsPerMM));
|
||||||
double diffPosition = reqPos() - actPos();
|
double diffPosition = reqPos() - actPos();
|
||||||
|
// Wild "tone" kludge
|
||||||
|
if (abs(diffPosition) > 0.0005) // 60 mm/min = 0.001 mm/ms
|
||||||
|
{
|
||||||
|
pwmCycleTime = 10 * StepGen::sync0CycleTime;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
double maxDist = maxFreq / stepsPerMM * pwmCycleTime / 1000000.0 * (diffPosition > 0 ? 1 : -1);
|
double maxDist = maxFreq / stepsPerMM * pwmCycleTime / 1000000.0 * (diffPosition > 0 ? 1 : -1);
|
||||||
reqPos(actualPosition + maxDist);
|
reqPos(actualPosition + maxDist);
|
||||||
@@ -72,7 +78,7 @@ void StepGen::handleStepper(void)
|
|||||||
digitalWrite(dirPin, sgn);
|
digitalWrite(dirPin, sgn);
|
||||||
timerStepDirection = steps > 0 ? 1 : -1;
|
timerStepDirection = steps > 0 ? 1 : -1;
|
||||||
timerStepPositionAtEnd = pulsesAtEndOfCycle; // Current Position
|
timerStepPositionAtEnd = pulsesAtEndOfCycle; // Current Position
|
||||||
double_t freqf = abs(steps) * (1e6 / double(pwmCycleTime));
|
float_t freqf = abs(steps) * (1e6 / float(pwmCycleTime));
|
||||||
uint32_t freq = uint32_t(freqf);
|
uint32_t freq = uint32_t(freqf);
|
||||||
MyTim->setMode(timerChan, TIMER_OUTPUT_COMPARE_PWM2, stepPin);
|
MyTim->setMode(timerChan, TIMER_OUTPUT_COMPARE_PWM2, stepPin);
|
||||||
MyTim->setOverflow(freq, HERTZ_FORMAT);
|
MyTim->setOverflow(freq, HERTZ_FORMAT);
|
||||||
@@ -96,7 +102,7 @@ void StepGen::timerCB()
|
|||||||
{
|
{
|
||||||
uint8_t sgn = steps > 0 ? HIGH : LOW;
|
uint8_t sgn = steps > 0 ? HIGH : LOW;
|
||||||
digitalWrite(dirPin, sgn);
|
digitalWrite(dirPin, sgn);
|
||||||
double_t freqf = abs(steps) * (1e6 / double(pwmCycleTime));
|
float_t freqf = abs(steps) * (1e6 / float(pwmCycleTime));
|
||||||
uint32_t freq = uint32_t(freqf);
|
uint32_t freq = uint32_t(freqf);
|
||||||
timerStepDirection = steps > 0 ? 1 : -1;
|
timerStepDirection = steps > 0 ? 1 : -1;
|
||||||
timerStepPositionAtEnd = timerNewEndStepPosition;
|
timerStepPositionAtEnd = timerNewEndStepPosition;
|
||||||
@@ -121,4 +127,3 @@ void StepGen::setScale(int16_t spm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t StepGen::sync0CycleTime = 0;
|
uint32_t StepGen::sync0CycleTime = 0;
|
||||||
uint32_t StepGen::pwmCycleTime = 0;
|
|
||||||
|
|||||||
@@ -177,6 +177,5 @@ uint16_t dc_checker(void)
|
|||||||
// Indicate we run DC
|
// Indicate we run DC
|
||||||
ESCvar.dcsync = 1;
|
ESCvar.dcsync = 1;
|
||||||
StepGen::sync0CycleTime = ESC_SYNC0cycletime() / 1000; // usecs
|
StepGen::sync0CycleTime = ESC_SYNC0cycletime() / 1000; // usecs
|
||||||
StepGen::pwmCycleTime = 10 * StepGen::sync0CycleTime;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user