My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dac_dac084s085.cpp 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /***************************************************************
  2. *
  3. * External DAC for Alligator Board
  4. *
  5. ****************************************************************/
  6. #include "../../inc/MarlinConfig.h"
  7. #if MB(ALLIGATOR)
  8. #include "dac_dac084s085.h"
  9. #include "../../Marlin.h"
  10. #include "../../module/stepper.h"
  11. #include "../../HAL/Delay.h"
  12. dac084s085::dac084s085() { }
  13. void dac084s085::begin() {
  14. uint8_t externalDac_buf[] = { 0x20, 0x00 }; // all off
  15. // All SPI chip-select HIGH
  16. SET_OUTPUT(DAC0_SYNC);
  17. #if EXTRUDERS > 1
  18. SET_OUTPUT(DAC1_SYNC);
  19. #endif
  20. cshigh();
  21. spiBegin();
  22. //init onboard DAC
  23. DELAY_US(2);
  24. WRITE(DAC0_SYNC, LOW);
  25. DELAY_US(2);
  26. WRITE(DAC0_SYNC, HIGH);
  27. DELAY_US(2);
  28. WRITE(DAC0_SYNC, LOW);
  29. spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
  30. WRITE(DAC0_SYNC, HIGH);
  31. #if EXTRUDERS > 1
  32. //init Piggy DAC
  33. DELAY_US(2);
  34. WRITE(DAC1_SYNC, LOW);
  35. DELAY_US(2);
  36. WRITE(DAC1_SYNC, HIGH);
  37. DELAY_US(2);
  38. WRITE(DAC1_SYNC, LOW);
  39. spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
  40. WRITE(DAC1_SYNC, HIGH);
  41. #endif
  42. return;
  43. }
  44. void dac084s085::setValue(const uint8_t channel, const uint8_t value) {
  45. if (channel >= 7) return; // max channel (X,Y,Z,E0,E1,E2,E3)
  46. const uint8_t externalDac_buf[] = {
  47. 0x10 | ((channel > 3 ? 7 : 3) - channel << 6) | (value >> 4),
  48. 0x00 | (value << 4)
  49. };
  50. // All SPI chip-select HIGH
  51. cshigh();
  52. if (channel > 3) { // DAC Piggy E1,E2,E3
  53. WRITE(DAC1_SYNC, LOW);
  54. DELAY_US(2);
  55. WRITE(DAC1_SYNC, HIGH);
  56. DELAY_US(2);
  57. WRITE(DAC1_SYNC, LOW);
  58. }
  59. else { // DAC onboard X,Y,Z,E0
  60. WRITE(DAC0_SYNC, LOW);
  61. DELAY_US(2);
  62. WRITE(DAC0_SYNC, HIGH);
  63. DELAY_US(2);
  64. WRITE(DAC0_SYNC, LOW);
  65. }
  66. DELAY_US(2);
  67. spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
  68. }
  69. void dac084s085::cshigh() {
  70. WRITE(DAC0_SYNC, HIGH);
  71. #if EXTRUDERS > 1
  72. WRITE(DAC1_SYNC, HIGH);
  73. #endif
  74. WRITE(SPI_EEPROM1_CS, HIGH);
  75. WRITE(SPI_EEPROM2_CS, HIGH);
  76. WRITE(SPI_FLASH_CS, HIGH);
  77. WRITE(SS_PIN, HIGH);
  78. }
  79. #endif // MB(ALLIGATOR)