Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Movement/StepperDrivers/TMC22xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class TmcDriverState
void UartTmcHandler(); // core of the ISR for this driver

private:
bool SetChopConf(uint32_t newVal);
bool SetChopConf(uint32_t newVal, bool raw = false);
void UpdateRegister(size_t regIndex, uint32_t regVal);
void UpdateChopConfRegister(); // calculate the chopper control register and flag it for sending
void UpdateCurrent();
Expand Down Expand Up @@ -547,7 +547,7 @@ bool TmcDriverState::SetRegister(SmartDriverRegister reg, uint32_t regVal)
switch(reg)
{
case SmartDriverRegister::chopperControl:
return SetChopConf(regVal);
return SetChopConf(regVal, true);

case SmartDriverRegister::toff:
return SetChopConf((configuredChopConfReg & ~CHOPCONF_TOFF_MASK) | ((regVal << CHOPCONF_TOFF_SHIFT) & CHOPCONF_TOFF_MASK));
Expand Down Expand Up @@ -602,10 +602,16 @@ uint32_t TmcDriverState::GetRegister(SmartDriverRegister reg) const
}

// Set the chopper control register to the settings provided by the user. We allow only the lowest 17 bits to be set.
bool TmcDriverState::SetChopConf(uint32_t newVal)
bool TmcDriverState::SetChopConf(uint32_t newVal, bool raw)
{
const uint32_t offTime = (newVal & CHOPCONF_TOFF_MASK) >> CHOPCONF_TOFF_SHIFT;
if (offTime == 0 || (offTime == 1 && (newVal & CHOPCONF_TBL_MASK) < (2 << CHOPCONF_TBL_SHIFT)))
// TOFF = 0 turns the driver off so it is not allowed unless given via Cnnn parameter.
if (!raw && offTime == 0)
{
return false;
}
// TOFF = 1 is not allowed if TBL = 0.
if (offTime == 1 && (newVal & CHOPCONF_TBL_MASK) < (2 << CHOPCONF_TBL_SHIFT))
{
return false;
}
Expand Down
16 changes: 10 additions & 6 deletions src/Movement/StepperDrivers/TMC2660.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class TmcDriverState
uint32_t ReadMicrostepPosition() const { return mstepPosition; }

private:
bool SetChopConf(uint32_t newVal);
bool SetChopConf(uint32_t newVal, bool raw = false);

void ResetLoadRegisters()
{
Expand Down Expand Up @@ -419,7 +419,7 @@ bool TmcDriverState::SetRegister(SmartDriverRegister reg, uint32_t regVal)
switch(reg)
{
case SmartDriverRegister::chopperControl:
return SetChopConf(regVal);
return SetChopConf(regVal, true);

case SmartDriverRegister::coolStep:
registers[SmartEnable] = TMC_REG_SMARTEN | (regVal & 0xFFFF);
Expand Down Expand Up @@ -482,12 +482,16 @@ uint32_t TmcDriverState::GetRegister(SmartDriverRegister reg) const
}

// Check the new chopper control register, update it and return true if it is legal
bool TmcDriverState::SetChopConf(uint32_t newVal)
bool TmcDriverState::SetChopConf(uint32_t newVal, bool raw)
{
// TOFF = 0 turns the driver off so it is not allowed.
// TOFF = 1 is not allowed if TBL = 0.
const uint32_t toff = (newVal & TMC_CHOPCONF_TOFF_MASK) >> TMC_CHOPCONF_TOFF_SHIFT;
if (toff == 0 || (toff == 1 && ((newVal & TMC_CHOPCONF_TBL_MASK) == 0)))
// TOFF = 0 turns the driver off so it is not allowed unless given via Cnnn parameter.
if (!raw && toff == 0)
{
return false;
}
// TOFF = 1 is not allowed if TBL = 0.
if (toff == 1 && ((newVal & TMC_CHOPCONF_TBL_MASK) == 0))
{
return false;
}
Expand Down
14 changes: 10 additions & 4 deletions src/Movement/StepperDrivers/TMC51xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class TmcDriverState
void TransferFailed();

private:
bool SetChopConf(uint32_t newVal);
bool SetChopConf(uint32_t newVal, bool raw = false);
void UpdateRegister(size_t regIndex, uint32_t regVal);
void UpdateChopConfRegister(); // calculate the chopper control register and flag it for sending
void UpdateCurrent();
Expand Down Expand Up @@ -485,7 +485,7 @@ bool TmcDriverState::SetRegister(SmartDriverRegister reg, uint32_t regVal)
switch(reg)
{
case SmartDriverRegister::chopperControl:
return SetChopConf(regVal);
return SetChopConf(regVal, true);

case SmartDriverRegister::toff:
return SetChopConf((configuredChopConfReg & ~CHOPCONF_TOFF_MASK) | ((regVal << CHOPCONF_TOFF_SHIFT) & CHOPCONF_TOFF_MASK));
Expand Down Expand Up @@ -552,10 +552,16 @@ uint32_t TmcDriverState::GetRegister(SmartDriverRegister reg) const
}

// Set the chopper control register to the settings provided by the user. We allow only the lowest 17 bits to be set.
bool TmcDriverState::SetChopConf(uint32_t newVal)
bool TmcDriverState::SetChopConf(uint32_t newVal, bool raw)
{
const uint32_t offTime = (newVal & CHOPCONF_TOFF_MASK) >> CHOPCONF_TOFF_SHIFT;
if (offTime == 0 || (offTime == 1 && (newVal & CHOPCONF_TBL_MASK) < (2 << CHOPCONF_TBL_SHIFT)))
// TOFF = 0 turns the driver off so it is not allowed unless given via Cnnn parameter.
if (!raw && offTime == 0)
{
return false;
}
// TOFF = 1 is not allowed if TBL = 0.
if (offTime == 1 && (newVal & CHOPCONF_TBL_MASK) < (2 << CHOPCONF_TBL_SHIFT))
{
return false;
}
Expand Down