Hello Everyone
Hope all are having great time.
Its my first time asking for a query on forums so please excuse me if I faulter on any of the precedent.
I'm using ADS1256 waveshare board with Raspberry Pi 4B. I have modified the code provided by waveshare, Basically added the timing constraints. Its working fine for single channel outputs but for multi channel outputs its throwing random spikes in the output of upto 2 mV. The bigger spikes are usually of same magnitude so I think I'm violating some delay constraint But I can't figure out where because I have put the delays as per datasheet only. Even if I made delays excessively large on purpose, The problem still remains.
Here's the relevant code snippet
/****************************************************************************** function: Set the channel to be read parameter: Channal : Set channel number Info: ******************************************************************************/ void ADS1256_SetDiffChannal(UBYTE Channal) { if (Channal == 0){ ADS1256_WriteReg(REG_MUX, (0 << 4) | 1); //DiffChannal AIN0-AIN1 } else if(Channal == 1){ ADS1256_WriteReg(REG_MUX, (2 << 4) | 3); //DiffChannal AIN2-AIN3 } else if(Channal == 2){ ADS1256_WriteReg(REG_MUX, (4 << 4) | 5); //DiffChannal AIN4-AIN5 } else if(Channal == 3){ ADS1256_WriteReg(REG_MUX, (6 << 4) | 7); //DiffChannal AIN6-AIN7 } } ******************************************************************************/ static UDOUBLE ADS1256_Read_ADC_Data(void) { UDOUBLE read = 0; UBYTE buf[3] = {0,0,0}; DEV_Digital_Write(DEV_CS_PIN, 0); DEV_Delay_us(1); ADS1256_WaitDRDY(); DEV_SPI_WriteByte(CMD_RDATA); DEV_Delay_us(7); buf[0] = DEV_SPI_ReadByte(); buf[1] = DEV_SPI_ReadByte(); buf[2] = DEV_SPI_ReadByte(); read = ((UDOUBLE)buf[0] << 16) & 0x00FF0000; read |= ((UDOUBLE)buf[1] << 8); /* Pay attention to It is wrong read |= (buf[1] << 8) */ read |= buf[2] ; DEV_Digital_Write(DEV_CS_PIN, 1); return read; } /****************************************************************************** function: Read ADC specified channel data parameter: Channel: Channel number Info: ******************************************************************************/ UDOUBLE ADS1256_GetChannalValue(UBYTE Channel) { UDOUBLE Value = 0; ADS1256_WaitDRDY(); if(Channel>=4){ return 0; } if(channel ==1){ ADS1256_SetDiffChannal(Channel); Value = ADS1256_Read_ADC_Data(); } else{ ADS1256_SetDiffChannal(Channel); DEV_Delay_us(4); ADS1256_WriteCmd(CMD_SYNC); DEV_Delay_us(4); ADS1256_WriteCmd(CMD_WAKEUP); DEV_Delay_us(1); Value = ADS1256_Read_ADC_Data(); } return Value; } /****************************************************************************** function: Read data from all channels parameter: ADC_Value : ADC Value Info: ******************************************************************************/ void ADS1256_GetAll(UDOUBLE *ADC_Value) { UBYTE i; for(i = 0; i<channel; i++){ ADS1256_WaitDRDY(); ADC_Value[i] = ADS1256_GetChannalValue(i); } }
Here's Snapshot of output on 2 channels
I hope I could describe the problem well. If there's anything missing please point it out, I'd add it ASAP.
Thank You Everyone!