Questions regarding an AD7730 bridge transducer based library for Arduino + PCB

Dear enthusiasts :D ,

I am doing a project which involves using an AD7730 bridge transducer chip as an Analog to Digital Converter (ADC). I have already noticed that there are a few threads dedicated to this subject and I will aim not to repeat whatever has already been discussed.

Firstly I found this useful webpage which I would like to bring to everyone’s attention. One can download schematics and libraries for putting together an Arduino friendly shield using AD7730 and programming Arduino to work with the shield for load cell and weight scales measurements.

Secondly, I have been going through the library files and came up with some questions, which I hope we can find the answer to together:

I have noticed that there are two pairs of files for communications over SPI interface namely WxSpi.h, WxSpi.cpp, wxspi.h and wxspi.cpp.

There is an AD7730.h for defining register locations on the AD7730 chip and there are a pair of files which define the functions which one can implement on AD7730, called LoadCell.h and LoadCell.cpp. There is also the Arduino UNO program called LoadCell.ino.

Question (1): Why while averaging on line 280 of LoadCell.cpp, a value of 0.5 is added to the value of the average? (and it has not been done later on for other averaging). This may require referring to the actual .cpp file and maybe the AD7730 datasheet if needed, but I could not find anything in the datasheet which would justify the addition of 0.5.

*offset = (long)(foffset / avg + 0.5);

Question (2): Why in line 294 of LoadCell.cpp, 8388608.0 is subtracted from “ftare”? Moreover, the value of 8388608.0 is defined in LoadCell.ino as a “const double” and is named “adcFullScale”. If AD7730 is supposed to have 24 bits of resolution and the code sets the ADC up for unipolar mode (line 396 of LoadCell.cpp) and a data register length of 24 bits ( lines 26 and 27 of LoadCell.cpp), then should not the ADC’s full range be (2^24)-1, while in this case it is 2^23(8388608.0)??

Here're lines 26 and 27 of the .cpp file:

const unsigned int initModeCmds[] = {
 COMMS_WRITE | MODE_REG, M_IDLE | MODEH_WORD_LEN_24, RNG_80_MV | SPI_LAST
};

Here's line 294 of the .cpp file:

ftare += measure(channel, RNG_10_MV) - 8388608.0;

Here's the line from the .ino file:

const double adcFullScale = 8388608.0;

Here's line 396 and onwards of the .cpp file:

void LoadCellAD7730::setUnipolar(bool unipolar)
{
 WxSpi.write_read(readModeCmds, spiReadBuffer, (byte)sizeof(spiReadBuffer));

 spiReadBuffer[1] = (spiReadBuffer[1] & ~MODEH_UNIPOLAR) | (unipolar ? MODEH_UNIPOLAR : 0);
 memcpy(spiWriteBuffer, writeModeCmds, sizeof(writeModeCmds));
 spiWriteBuffer[1] |= spiReadBuffer[1];
 spiWriteBuffer[2] |= spiReadBuffer[2];

 WxSpi.write_read((const unsigned int*)spiWriteBuffer, spiReadBuffer, sizeof(spiReadBuffer));
}

Question (3): On line 139 of LoadCell.cpp, why a value of “500000UL” has been fed to the function? I thought it should be “5000000UL” which means 5MHz, which is defined in the Timing Characteristics table of AD7730.

WxSpi.begin(500000UL, (byte)3);

I really appreciate it if anyone can come up with some hints or help and I really hope that understanding this library could help other people in their projects as well :) .