Added timer2 for proper start point

This commit is contained in:
Hakan Bastedt
2024-02-02 21:43:58 +01:00
parent 0384646972
commit 2b2704bb17
4 changed files with 10 additions and 5 deletions

View File

@@ -16,6 +16,7 @@ private:
volatile double_t requestedPosition; volatile double_t requestedPosition;
volatile uint8_t enabled; volatile uint8_t enabled;
HardwareTimer *MyTim; HardwareTimer *MyTim;
HardwareTimer *MyTim2;
uint16_t stepsPerMM; uint16_t stepsPerMM;
uint8_t dirPin; uint8_t dirPin;
PinName stepPin; PinName stepPin;

View File

@@ -18,6 +18,7 @@ private:
volatile int32_t oldStepPosition; volatile int32_t oldStepPosition;
volatile uint8_t enabled; volatile uint8_t enabled;
HardwareTimer *MyTim; HardwareTimer *MyTim;
HardwareTimer *MyTim2;
int16_t stepsPerMM; int16_t stepsPerMM;
uint8_t dirPin; uint8_t dirPin;
PinName stepPin; PinName stepPin;
@@ -33,7 +34,7 @@ public:
static uint32_t sync0CycleTime; static uint32_t sync0CycleTime;
volatile uint32_t lcncCycleTime; // Linuxcnc nominal cycle time (1 ms often) volatile uint32_t lcncCycleTime; // Linuxcnc nominal cycle time (1 ms often)
StepGen2(TIM_TypeDef *Timer, uint32_t timerChannel, PinName stepPin, uint8_t dirPin, void irq(void)); StepGen2(TIM_TypeDef *Timer, TIM_TypeDef *Timer2, uint32_t _timerChannel, PinName _stepPin, uint8_t _dirPin, void irq(void));
uint32_t handleStepper(void); uint32_t handleStepper(void);
void timerCB(); void timerCB();
@@ -50,7 +51,6 @@ public:
void setScale(int16_t spm) { stepsPerMM = spm; } void setScale(int16_t spm) { stepsPerMM = spm; }
int16_t getScale() { return stepsPerMM; } int16_t getScale() { return stepsPerMM; }
uint32_t updatePosAndReturn(int32_t stepPosStop, uint32_t i); uint32_t updatePosAndReturn(int32_t stepPosStop, uint32_t i);
}; };
#endif #endif

View File

@@ -2,7 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include "StepGen2.h" #include "StepGen2.h"
StepGen2::StepGen2(TIM_TypeDef *Timer, uint32_t _timerChannel, PinName _stepPin, uint8_t _dirPin, void irq(void)) StepGen2::StepGen2(TIM_TypeDef *Timer, TIM_TypeDef *Timer2, uint32_t _timerChannel, PinName _stepPin, uint8_t _dirPin, void irq(void))
{ {
timerIsRunning = 0; timerIsRunning = 0;
timerStepPosition = 0; timerStepPosition = 0;
@@ -22,6 +22,7 @@ StepGen2::StepGen2(TIM_TypeDef *Timer, uint32_t _timerChannel, PinName _stepPin,
MyTim = new HardwareTimer(Timer); MyTim = new HardwareTimer(Timer);
MyTim->attachInterrupt(irq); MyTim->attachInterrupt(irq);
pinMode(dirPin, OUTPUT); pinMode(dirPin, OUTPUT);
MyTim2 = new HardwareTimer(Timer2);
} }
uint32_t StepGen2::handleStepper(void) uint32_t StepGen2::handleStepper(void)

View File

@@ -33,6 +33,9 @@ void timerCallbackStep2(void)
} }
#endif #endif
#include "StepGen2.h" #include "StepGen2.h"
void timerCallbackStep(void);
StepGen2 Step(TIM1, TIM10, 4, PA_11, PA12, timerCallbackStep);
void timerCallbackStep(void) { Step.timerCB(); }
CircularBuffer<uint32_t, 200> Tim; CircularBuffer<uint32_t, 200> Tim;
volatile uint64_t nowTime = 0, thenTime = 0; volatile uint64_t nowTime = 0, thenTime = 0;
@@ -181,9 +184,9 @@ uint16_t dc_checker(void)
{ {
// Indicate we run DC // Indicate we run DC
ESCvar.dcsync = 1; ESCvar.dcsync = 1;
#if 0 #if 0
StepGen::sync0CycleTime = ESC_SYNC0cycletime() / 1000; // usecs StepGen::sync0CycleTime = ESC_SYNC0cycletime() / 1000; // usecs
#endif #endif
StepGen2::sync0CycleTime = ESC_SYNC0cycletime() / 1000; // usecs StepGen2::sync0CycleTime = ESC_SYNC0cycletime() / 1000; // usecs
return 0; return 0;
} }