Hello, I am working on a vibration analysis program in LabView that uses data from a piezo accelerometer. I've got an Analog Devices CN0350 charge amplifier/adc board that is communicating via SPI with a Due, which is using native USB to send the data to LabView. However, I'm getting strange results from the adc; if I slowly shake the accelerometer, instead of reading a smooth sine wave, the waveform is rough and past a certain amplitude, looks like the peaks are either clipping or sometimes even getting transposed to the center. I reconfigured the charge amplifier to match my accelerometer but verified with an oscilloscope that it is working correctly and within the voltage range of the adc. And it's not a LabView issue, since the incoming data looks the same in the Arduino IDE's serial monitor/plotter. I attached a screenshot from LabView and put the code below. I found this program in another thread but modified it slightly for native usb and to print a formatted string. Any advice would be greatly appreciated. Thanks!
#include<SPI.h>
#define CONVST 9
#define SS 10
char format[50];
void AD7091R_init_conv() {
digitalWrite(CONVST, LOW);
delayMicroseconds(1);
digitalWrite(CONVST, HIGH);
}
void AD7091R_soft_reset() {
AD7091R_init_conv();
digitalWrite(SS, LOW);
SPI.transfer(0x00);
digitalWrite(SS, HIGH);
delayMicroseconds(1);
AD7091R_init_conv();
delayMicroseconds(1);
}
void setup()
{
//Initialize serial and wait for port to open:
SerialUSB.begin(9600);
while (!SerialUSB) {
; // wait for serial port to connect. Needed for native USB
}
// Serial.begin(115200);
SPI.begin();
pinMode(CONVST, OUTPUT);
digitalWrite(CONVST, HIGH);
pinMode(SS, OUTPUT);
digitalWrite(SS, HIGH);
AD7091R_soft_reset();
}
void loop()
{
AD7091R_init_conv();
delayMicroseconds(1);
digitalWrite(SS, LOW);
uint16_t val = SPI.transfer(0x00); //receive bits 11-4
byte x = SPI.transfer(0x00); //receive bits 3-0 (will be in bits 7-4 of x)
digitalWrite(SS, HIGH);
val = (val << 4) | (x >> 4); //combine the 12 bits read
val &= 0x0FFF; //masking
sprintf(format, "%4d", val);
SerialUSB.println(format); //this is the 12bit ADC value 0-4095
//Serial.println(val);
delayMicroseconds(300); //arbitrary loop delay
}
