Well,
looks like pretty much forward,
According to page 19 of the
datasheet, to set the VBias on you need to set BIAS on Command Register (CMR) , witch is at bit 7 of CMR 's byte 3.
The CMDwrite routine that you are using is writing only byte2, byte1 and byte0, as it starts on the byte 2 address (b0101)
Now I have two suggestions... either you recode the CMDwrite routine to include bias handling, witch means write the four command bytes, and considering command byte 3 default values, it would be something like this:
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| void ADSx::CMRwrite(byte channel,byte mode,byte gain,byte TMR,int DR, byte vBIAS) // vBIAS =1 => ON;vBIAS =0 => OFF
{
byte Byte[4];
Byte[0] = ((vBIAS & 0x01) << 7) | 0x40; // Command Byte3
int _gain;
switch (gain) {
case 2: _gain = B001; break;
case 4: _gain = B010; break;
case 8: _gain = B011; break;
case 16: _gain= B100; break;
default: _gain = 0;
}
Byte[1] = mode<<5 | _gain<<2 | channel-1; // Command Byte2
byte _TMR;
switch (TMR) {
case 2: _TMR = B001; break;
case 4: _TMR = B010; break;
case 8: _TMR = B011; break;
case 16: _TMR= B100; break;
default: _TMR = 0;
}
Byte[2] = _TMR<<5 | DR>>8; // Command Byte1
Byte[3] = DR; // Command Byte0
write(B0100,4,Byte); // B0100 is the address for command byte 3
} |
or, since you are not performing any write operation to command byte3 in your source code, could code a sub just for control the Vbias, for example:
Code C - [expand] |
1
2
3
4
5
6
7
8
| void ADSx::CMR_bias_control(byte vBIAS) // vBIAS =1 => ON;vBIAS =0 => OFF
{
byte Byte[1];
Byte[0] = ((vBIAS & 0x01) << 7) | 0x40; // Command Byte3
write(B0100,1,Byte); // B0100 is the address for command byte 3
} |
note: I don't know if the adc allows a write operation only for this byte, but I couldn't found anything saying that we can't do this ...
Regards,
Ricardo