Skip to content

Commit

Permalink
DS4432: Fix integer overflow for vcore values of 4900 mv and higher
Browse files Browse the repository at this point in the history
Signed-off-by: Robin van der Gracht <[email protected]>
  • Loading branch information
rvdgracht committed Jul 5, 2024
1 parent dd2f094 commit 1c5fa83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions main/DS4432U.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ bool DS4432U_test(void)

uint8_t DS4432U_voltage_to_reg(uint32_t vout_mv, uint32_t vnom_mv,
uint32_t ra_ohm, uint32_t rb_ohm,
int32_t ifs_na, uint32_t vfb_mv)
uint32_t ifs_na, uint32_t vfb_mv)
{
uint8_t reg;
// Calculate current flowing though bottom resistor (Rb) in nA
int32_t irb_na = (vfb_mv * 1000 * 1000) / rb_ohm;
int32_t irb_na = ((uint64_t)vfb_mv * 1000 * 1000) / rb_ohm;
// Calculate current required through top resistor (Ra) to achieve vout in nA
int32_t ira_na = ((vout_mv - vfb_mv) * 1000 * 1000) / ra_ohm;
int32_t ira_na = ((uint64_t)(vout_mv - vfb_mv) * 1000 * 1000) / ra_ohm;
// Calculate the delta current the DAC needs to sink/source in nA
uint32_t dac_na = abs(irb_na - ira_na);
// Calculate required DAC steps to get dac_na (rounded)
Expand Down
2 changes: 1 addition & 1 deletion main/DS4432U.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ esp_err_t DS4432U_set_current_code(uint8_t output, uint8_t code);
esp_err_t DS4432U_get_current_code(uint8_t output, uint8_t *code);
uint8_t DS4432U_voltage_to_reg(uint32_t vout_mv, uint32_t vnom_mv,
uint32_t ra_ohm, uint32_t rb_ohm,
int32_t ifs_na, uint32_t vfb_mv);
uint32_t ifs_na, uint32_t vfb_mv);
#endif /* DS4432U_H_ */

0 comments on commit 1c5fa83

Please sign in to comment.