Example #1
0
void dac_current_raw(uint8_t channel, uint16_t val) {
  if (!dac_present) return;

  NOMORE(val, DAC_STEPPER_MAX);

  mcp4728_analogWrite(dac_order[channel], val);
  mcp4728_simpleCommand(UPDATE);
}
Example #2
0
void dac_current_percent(uint8_t channel, float val) {
  if (!dac_present) return;

  NOMORE(val, 100);

  mcp4728_analogWrite(dac_order[channel], val * 0.01 * (DAC_STEPPER_MAX));
  mcp4728_simpleCommand(UPDATE);
}
Example #3
0
  int dac_init() {
    #if PIN_EXISTS(DAC_DISABLE)
      OUT_WRITE(DAC_DISABLE_PIN, LOW);  // set pin low to enable DAC
    #endif

    mcp4728_init();

    if (mcp4728_simpleCommand(RESET)) return -1;

    dac_present = true;

    mcp4728_setVref_all(DAC_STEPPER_VREF);
    mcp4728_setGain_all(DAC_STEPPER_GAIN);

    return 0;
  }
Example #4
0
int dac_init() {
  #if PIN_EXISTS(DAC_DISABLE)
    OUT_WRITE(DAC_DISABLE_PIN, LOW);  // set pin low to enable DAC
  #endif

  mcp4728_init();

  if (mcp4728_simpleCommand(RESET)) return -1;

  dac_present = true;

  mcp4728_setVref_all(DAC_STEPPER_VREF);
  mcp4728_setGain_all(DAC_STEPPER_GAIN);

  if (mcp4728_getDrvPct(0) < 1 || mcp4728_getDrvPct(1) < 1 || mcp4728_getDrvPct(2) < 1 || mcp4728_getDrvPct(3) < 1 ) {
    mcp4728_setDrvPct(dac_channel_pct);
    mcp4728_eepromWrite();
  }

  return 0;
}