Search FAQs on the left to see if your question has been answered. Click on the dropdown to view all of the documents associated with the product. If you can't find your question, click on Ask a Question

Example Parity Check on the AD719X family

Example Parity Check on the AD719X family by olso4539

Hi all,

From the AD7193 data sheet...

"When the ENPAR bit in the mode register is set to 1, parity is enabled. The contents of the status register must be transmitted along with each 24-bit conversion when the parity function is enabled. To append the contents of the status register to each conversion read, the DAT_STA bit in the mode register should be set to 1. For each conversion read, the parity bit in the status register is programmed so that the overall number of 1s trans-mitted in the 24-bit data-word is even. Therefore, for example, if the 24-bit conversion contains 11 ones (binary format), the parity bit is set to 1 so that the total number of 1s in the serial transmission is even. If the microprocessor receives an odd number of 1s, it knows that the data received has been corrupted.

The parity function does not ensure that all errors are detected. For example, two bits of corrupt data can result in the micro-processor receiving an even number of 1s. Therefore, an error condition is not detected."

I decided to post a quick example of how to check for parity.  I use 32 bit words (24 data bits + 8 bit status register).  Note that the parity bit does not ensure that the entire 32 bit word has an even number of bits, only the 24 bits of data plus the parity bit.

unsigned long BitCount(unsigned long x) { //where unsigned long is 32 bits, this code was written for a pic32

    x -= ((x >> 1) & 0x55555555);

    x = ((x >> 2) & 0x33333333) + (x & 0x33333333);

    x = ((x >> 4) + x) & 0x0F0F0F0F;

    x *= 0x01010101;

    return (x >> 24);


if (BitCount(ADCValue & 0xFFFFFF10) & 1) { //Mask for the 24 data value plus the parity bit, count the bits, check LSB to see if it is odd