49 digitalWrite(csPin, LOW);
50 pinMode(csPin, OUTPUT);
61 uint16_t dataOut = transfer((0x8 | (address & 0b111)) << 12);
63 return dataOut & 0xFFF;
69 return readReg((uint8_t)address);
80 transfer(((address & 0b111) << 12) | (value & 0xFFF));
95 SPISettings settings = SPISettings(500000, MSBFIRST, SPI_MODE0);
97 uint16_t transfer(uint16_t value)
99 return SPI.transfer16(value);
104 digitalWrite(csPin, HIGH);
105 SPI.beginTransaction(settings);
110 SPI.endTransaction();
111 digitalWrite(csPin, LOW);
136 SlowIncMixedDec = 0b001,
139 SlowIncAutoMixedDec = 0b100,
198 driver.setChipSelectPin(pin);
230 return driver.readReg(HPSDRegAddr::CTRL) == ctrl &&
231 driver.readReg(HPSDRegAddr::TORQUE) == (torque & ~(1 << 10)) &&
232 driver.readReg(HPSDRegAddr::OFF) == off &&
233 driver.readReg(HPSDRegAddr::BLANK) == blank &&
234 driver.readReg(HPSDRegAddr::DECAY) == decay &&
235 driver.readReg(HPSDRegAddr::STALL) == stall &&
236 driver.readReg(HPSDRegAddr::DRIVE) == drive;
300 return ctrl >> 1 & 1;
311 driver.writeReg(HPSDRegAddr::CTRL, ctrl | (1 << 2));
334 case HPSDStepMode::MicroStep1: sm = 0b0000;
break;
335 case HPSDStepMode::MicroStep2: sm = 0b0001;
break;
336 case HPSDStepMode::MicroStep4: sm = 0b0010;
break;
337 case HPSDStepMode::MicroStep8: sm = 0b0011;
break;
338 case HPSDStepMode::MicroStep16: sm = 0b0100;
break;
339 case HPSDStepMode::MicroStep32: sm = 0b0101;
break;
340 case HPSDStepMode::MicroStep64: sm = 0b0110;
break;
341 case HPSDStepMode::MicroStep128: sm = 0b0111;
break;
342 case HPSDStepMode::MicroStep256: sm = 0b1000;
break;
345 ctrl = (ctrl & 0b111110000111) | (sm << 3);
383 if (current > 8000) { current = 8000; }
409 if (current > 16000) { current = 16000; }
429 uint8_t isgainBits = 0b11;
430 uint16_t torqueBits = ((uint32_t)384 * current) / 6875;
433 while (torqueBits > 0xFF)
439 ctrl = (ctrl & 0b110011111111) | (isgainBits << 8);
441 torque = (torque & 0b111100000000) | torqueBits;
453 decay = (decay & 0b00011111111) | (((uint8_t)mode & 0b111) << 8);
474 return driver.readReg(HPSDRegAddr::STATUS);
485 driver.writeReg(HPSDRegAddr::STATUS, 0);
509 driver.writeReg(HPSDRegAddr::STATUS, ~0b00111111);
514 uint16_t ctrl, torque, off, blank, decay, stall, drive;
519 driver.writeReg(HPSDRegAddr::CTRL, ctrl);
525 driver.writeReg(HPSDRegAddr::TORQUE, torque);
531 driver.writeReg(HPSDRegAddr::OFF, off);
537 driver.writeReg(HPSDRegAddr::BLANK, blank);
543 driver.writeReg(HPSDRegAddr::DECAY, decay);
549 driver.writeReg(HPSDRegAddr::STALL, stall);
555 driver.writeReg(HPSDRegAddr::DRIVE, drive);
@ OTS
Overtemperature shutdown.
@ APDF
Channel A predriver fault.
@ UVLO
Undervoltage lockout.
@ BOCP
Channel B overcurrent shutdown.
@ STDLAT
Latched stall detect.
@ AOCP
Channel A overcurrent shutdown.
@ BPDF
Channel B predriver fault.
HPSDRegAddr
Addresses of control and status registers.
HPSDStepMode
Possible arguments to setStepMode().
HPSDDecayMode
Possible arguments to setDecayMode().
void writeReg(uint8_t address, uint16_t value)
Writes the specified value to a register.
uint16_t readReg(uint8_t address)
Reads the register at the given address and returns its raw value.
void writeReg(HPSDRegAddr address, uint16_t value)
Writes the specified value to a register.
void setChipSelectPin(uint8_t pin)
uint16_t readReg(HPSDRegAddr address)
Reads the register at the given address and returns its raw value.
void setCurrentMilliamps36v8(uint16_t current)
void setStepMode(uint16_t mode)
void setCurrentMilliamps36v4(uint16_t current)
HighPowerStepperDriver()
The default constructor.
void writeBLANK()
Writes the cached value of the BLANK register to the device.
void setChipSelectPin(uint8_t pin)
void disableDriver()
Disables the driver (ENBL = 0).
void enableDriver()
Enables the driver (ENBL = 1).
void setStepMode(HPSDStepMode mode)
void writeDRIVE()
Writes the cached value of the DRIVE register to the device.
void writeSTALL()
Writes the cached value of the STALL register to the device.
void writeOFF()
Writes the cached value of the OFF register to the device.
void writeTORQUE()
Writes the cached value of the TORQUE register to the device.
void setDirection(bool value)
void writeDECAY()
Writes the cached value of the DECAY register to the device.
void writeCTRL()
Writes the cached value of the CTRL register to the device.
void setDecayMode(HPSDDecayMode mode)