Dan Matthews / Mbed 2 deprecated GPS_Incremental

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ADIS16488.h Source File

ADIS16488.h

00001 
00002 
00003 
00004 //set up the SPI on pins 5, 6, 7 to read from the ADIS16488
00005 SPI spi(p5, p6, p7); // mosi (DIN), miso (DOUT), sclk (CLK)
00006 DigitalOut ADIS_CS(p8);     //Chip Select for the ADIS SPI
00007 InterruptIn ADIS_DR(p28);   //DataReady interrupt connected to DIO2 for ADIS
00008 DigitalOut ADIS_RST(p20);   //ADIS reset pin
00009 
00010 bool IMUDataReady = false;
00011 int IMURecordCounter = 0;
00012 //see Table 9 from page 11 of the ADIS16488 spec 
00013 //see fig 15 of spec -- note the low byte of the regsiter word is always zero
00014 // X_DELTANG_LOW, Y_DELTANG_LOW, X_DETANG_LOW, X_DELTVEL_LOW, Y_DELTVEL_LOW, Z_DELTVEL_LOW
00015 unsigned short LOW_REGISTER[]  = {0x4000, 0x4400, 0x4800, 0x4C00, 0x5000, 0x5400};   
00016 // X_DELTANG_HIGH, Y_DELTANG_HIGH, X_DETANG_HIGH, X_DELTVEL_HIGH, Y_DELTVEL_HIGH, Z_DELTVEL_HIGH
00017 unsigned short HIGH_REGISTER[] = {0x4200, 0x4600, 0x4A00, 0x4E00, 0x5200, 0x5600}; 
00018     
00019 union WD { long dataWord; unsigned short pt[2];} wd;
00020 
00021 #pragma pack(1)
00022 struct IMUREC
00023 {
00024     unsigned long synch;
00025     unsigned char msgID;
00026     double GPSTime;
00027     long dataWord[6];
00028 } imuRec;
00029 
00030 
00031 
00032 void IMUDataReadyISR(void)
00033 {   
00034     imuRec.GPSTime = GPSTimemsecs + timeFromPPS.read_us()/1000000.0;
00035     spi.write((int) HIGH_REGISTER[0]); // next read will return results from HIGH_REGITER[0]
00036     for (int i=0; i<6; i++)  //read the 6 rate and accel variables
00037     {
00038         wd.pt[1] = (unsigned short)spi.write((int) LOW_REGISTER[i]) ; 
00039         if (i<5)  // dont this on the last because this was pre-called
00040         {
00041             wd.pt[0] = (unsigned short)spi.write((int) HIGH_REGISTER[i+1]);
00042         }
00043         imuRec.dataWord[i] = wd.dataWord; //data word is a signed long
00044                 
00045      }
00046      IMUDataReady = true;
00047      IMURecordCounter++;
00048   
00049     return;
00050 } 
00051 
00052 void setupADIS(void)
00053 {
00054     ADIS_DR.mode(PullDown);
00055     ADIS_RST = 0;
00056     
00057     printf("\nStart of ADIS test\n");
00058     //  set the IMU dataReady ISR
00059     ADIS_DR.rise(&IMUDataReadyISR);
00060     
00061     // Setup the mbed SPI for 16 bit data, high steady state clock,
00062     // second edge capture, with a 1MHz clock rate
00063     spi.format(16,3);
00064     spi.frequency(1000000);   
00065     
00066     ADIS_CS = 1;  //CS must be set high before it goes low cause the enable is the transition
00067     ADIS_RST = 1;
00068     wait(0.5);
00069     ADIS_CS = 0; //set the Chip select low to enable the IMU SPI access
00070     
00071     spi.write((int)0x8003);  //change to page 3
00072     
00073     //change the DECRATE to 98.4 Hz (this is also in page 3)
00074     //the 8 sets the high bit to 1 indicating a write to a register
00075     // The C abd D designate the registers for the DECRATE of Page 3
00076     // The 17 sets the rate to:  2460/(23+1) = 102.5Hz
00077     spi.write((int)0x8C17);    //write high byte  (only page number can be written in a single byte)
00078     spi.write((int)0x8D00);    //write the low byte of DECRATE 
00079     
00080     //to set the GPS VARF clock as the input synch clock for the IMU
00081     //the high byte is CD indicating the synch is enabled on the rising edge of the input clock  
00082     //spi.write((int)0x86CD);    //write high byte to register 0x06
00083     //spi.write((int)0x8700);    //write the low byte of 00 to registed 0x07
00084     
00085     //change the page to 0 to get the data
00086     spi.write((int)0x8000);  //change to page 0
00087     
00088     //set the IMU synch and message ID
00089     imuRec.synch = 0xAA44121C;  //same as the GPS synch words
00090     imuRec.msgID=111;  //IMU record ID
00091 }