![]() |
LPCOpen Platform for LPC18XX/43XX microcontrollers
18XX43XX
LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers
|
HSADC samples are 12-bit in size and included appended status information. an optional channel ID, and may be packed with another sample. These support functions and macros allow the sample data from the FIFO or a DMA stream to be separated into it's individual parts.
Getting and checking the HSADC sample
A HSADC sample can be read from the HSADC FIFO with the Chip_HSADC_GetFIFO() function. It will read the oldest entry from the FIFO. The sample includes a valid data status flag and optional channel ID. The sample may also be packed with another sample.
To determine if the sample is packed with another sample, mask the sample value with HSADC_FIFO_PACKEDMASK. If another sample exists, the other sample can be extracted with the HSADC_FIFO_SHIFTPACKED() macro.
Use the HSADC_FIFO_SAMPLE() and HSADC_FIFO_CHAN_ID() macros to strip out the data and channel ID from the sample. Mask the sample with the HSADC_FIFO_EMPTY definition to determine if the sample is valid.
uint32_t ch, data, sample[2];
/* Get sample or packed samples */
sample[0] = Chip_HSADC_GetFIFO(LPC_ADCHS);
/* Is sample valid? */
if (!(sample[0] & HSADC_FIFO_EMPTY)) {
/* Sample is not empty, shift off sample data and channel */
data = HSADC_FIFO_SAMPLE(sample[0]);
data = HSADC_FIFO_CHAN_ID(sample[0]);
}
/* Check for packed sample. Only need to do this if sample packing is
enabled */
if (sample[0] & HSADC_FIFO_PACKEDMASK) {
/* Packed sample exists, so get it */
sample[1] = HSADC_FIFO_SHIFTPACKED(sample[0]);
}
1.8.3.1