AnsweredAssumed Answered

Guidance on Using the ADIS16228 w/ Raspberry PI

Question asked by robert_choe on Jun 18, 2018
Latest reply on Jul 18, 2018 by PiSens

Hi!

I am currently working on a project at my internship @ Volvo Group where I am using the ADIS16228 to perform real-time condition monitoring on one of the machines here. I am planning on taking the vibration data from the adis16228 and performing machine learning algorithms on it. 

 

I am fairly new to programming sensors, SPI communication, and using the PI and was hoping to get some guidance on my code, but have a basic knowledge on them.

 

My goal is to get data in the following format:

| x , y , z

| x , y , z

| x , y , z

| x, y, z

.

.

.

 

where my sampling frequency is 20.4 ksps and the sampling period will be 5 seconds. 

 

I am placing the adis16228 in real-time sampling mode (REC_CTRL[1:0] = 11), and I think the course of action is to to perform a read to the x_buf, y_buf, and z_buf registers after I do a real-time sample for 5 seconds.

 

I guess I am confused at this part. When i start the record GLOB_CMD[11] = 1, do I do a delay for five seconds, then set GLOB_CMD[11] = 0?

Then after this, will my buffers look like this?

x_BUF: x1,x2,x3,x4,x5,x6.............................................................x100000

y_BUF: y1,y2,y3,y4,y5,y6....................................................y100000

z_BUF: z1,z2,z3,z4,z5...............

 

If so, when I read each register, will each read command move the pointer in the buffer, or is that something I have to manually keep track of?

 

I am currently using wiringPI to read and write to registers.

Here is my code so far, will much left to write

<

#include <wiringPiSPI>
#include <wiringSerial.h>

#define CE0 10 //GPI008 which is pin 24 which is CE0 is 10 in wiringPi number
#define CE0_CHANNEL 0
#define CE1_CHANNEL 0
#define LOW 0
#define HIGH 1
#define TEMP_OUT 0x08
#define GLOB_CMD 0x3E
#define REC_CTRL1 0x1A
#define REC_CTRL2 0x1C
#define AVG_CNT 0x3A
#define X_BUF_ADDR 0x14
#define Y_BUF 0x16
#define Z_BUF 0x18

char values[16];
int x,y,z;

const char * setup(void) {

wiringPiSetupGPIO();
wiringPiSPISetup (CE0_CHANNEL, 50000) ; //Setting chip select 0, to a speed of 50000Hz
pinMode(CE0, OUTPUT);
delay(50);

//recording mode
writeRegister(REC_CTRL1,0000000000000011 );
delay(50);
//Sampling Rate: 20,480 SPS
writeRegister(AVG_CNT, 000000000000000, 16);
delay(50);
//Sensitivity: 0 to 5g
writeRegister(REC_CTRL2,000000001010101);
delay(50);

return "ADIS16228 intialized";

}
void writeRegister(int addr, int cmmd) {
digitalWrite(CE0, LOW);
wiringPiSPIDataRW(CE0_CHANNEL, addr, 16);
wiringPiSPIDataRW(CE0_CHANNEL, cmmd, 16);
digitalWrite(CE0, HIGH);
}

int readRegister(int addr) {
digitalWrite(CE0, LOW);
wiringPiSPIDataRW(CE0_CHANNEL, addr, 16);
return wiringPiSPIDataRW(CE0_CHANNEL, 0x00, 16);
}

const char * shutDown(void) {
writeRegister(GLOB_CMD, 0000000000000010);
return "ADIS16228 Powered Down";
}

 

//wirting to a register
//Set RW = 0 to communciate target address
//
//
//could do start_recrod that that in int arg, and that dermines recording mode REC_CTRL1
void start_record(void) {

writeRegister(GLOB_CMD, 0000100000000000 );

delay(50);

}

int read_x_data(void) {
int x;
//set chip select CE0/ pin #24/ GPIO08 to LOW (0)
pinMode(CE0, OUTPUT);
delay(500);
digitalWrite(CE0, LOW);
delay(500);

x = wiringPiSPIDataRW(CEO_CHANNEL, X_BUF_ADDR, 16); //num of bytes
delay(500);

digitalWrite(CE0, HIGH);
return x;
}


int main (void) {
setup();


}

>

Outcomes