diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-07-05 14:41:33 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-07-05 14:41:33 +0300 |
commit | 93fba580c031d8b635084c14eb812d64c822a6ba (patch) | |
tree | af3e4e448dbe60eccca5a1fdd9a1595a129c383b /src/Platform/Platform.cpp | |
parent | 02bdc0f3527fdf52b8a2f7142120ed7072630f89 (diff) |
Re-implemented support for MB6XD long step pulses for ATE testing
Diffstat (limited to 'src/Platform/Platform.cpp')
-rw-r--r-- | src/Platform/Platform.cpp | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/src/Platform/Platform.cpp b/src/Platform/Platform.cpp index e9dfb10f..968ed426 100644 --- a/src/Platform/Platform.cpp +++ b/src/Platform/Platform.cpp @@ -647,19 +647,9 @@ void Platform::Init() noexcept #ifdef DUET3_MB6XD driverErrPinsActiveLow = (numErrorHighDrivers >= NumDirectDrivers/2); // determine the error signal polarity by assuming most drivers are not in the error state - - // Set up the step gate timer - pmc_enable_periph_clk(STEP_GATE_TC_ID); - STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_CCR = TC_CCR_CLKDIS; - STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_CMR = TC_CMR_BSWTRG_SET // software trigger sets TIOB - | TC_CMR_BCPC_CLEAR // RC compare clears TIOB - | TC_CMR_WAVE // waveform mode - | TC_CMR_WAVSEL_UP // count up - | TC_CMR_CPCSTOP // counter clock is stopped when counter reaches RC - | TC_CMR_EEVT_XC0 // set external events from XC0 (this allows TIOB to be an output) - | TC_CMR_TCCLKS_TIMER_CLOCK2; // divide MCLK (150MHz) by 8 = 18.75MHz + pmc_enable_periph_clk(STEP_GATE_TC_ID); // need to do this before we set up the step gate TC + UpdateDriverTimings(); // this also initialises the step gate TC SetPinFunction(StepGatePin, StepGatePinFunction); - STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_CCR = TC_CCR_CLKEN; #endif // Set up the axis+extruder arrays @@ -705,9 +695,7 @@ void Platform::Init() noexcept #endif } -#ifdef DUET3_MB6XD - UpdateDriverTimings(); -#else +#ifndef DUET3_MB6XD for (uint32_t& entry : slowDriverStepTimingClocks) { entry = 0; // reset all to zero as we have no known slow drivers yet @@ -2779,13 +2767,31 @@ void Platform::UpdateDriverTimings() noexcept } // Convert the step pulse width to clocks of the step pulse gate timer. First define some constants. - constexpr uint32_t StepGateTcClockFrequency = (SystemCoreClockFreq/2)/8; - constexpr float StepGateClocksPerMicrosecond = (float)StepGateTcClockFrequency/1.0e6; - const float fclocks = min<float>(ceilf(worstTimings[0] * StepGateClocksPerMicrosecond), 65535.0); // the TC is only 16 bits wide - STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_RC = (uint32_t)fclocks; + constexpr uint32_t StepGateTcBaseClockFrequency = (SystemCoreClockFreq/2)/8; // the step gate T clock frequency when we use a prescaler of 8 + constexpr float StepGateBaseClocksPerMicrosecond = (float)StepGateTcBaseClockFrequency * 1.0e-6; + const float fclocks = min<float>(ceilf(worstTimings[0] * StepGateBaseClocksPerMicrosecond), (float)(4 * 65535)); // the TC is only 16 bits wide, but we increase the prescaler to 32 if necessary + + uint32_t iclocks = (uint32_t)fclocks; + uint32_t clockPrescaler = TC_CMR_TCCLKS_TIMER_CLOCK2; // divide MCLK (150MHz) by 8 = 18.75MHz + if (iclocks > 65535) + { + clockPrescaler = TC_CMR_TCCLKS_TIMER_CLOCK3; // divide MCLK (150MHz) by 32 = 4.6875MHz + iclocks >>= 2; + } + + STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_CCR = TC_CCR_CLKDIS; + STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_CMR = TC_CMR_BSWTRG_SET // software trigger sets TIOB + | TC_CMR_BCPC_CLEAR // RC compare clears TIOB + | TC_CMR_WAVE // waveform mode + | TC_CMR_WAVSEL_UP // count up + | TC_CMR_CPCSTOP // counter clock is stopped when counter reaches RC + | TC_CMR_EEVT_XC0 // set external events from XC0 (this allows TIOB to be an output) + | clockPrescaler; // divide MCLK (150MHz) by 8 or 32 + STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_RC = iclocks; + STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_CCR = TC_CCR_CLKEN; // Convert the quantised step pulse width back to microseconds - const float actualStepPulseMicroseconds = fclocks/StepGateClocksPerMicrosecond; + const float actualStepPulseMicroseconds = fclocks/StepGateBaseClocksPerMicrosecond; // Now convert the other values from microseconds to step clocks stepPulseMinimumPeriodClocks = MicrosecondsToStepClocks(worstTimings[1] + actualStepPulseMicroseconds); @@ -2797,8 +2803,12 @@ void Platform::UpdateDriverTimings() noexcept void Platform::GetActualDriverTimings(float timings[4]) noexcept { - constexpr uint32_t StepGateTcClockFrequency = (SystemCoreClockFreq/2)/8; - constexpr float MicrosecondsPerStepGateClock = 1.0e6/(float)StepGateTcClockFrequency; + uint32_t StepGateTcClockFrequency = (SystemCoreClockFreq/2)/8; + if ((STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_CMR & TC_CMR_TCCLKS_Msk) == TC_CMR_TCCLKS_TIMER_CLOCK3) + { + StepGateTcClockFrequency >>= 2;; + } + const float MicrosecondsPerStepGateClock = 1.0e6/(float)StepGateTcClockFrequency; constexpr float StepClocksToMicroseconds = 1.0e6/(float)StepClockRate; timings[0] = (float)STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_RC * MicrosecondsPerStepGateClock; timings[1] = stepPulseMinimumPeriodClocks * StepClocksToMicroseconds - timings[0]; |