Skip to content

Ds2438 fixes #35

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions userial/ad26.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,25 @@ float Volt_Reading(int portnum, int vdd, int *cad)
if(cad) {

/* Get Current reading as well */
/* convert from 12-bit 2's complement, see
* https://en.wikipedia.org/wiki/Two%27s_complement
* According to the DS2438 datasheet the current register
* has 10 significant bits (Page 6, Table 3). However,
* the stated conversion formulae seem to hint at
* 12 bits. Nevertheless, the stated voltage unit of
* 0.2441mV per digital unit and the maximum voltage
* rating on the Vsense pins of 250mV are consistent with
* a 10-bit register format plus sign bits. This is
* what we use here.
*/
c = send_block[8] & 0x3;

*cad = (c << 8) | send_block[7];
if(send_block[8] & 0x4) *cad = - *cad;
if(send_block[8] & 0x4) {
/* Negative value represented by set sign bit
* with weight of -2^10
*/
*cad = *cad - 1024;
}

// printf("CAD=%d\n", *cad);
}
Expand Down