Hi, using the Waveshare ADS1256 HAT for a Raspberry based DAQ. I have it reading in at a good rate (4 channels, 1 kHz), and want to clarify a couple things about the spec and my code.
So first, my WaitDRDY() function is just a while loop, intend to implement that off an interrupt eventually. It works now, but could be more efficient.
The big one is the filter settling time per Table 13 in the spec and how I'm implementing it. My understanding is that when the multiplexer switches from one channel to the next, it takes a certain length of time to sample that new value and filter it out, presumably to prevent the previous channel from ghosting onto the new one. At my 30 ksps rate, I should allow 210 us for that to happen, and that's T18 on the attached sequence. So in my code, I timestamp between sync and wakeup, send the wakeup and data read commands, then have a while loop that waits 210 us before the next set of events. I've tried moving that buffer array to before the while loop, but then I get garbage data. Wondering if I have the timing sequence understood correctly, and if there's a slicker way to implement that 210 us delay, like driving off the interrupt of some other pin?
Thanks much!
Dave Ruxton
UDOUBLE ADS1256_FastRead(UBYTE Channel){
UDOUBLE Value = 0;
UBYTE buf[3] = {0,0,0};
struct timeval stop, start;
int diffTime;
ADS1256_WaitDRDY(); //Wait till Data Ready pin goes low
ADS1256_SetChannel(Channel); //Write next channel to MUX register (if on chan 0, send chan 1)
ADS1256_WriteCmd(CMD_SYNC); //Send Sync command
gettimeofday(&start, NULL); //Start timestamp for filter settling time (t18 in spec)
ADS1256_WriteCmd(CMD_WAKEUP); //Send Wakeup command
DEV_Digital_Write(DEV_CS_PIN, 0); //Pull down Chip Select Pin (not shown in spec, but apparently necessary?
DEV_SPI_WriteByte(CMD_RDATA); //Send Read Data command
while(1){ //Wait for filter settle time, continuously check timer till time has elapsed
gettimeofday(&stop, NULL);
diffTime = (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec;
if(diffTime >= 210){ //210 us for 30 ksps sample rate per ads1236 spec
break;
}
}
buf[0] = DEV_SPI_ReadByte(); //Read data bytes into array
buf[1] = DEV_SPI_ReadByte();
buf[2] = DEV_SPI_ReadByte();
DEV_Digital_Write(DEV_CS_PIN, 1);
Value = ((UDOUBLE)buf[0] << 16) & 0x00FF0000; //Read and shift bytes into Value
Value |= ((UDOUBLE)buf[1] << 8);
Value |= buf[2];
if (Value & 0x800000) //Don't know what this does, was in the original lib
Value &= 0xFF000000;
DEV_Digital_Write(DEV_CS_PIN, 1); //Toggle CS pin high, not sure if necessary, left it in
return Value;
}