ooops it was set to use DC sync, not the intention, SM2 sync was intended. Switch to SM2 sync

This commit is contained in:
Hakan Bastedt
2024-01-05 21:33:06 +01:00
parent 37d3ea6567
commit 7e06b0ce68
2 changed files with 10 additions and 24 deletions

View File

@@ -17,7 +17,7 @@ debug_tool = stlink
debug_build_flags = -O0 -g -ggdb
monitor_port = COM7
monitor_speed = 115200
build_flags = -O0 -g -Wl,--no-warn-rwx-segment
build_flags = -Wl,--no-warn-rwx-segment
lib_deps =
SPI
rlogiacco/CircularBuffer@^1.3.3

View File

@@ -60,9 +60,7 @@ void cb_set_outputs(void) // Master outputs gets here, slave inputs, first opera
byte forwardDirection = 0; // 1 if going forward
int32_t pulsesToGo = 1000 * (requestedPosition - actualPosition);
if (pulsesToGo != 0)
makePulses(900, abs(pulsesToGo)); // Make the pulses using hardware timer
// digitalWrite(STEPPER_DIR_PIN, HIGH); // I think one should really wait a bit when changed
makePulses(900, pulsesToGo); // Make the pulses using hardware timer
actualPosition = requestedPosition;
}
@@ -114,7 +112,7 @@ static esc_cfg_t config =
.set_defaults_hook = NULL,
.pre_state_change_hook = NULL,
.post_state_change_hook = NULL,
.application_hook = handleStepper, // StepGen,
.application_hook = NULL, // StepGen,
.safeoutput_override = NULL,
.pre_object_download_hook = NULL,
.post_object_download_hook = NULL,
@@ -137,11 +135,13 @@ void TimerStep_CB(void)
void makePulses(uint32_t period /* in usecs */, int32_t pulses /* nr of pulses to do*/)
{
byte sgn = pulses > 0 ? HIGH : LOW;
digitalWrite(STEPPER_DIR_PIN, sgn); // I think one should really wait a bit when changed
uint32_t puls = abs(pulses);
MyTim->setOverflow(puls * 1000000 / period, HERTZ_FORMAT);
MyTim->setOverflow(abs(pulses) * 1000000 / period, HERTZ_FORMAT);
MyTim->setCaptureCompare(4, 50, PERCENT_COMPARE_FORMAT); // 50 %
stepCount = 0;
stepPulses = puls;
stepPulses = abs(pulses);
MyTim->resume();
}
@@ -215,20 +215,6 @@ void sync0Handler(void)
serveIRQ = 1;
}
void handleStepper(void)
{
#if 0
byte forwardDirection = 0; // 1 if going forward
int32_t pulsesToGo = 1000 * (requestedPosition - actualPosition);
if (pulsesToGo != 0)
makePulses(500, 1); // Make the pulses using hardware timer
// digitalWrite(STEPPER_DIR_PIN, HIGH); // I think one should really wait a bit when changed
actualPosition = requestedPosition;
#endif
}
void ESC_interrupt_enable(uint32_t mask)
{
// Enable interrupt for SYNC0 or SM2 or SM3
@@ -273,7 +259,7 @@ extern "C" uint32_t ESC_SYNC0cycletime(void);
uint16_t dc_checker(void)
{
// Indicate we run DC
ESCvar.dcsync = 1;
ESCvar.dcsync = 0;
sync0CycleTime = ESC_SYNC0cycletime();
return 0;
}