Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firmware: switch the DAC off too when switching off Vio #243

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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