wip, stepper doesn't run
This commit is contained in:
@@ -226,7 +226,7 @@ static void MX_TIM1_Init(void)
|
|||||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
|
|||||||
nFires++;
|
nFires++;
|
||||||
PreviousEncoderCounterValue = 0;
|
PreviousEncoderCounterValue = 0;
|
||||||
}
|
}
|
||||||
Obj.DiffT = sync0CycleTime;
|
// Obj.DiffT = sync0CycleTime;
|
||||||
|
|
||||||
int64_t pos = unwrap_encoder(TIM2->CNT, &PreviousEncoderCounterValue);
|
int64_t pos = unwrap_encoder(TIM2->CNT, &PreviousEncoderCounterValue);
|
||||||
double CurPos = pos * PosScaleRes;
|
double CurPos = pos * PosScaleRes;
|
||||||
@@ -102,7 +102,7 @@ static esc_cfg_t config =
|
|||||||
.esc_hw_eep_handler = NULL,
|
.esc_hw_eep_handler = NULL,
|
||||||
.esc_check_dc_handler = dc_checker,
|
.esc_check_dc_handler = dc_checker,
|
||||||
};
|
};
|
||||||
|
#define STEPPER_DIR PA12
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
Serial1.begin(115200);
|
Serial1.begin(115200);
|
||||||
@@ -117,6 +117,7 @@ void setup(void)
|
|||||||
|
|
||||||
ecat_slv_init(&config);
|
ecat_slv_init(&config);
|
||||||
attachInterrupt(digitalPinToInterrupt(INDEX_PIN), indexPulse, RISING); // Always when Index triggered
|
attachInterrupt(digitalPinToInterrupt(INDEX_PIN), indexPulse, RISING); // Always when Index triggered
|
||||||
|
pinMode(STEPPER_DIR, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
@@ -160,11 +161,12 @@ volatile int32_t actualPosition = 0;
|
|||||||
volatile int32_t requestedPosition;
|
volatile int32_t requestedPosition;
|
||||||
volatile uint32_t pulsesToGo = 0;
|
volatile uint32_t pulsesToGo = 0;
|
||||||
volatile byte forwardDirection = 0; // 1 if going forward
|
volatile byte forwardDirection = 0; // 1 if going forward
|
||||||
#define STEPPER_DIR PA12
|
|
||||||
// #define STEPPER_STEP PA11 // Set in StepperSetup
|
volatile uint32_t syncCounts = 0;
|
||||||
|
|
||||||
void sync0Handler(void)
|
void sync0Handler(void)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
// Update the actual position
|
// Update the actual position
|
||||||
actualPosition += pulsesToGo;
|
actualPosition += pulsesToGo;
|
||||||
Obj.StepGenOut1.ActualPosition = actualPosition;
|
Obj.StepGenOut1.ActualPosition = actualPosition;
|
||||||
@@ -172,9 +174,16 @@ void sync0Handler(void)
|
|||||||
requestedPosition = Obj.StepGenIn1.CommandedPosition;
|
requestedPosition = Obj.StepGenIn1.CommandedPosition;
|
||||||
// Get the diff and the direction
|
// Get the diff and the direction
|
||||||
pulsesToGo = requestedPosition - actualPosition;
|
pulsesToGo = requestedPosition - actualPosition;
|
||||||
forwardDirection = pulsesToGo > 0 ? 1 : 0;
|
#else
|
||||||
|
syncCounts++;
|
||||||
|
pulsesToGo = syncCounts % 2 ? 4 : 8;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// forwardDirection = pulsesToGo > 0 ? 1 : 0;
|
||||||
|
forwardDirection = syncCounts % 2 ? 1 : 0;
|
||||||
// Set direction pin
|
// Set direction pin
|
||||||
digitalWrite(STEPPER_DIR, forwardDirection); // I think one should really wait a bit when changed
|
digitalWrite(STEPPER_DIR, forwardDirection); // I think one should really wait a bit when changed
|
||||||
|
Obj.DiffT = forwardDirection;
|
||||||
// Make the pulses using hardware timer
|
// Make the pulses using hardware timer
|
||||||
makePulses(sync0CycleTime / 1000, pulsesToGo);
|
makePulses(sync0CycleTime / 1000, pulsesToGo);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user