diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-01-17 22:19:15 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-01-17 22:19:15 +0300 |
commit | a7f8d8aca37084c93803836f1dc627c3a274f36a (patch) | |
tree | e745410ab9e69e7147072c0fa08e748b574d9379 /src/Platform/Platform.cpp | |
parent | e92b3cd7e4f94fde394231ec82e2268de19e5831 (diff) |
More work on MB6XD step generation
Also removed some obsolete Duet 085, RADDs and Alligator code
Diffstat (limited to 'src/Platform/Platform.cpp')
-rw-r--r-- | src/Platform/Platform.cpp | 138 |
1 files changed, 65 insertions, 73 deletions
diff --git a/src/Platform/Platform.cpp b/src/Platform/Platform.cpp index c4877c96..0ae91ba1 100644 --- a/src/Platform/Platform.cpp +++ b/src/Platform/Platform.cpp @@ -49,6 +49,7 @@ # include <AnalogIn.h> # include <DmacManager.h> using LegacyAnalogIn::AdcBits; +# include <pmc/pmc.h> # if SAME70 static_assert(NumDmaChannelsUsed <= NumDmaChannelsSupported, "Need more DMA channels in CoreNG"); # endif @@ -58,9 +59,6 @@ static_assert(NumDmaChannelsUsed <= NumDmaChannelsSupported, "Need more DMA chan using AnalogIn::AdcBits; // for compatibility with CoreNG, which doesn't have the AnalogIn namespace #elif defined(__LPC17xx__) # include "LPC/BoardConfig.h" -#else -# include "sam/drivers/tc/tc.h" -# include "sam/drivers/hsmci/hsmci.h" #endif #include <Libraries/sd_mmc/sd_mmc.h> @@ -684,6 +682,16 @@ 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_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_TCCLKS_TIMER_CLOCK2; // divide MCLK (150MHz) by 8 = 18.75MHz + SetPinFunction(StepGatePin, StepGatePinFunction); #endif // Set up the axis+extruder arrays @@ -2780,6 +2788,44 @@ GCodeResult Platform::SetMotorCurrent(size_t axisOrExtruder, float currentOrPerc #endif } +#ifdef DUET3_MB6XD + +// Fetch the worst (longest) timings of any driver, set up the step pulse width timer, and convert the other timings from microseconds to step clocks +void Platform::UpdateDriverTimings() +{ + float worstTimings[4]; + memcpyf(worstTimings, driverTimingMicroseconds[0], 4); + for (size_t driver = 1; driver < NumDirectDrivers; ++driver) + { + for (size_t i = 0; i < 4; ++i) + { + if (driverTimingMicroseconds[driver][i] > worstTimings[i]) + { + worstTimings[i] = driverTimingMicroseconds[driver][i]; + } + } + } + + // 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; + constexpr float MicrosecondsPerStepGateClock = 1.0e6/(float)StepGateTcClockFrequency; + + const float fclocks = ceilf(worstTimings[0] * StepGateClocksPerMicrosecond); + const uint32_t gateClocks = (uint32_t)fclocks; + STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_RC = gateClocks; + + // Convert the quantised step pulse width back to microseconds + const float actualStepPulseMicroseconds = fclocks * MicrosecondsPerStepGateClock; + + // Now convert the other values from microseconds to step clocks + stepPulseMinimumPeriodClocks = MicrosecondsToStepClocks(worstTimings[1] + actualStepPulseMicroseconds); + directionSetupClocks = MicrosecondsToStepClocks(worstTimings[2]); + directionHoldClocksFromLeadingEdge = MicrosecondsToStepClocks(worstTimings[3] + actualStepPulseMicroseconds); +} + +#endif + // This must not be called from an ISR, or with interrupts disabled. void Platform::UpdateMotorCurrent(size_t driver, float current) noexcept { @@ -2790,46 +2836,6 @@ void Platform::UpdateMotorCurrent(size_t driver, float current) noexcept { SmartDrivers::SetCurrent(driver, current); } -#elif defined (DUET_06_085) - const uint16_t pot = (unsigned short)((0.256*current*8.0*senseResistor + maxStepperDigipotVoltage/2)/maxStepperDigipotVoltage); - if (driver < 4) - { - mcpDuet.setNonVolatileWiper(potWipes[driver], pot); - mcpDuet.setVolatileWiper(potWipes[driver], pot); - } - else - { - if (board == BoardType::Duet_085) - { - // Extruder 0 is on DAC channel 0 - if (driver == 4) - { - const float dacVoltage = max<float>(current * 0.008 * senseResistor + stepperDacVoltageOffset, 0.0); // the voltage we want from the DAC relative to its minimum - const float dac = dacVoltage/stepperDacVoltageRange; - AnalogOut(DAC0, dac); - } - else - { - mcpExpansion.setNonVolatileWiper(potWipes[driver-1], pot); - mcpExpansion.setVolatileWiper(potWipes[driver-1], pot); - } - } - else if (driver < 8) // on a Duet 0.6 we have a maximum of 8 drives - { - mcpExpansion.setNonVolatileWiper(potWipes[driver], pot); - mcpExpansion.setVolatileWiper(potWipes[driver], pot); - } - } -#elif defined(__ALLIGATOR__) - // Alligator SPI DAC current - if (driver < 4) // Onboard DAC - { - dacAlligator.setChannel(3-driver, current * 0.102); - } - else // Piggy module DAC - { - dacPiggy.setChannel(7-driver, current * 0.102); - } #elif defined(__LPC17xx__) if (hasDriverCurrentControl) { @@ -3103,8 +3109,8 @@ void Platform::SetDriverStepTiming(size_t driver, const float microseconds[4]) n { if (microseconds[i] > MinStepPulseTiming) { - slowDriversBitmap |= StepPins::CalcDriverBitmap(driver); // this drive does need extended timing - const uint32_t clocks = (uint32_t)(((float)StepClockRate * microseconds[i] * 0.000001) + 0.99); // convert microseconds to step clocks, rounding up + slowDriversBitmap |= StepPins::CalcDriverBitmap(driver); // this drive does need extended timing + const uint32_t clocks = MicrosecondsToStepClocks(microseconds[i]); // convert microseconds to step clocks, rounding up if (clocks > slowDriverStepTimingClocks[i]) { slowDriverStepTimingClocks[i] = clocks; @@ -3770,11 +3776,13 @@ void Platform::SetBoardType(BoardType bt) noexcept board = (digitalRead(DIRECTION_PINS[1])) // if SAME54P20A ? BoardType::Duet3Mini_WiFi : BoardType::Duet3Mini_Ethernet; -#elif defined(DUET3) +#elif defined(DUET3_MB6HC) // Driver 0 direction has a pulldown resistor on v0.6 and v1.0 boards, but won't on v1.01 boards pinMode(DIRECTION_PINS[0], INPUT_PULLUP); delayMicroseconds(20); // give the pullup resistor time to work - board = (digitalRead(DIRECTION_PINS[0])) ? BoardType::Duet3_v101 : BoardType::Duet3_v06_100; + board = (digitalRead(DIRECTION_PINS[0])) ? BoardType::Duet3_6HC_v101 : BoardType::Duet3_6HC_v06_100; +#elif defined(DUET3_MB6XD) + board = BoardType::Duet3_6XD; #elif defined(SAME70XPLD) board = BoardType::SAME70XPLD_0; #elif defined(DUET_NG) @@ -3848,9 +3856,11 @@ const char *_ecv_array Platform::GetElectronicsString() const noexcept case BoardType::Duet3Mini_Unknown: return "Duet 3 " BOARD_SHORT_NAME " unknown variant"; case BoardType::Duet3Mini_WiFi: return "Duet 3 " BOARD_SHORT_NAME " WiFi"; case BoardType::Duet3Mini_Ethernet: return "Duet 3 " BOARD_SHORT_NAME " Ethernet"; -#elif defined(DUET3) - case BoardType::Duet3_v06_100: return "Duet 3 " BOARD_SHORT_NAME " v0.6 or 1.0"; - case BoardType::Duet3_v101: return "Duet 3 " BOARD_SHORT_NAME " v1.01 or later"; +#elif defined(DUET3_MB6HC) + case BoardType::Duet3_6HC_v06_100: return "Duet 3 " BOARD_SHORT_NAME " v0.6 or 1.0"; + case BoardType::Duet3_6HC_v101: return "Duet 3 " BOARD_SHORT_NAME " v1.01 or later"; +#elif defined(DUET3_MB6XD) + case BoardType::Duet3_6XD: return "Duet 3 " BOARD_SHORT_NAME; // we have only one version at present #elif defined(SAME70XPLD) case BoardType::SAME70XPLD_0: return "SAME70-XPLD"; #elif defined(DUET_NG) @@ -3863,18 +3873,8 @@ const char *_ecv_array Platform::GetElectronicsString() const noexcept case BoardType::Duet2SBC_102: return "Duet 2 + SBC 1.02 or later"; #elif defined(DUET_M) case BoardType::DuetM_10: return "Duet Maestro 1.0"; -#elif defined(DUET_06_085) - case BoardType::Duet_06: return "Duet 0.6"; - case BoardType::Duet_07: return "Duet 0.7"; - case BoardType::Duet_085: return "Duet 0.85"; -#elif defined(__RADDS__) - case BoardType::RADDS_15: return "RADDS 1.5"; -#elif defined(__ALLIGATOR__) - case BoardType::Alligator_2: return "Alligator r2"; #elif defined(PCCB_10) case BoardType::PCCB_v10: return "PC001373"; -#elif defined(PCCB_08) || defined(PCCB_08_X5) - case BoardType::PCCB_v08: return "PCCB 0.8"; #elif defined(__LPC17xx__) case BoardType::Lpc: return LPC_ELECTRONICS_STRING; #else @@ -3893,9 +3893,11 @@ const char *_ecv_array Platform::GetBoardString() const noexcept case BoardType::Duet3Mini_Unknown: return "duet5lcunknown"; case BoardType::Duet3Mini_WiFi: return "duet5lcwifi"; case BoardType::Duet3Mini_Ethernet: return "duet5lcethernet"; -#elif defined(DUET3) - case BoardType::Duet3_v06_100: return "duet3mb6hc100"; - case BoardType::Duet3_v101: return "duet3mb6hc101"; +#elif defined(DUET3_MB6HC) + case BoardType::Duet3_6HC_v06_100: return "duet3mb6hc100"; + case BoardType::Duet3_6HC_v101: return "duet3mb6hc101"; +#elif defined(DUET3_MB6XD) + case BoardType::Duet3_6XD: return "duet3mb6xd"; // we have only one version at present #elif defined(SAME70XPLD) case BoardType::SAME70XPLD_0: return "same70xpld"; #elif defined(DUET_NG) @@ -3907,18 +3909,8 @@ const char *_ecv_array Platform::GetBoardString() const noexcept case BoardType::Duet2SBC_102: return "duet2sbc102"; #elif defined(DUET_M) case BoardType::DuetM_10: return "duetmaestro100"; -#elif defined(DUET_06_085) - case BoardType::Duet_06: return "duet06"; - case BoardType::Duet_07: return "duet07"; - case BoardType::Duet_085: return "duet085"; -#elif defined(__RADDS__) - case BoardType::RADDS_15: return "radds15"; -#elif defined(__ALLIGATOR__) - case BoardType::Alligator_2: return "alligator2"; #elif defined(PCCB_10) case BoardType::PCCB_v10: return "pc001373"; -#elif defined(PCCB_08) || defined(PCCB_08_X5) - case BoardType::PCCB_v08: return "pccb08"; #elif defined(__LPC17xx__) case BoardType::Lpc: return LPC_BOARD_STRING; #else |