Post by Admin on Sept 29, 2017 8:37:41 GMT
We have been experimenting with the Digilent Analog Shield. This has the TI ADS8343 4-channel 16-bit ADC chip. The 16bit ADC converter has four analogue input channels AN0-AN3. On the Digilent Analogue Shield an op amp front end on the PCB provides a bipolar input range of -5V to +5V. The A to D converter output of the chip is via a three wire SPI interface. The readings are provided in a 2’s complement format allowing an effective signed 16bit number to represent the result from 0x8000 (-5V) to 0x7FFF (+5V).
We needed this for a project for which the 12-bit resolution of the TC275's ADC was insufficient. The ADS8343 is SPI-driven and the timing of the SPI messages is critical if accurate periodic sampling is required. A simple driver (attached) uses a bit-bashed SPI to operate the ADC chip. This is more deterministic than the usual SPI driver. However it is important that it is not interrupted by anything so the interrupts are disabled before the driver is called:
#include "analogshield.h"
/* Convert ADS8343 output to a signed number */
#define MakeSigned(a) (a & 0x4000) ? a=a-32768:a=a;
typedef union { uint8 Bytes[2]; uint16 Word; sint16 Sword; } BWtype ;
BWtype ADC_RawData[4];
/* Sample ADC from analog shield first two channels */
_disable(); /* Disable interrupts to guarantee fixed timing as far as possible */
ADC_Temp0 = analog.signedRead(0,0);
ADC_Temp1 = analog.signedRead(1,0);
ADC_Temp2 = analog.signedRead(2,0);
ADC_Temp3 = analog.signedRead(3,0);
_enable();
/* Correct for signed value */
ADC_RawData[0].Sword = MakeSigned(ADC_Temp0);
ADC_RawData[1].Sword = MakeSigned(ADC_Temp1);
ADC_RawData[2].Sword = MakeSigned(ADC_Temp2);
ADC_RawData[3].Sword = MakeSigned(ADC_Temp3);
The next ShieldBuddy release will contain a QSPI-driven version which uses a GTM timer to guarantee the accuracy of the sampling rate...
analogShield.cpp (17.28 KB)analogShield.h (4.82 KB)
We needed this for a project for which the 12-bit resolution of the TC275's ADC was insufficient. The ADS8343 is SPI-driven and the timing of the SPI messages is critical if accurate periodic sampling is required. A simple driver (attached) uses a bit-bashed SPI to operate the ADC chip. This is more deterministic than the usual SPI driver. However it is important that it is not interrupted by anything so the interrupts are disabled before the driver is called:
#include "analogshield.h"
/* Convert ADS8343 output to a signed number */
#define MakeSigned(a) (a & 0x4000) ? a=a-32768:a=a;
typedef union { uint8 Bytes[2]; uint16 Word; sint16 Sword; } BWtype ;
BWtype ADC_RawData[4];
/* Sample ADC from analog shield first two channels */
_disable(); /* Disable interrupts to guarantee fixed timing as far as possible */
ADC_Temp0 = analog.signedRead(0,0);
ADC_Temp1 = analog.signedRead(1,0);
ADC_Temp2 = analog.signedRead(2,0);
ADC_Temp3 = analog.signedRead(3,0);
_enable();
/* Correct for signed value */
ADC_RawData[0].Sword = MakeSigned(ADC_Temp0);
ADC_RawData[1].Sword = MakeSigned(ADC_Temp1);
ADC_RawData[2].Sword = MakeSigned(ADC_Temp2);
ADC_RawData[3].Sword = MakeSigned(ADC_Temp3);
The next ShieldBuddy release will contain a QSPI-driven version which uses a GTM timer to guarantee the accuracy of the sampling rate...
analogShield.cpp (17.28 KB)analogShield.h (4.82 KB)