Skip to content

Commit

Permalink
firmware: switch the DAC off too when switching off Vio
Browse files Browse the repository at this point in the history
Without this, the DAC still outputs it's control voltage even if Vio is off.
This goes through the feedback resistors to the output. I measured about
15 mV without this patch on a port that was previously enabled.
With this patch it properly goes down to zero.

While such a low voltage usually shouldn't be a problem, I consider it
unclean design, especially if it is so easy to fix.
  • Loading branch information
electroniceel committed Dec 6, 2020
1 parent e472c43 commit ca49533
Show file tree
Hide file tree
Showing 2 changed files with 449 additions and 443 deletions.
32 changes: 18 additions & 14 deletions firmware/dac_ldo.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,23 @@ bool iobuf_set_voltage(uint8_t mask, __xdata const uint16_t *millivolts_ptr) {
if((mask & IO_BUF_A) && millivolts > glasgow_config.voltage_limit[0]) return false;
if((mask & IO_BUF_B) && millivolts > glasgow_config.voltage_limit[1]) return false;

// Just disable the LDOs, DAC power is irrelevant
if(millivolts == 0) {
// disable the LDOs before any I2C comms, we may need to be fast in case of an alert
IOD &= ~pin_mask;
return true;
}

// Compute the DAC code word
if(millivolts < MIN_VOLTAGE || millivolts > MAX_VOLTAGE)
return false;

// Offset 1650, slope -15.2, 0x1000/15.2 = 269
// The DAC has a 12-bit code word, so we only shift back by 8
code_word = (254 << 4) - ((((millivolts - 1650) >> 4) * 269) >> 4);
code_bytes[0] = code_word >> 8;
code_bytes[1] = code_word & 0xff;
code_bytes[0] = 0;
code_bytes[1] = 0;
} else {
// Compute the DAC code word
if(millivolts < MIN_VOLTAGE || millivolts > MAX_VOLTAGE)
return false;

// Offset 1650, slope -15.2, 0x1000/15.2 = 269
// The DAC has a 12-bit code word, so we only shift back by 8
code_word = (254 << 4) - ((((millivolts - 1650) >> 4) * 269) >> 4);
code_bytes[0] = code_word >> 8;
code_bytes[1] = code_word & 0xff;
}

// Send the DAC code word
if(!dac_start(mask, /*read=*/false))
Expand All @@ -86,8 +88,10 @@ bool iobuf_set_voltage(uint8_t mask, __xdata const uint16_t *millivolts_ptr) {
if(!i2c_stop())
return false;

// Enable LDO(s)
IOD |= pin_mask;
if(millivolts != 0) {
// Enable LDO(s)
IOD |= pin_mask;
}

return true;
}
Expand Down

0 comments on commit ca49533

Please sign in to comment.