Dan Matthews / Mbed 2 deprecated GPS_Incremental-V1_0

Dependencies:   mbed

Fork of GPS_Incremental by james kain

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 short msgID;
00026     unsigned long GPSTime;
00027     long dataWord[6];
00028     //  4 + 2 + 4 + 24 = 34
00029 } imuRec;
00030 
00031 void IMUDataReadyISR(void)
00032 {   
00033     IMUDataReady = true;
00034     return;
00035 } 
00036 
00037 void setupADIS(void)
00038 {
00039     ADIS_DR.mode(PullDown);
00040     ADIS_RST = 0;
00041     
00042     //  set the IMU dataReady ISR
00043     ADIS_DR.rise(&IMUDataReadyISR);
00044     
00045     // Setup the mbed SPI for 16 bit data, high steady state clock,
00046     // second edge capture, with a 1MHz clock rate
00047     spi.format(16,3);
00048     spi.frequency(1000000);   
00049     
00050     ADIS_CS = 1;  //CS must be set high before it goes low cause the enable is the transition
00051     ADIS_RST = 1;
00052     wait(0.5);
00053     ADIS_CS = 0; //set the Chip select low to enable the IMU SPI access
00054     
00055     spi.write((int)0x8003);  //change to page 3
00056     
00057     //change the DECRATE to 98.4 Hz (this is also in page 3)
00058     //the 8 sets the high bit to 1 indicating a write to a register
00059     // The C abd D designate the registers for the DECRATE of Page 3
00060     // The 17 sets the rate to:  2460/(23+1) = 102.5Hz
00061     spi.write((int)0x8C17);    //write high byte  (only page number can be written in a single byte)
00062     spi.write((int)0x8D00);    //write the low byte of DECRATE 
00063     
00064     //to set the GPS VARF clock as the input synch clock for the IMU
00065     //the high byte is CD indicating the synch is enabled on the rising edge of the input clock  
00066     //spi.write((int)0x86CD);    //write high byte to register 0x06
00067     //spi.write((int)0x8700);    //write the low byte of 00 to registed 0x07
00068     
00069     //change the page to 0 to get the data
00070     spi.write((int)0x8000);  //change to page 0
00071     
00072     toPC.printf(" setting the default values\n");
00073     
00074     //set the IMU synch and message ID
00075     imuRec.synch = 0x1C1244AA;  //same as the GPS synch words
00076 
00077     imuRec.msgID=111;  //IMU record ID
00078     
00079     toPC.printf(" finished setting the default values\n");
00080 
00081 }