james kain / Mbed 2 deprecated GPS_Incremental

Dependencies:   mbed

Fork of GPS_Incremental by Dan Matthews

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