2017-06-18 01:36:10 +02:00
|
|
|
/***************************************************************
|
|
|
|
*
|
|
|
|
* External DAC for Alligator Board
|
|
|
|
*
|
|
|
|
****************************************************************/
|
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
#include "../../inc/MarlinConfig.h"
|
2017-06-18 01:36:10 +02:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
#if MB(ALLIGATOR)
|
2017-06-18 01:36:10 +02:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
#include "dac_dac084s085.h"
|
|
|
|
|
|
|
|
#include "../../Marlin.h"
|
|
|
|
#include "../../module/stepper.h"
|
|
|
|
|
|
|
|
dac084s085::dac084s085() {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dac084s085::begin() {
|
|
|
|
uint8_t externalDac_buf[2] = {0x20,0x00};//all off
|
|
|
|
|
|
|
|
// All SPI chip-select HIGH
|
|
|
|
pinMode(DAC0_SYNC, OUTPUT);
|
|
|
|
digitalWrite( DAC0_SYNC , HIGH );
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
pinMode(DAC1_SYNC, OUTPUT);
|
|
|
|
digitalWrite( DAC1_SYNC , HIGH );
|
|
|
|
#endif
|
|
|
|
digitalWrite( SPI_EEPROM1_CS , HIGH );
|
|
|
|
digitalWrite( SPI_EEPROM2_CS , HIGH );
|
|
|
|
digitalWrite( SPI_FLASH_CS , HIGH );
|
|
|
|
digitalWrite( SS_PIN , HIGH );
|
|
|
|
spiBegin();
|
|
|
|
|
|
|
|
//init onboard DAC
|
|
|
|
delayMicroseconds(2U);
|
|
|
|
digitalWrite( DAC0_SYNC , LOW );
|
|
|
|
delayMicroseconds(2U);
|
|
|
|
digitalWrite( DAC0_SYNC , HIGH );
|
|
|
|
delayMicroseconds(2U);
|
|
|
|
digitalWrite( DAC0_SYNC , LOW );
|
|
|
|
|
|
|
|
spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
|
|
|
|
digitalWrite( DAC0_SYNC , HIGH );
|
|
|
|
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
//init Piggy DAC
|
2017-06-18 01:36:10 +02:00
|
|
|
delayMicroseconds(2U);
|
2017-09-06 13:28:32 +02:00
|
|
|
digitalWrite( DAC1_SYNC , LOW );
|
2017-06-18 01:36:10 +02:00
|
|
|
delayMicroseconds(2U);
|
2017-09-06 13:28:32 +02:00
|
|
|
digitalWrite( DAC1_SYNC , HIGH );
|
2017-06-18 01:36:10 +02:00
|
|
|
delayMicroseconds(2U);
|
2017-09-06 13:28:32 +02:00
|
|
|
digitalWrite( DAC1_SYNC , LOW );
|
2017-06-18 01:36:10 +02:00
|
|
|
|
|
|
|
spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
|
2017-09-06 13:28:32 +02:00
|
|
|
digitalWrite( DAC1_SYNC , HIGH );
|
|
|
|
#endif
|
2017-06-18 01:36:10 +02:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-06-18 01:36:10 +02:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
void dac084s085::setValue(uint8_t channel, uint8_t value) {
|
|
|
|
if(channel >= 7) // max channel (X,Y,Z,E0,E1,E2,E3)
|
2017-06-18 01:36:10 +02:00
|
|
|
return;
|
2017-09-06 13:28:32 +02:00
|
|
|
if(value > 255) value = 255;
|
|
|
|
|
|
|
|
uint8_t externalDac_buf[2] = {0x10,0x00};
|
|
|
|
|
|
|
|
if(channel > 3)
|
|
|
|
externalDac_buf[0] |= (7 - channel << 6);
|
|
|
|
else
|
|
|
|
externalDac_buf[0] |= (3 - channel << 6);
|
|
|
|
|
|
|
|
externalDac_buf[0] |= (value >> 4);
|
|
|
|
externalDac_buf[1] |= (value << 4);
|
2017-09-27 11:57:14 +02:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
// All SPI chip-select HIGH
|
|
|
|
digitalWrite( DAC0_SYNC , HIGH );
|
|
|
|
#if EXTRUDERS > 1
|
|
|
|
digitalWrite( DAC1_SYNC , HIGH );
|
|
|
|
#endif
|
|
|
|
digitalWrite( SPI_EEPROM1_CS , HIGH );
|
|
|
|
digitalWrite( SPI_EEPROM2_CS , HIGH );
|
|
|
|
digitalWrite( SPI_FLASH_CS , HIGH );
|
|
|
|
digitalWrite( SS_PIN , HIGH );
|
|
|
|
|
|
|
|
if(channel > 3) { // DAC Piggy E1,E2,E3
|
|
|
|
|
|
|
|
digitalWrite(DAC1_SYNC , LOW);
|
|
|
|
delayMicroseconds(2U);
|
|
|
|
digitalWrite(DAC1_SYNC , HIGH);
|
|
|
|
delayMicroseconds(2U);
|
|
|
|
digitalWrite(DAC1_SYNC , LOW);
|
2017-06-18 01:36:10 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
else { // DAC onboard X,Y,Z,E0
|
2017-06-18 01:36:10 +02:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
digitalWrite(DAC0_SYNC , LOW);
|
2017-06-18 01:36:10 +02:00
|
|
|
delayMicroseconds(2U);
|
2017-09-06 13:28:32 +02:00
|
|
|
digitalWrite(DAC0_SYNC , HIGH);
|
|
|
|
delayMicroseconds(2U);
|
|
|
|
digitalWrite(DAC0_SYNC , LOW);
|
2017-06-18 01:36:10 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
delayMicroseconds(2U);
|
|
|
|
spiSend(SPI_CHAN_DAC,externalDac_buf , 2);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MB(ALLIGATOR)
|