Jim Cooke
/
Hat_Board_v5_1
Slight Mod
Fork of Hat_Board_v5 by
Diff: main.cpp
- Revision:
- 2:3a8cd127b72a
- Parent:
- 1:2efeed26d93a
- Child:
- 3:8334f137c151
--- a/main.cpp Thu Mar 20 09:03:12 2014 +0000 +++ b/main.cpp Thu Mar 20 09:49:36 2014 +0000 @@ -16,94 +16,65 @@ int reading_IR,reading_660,LSB,MSB; char rx_data[4]; -char accel_2_data[2]; char accel_data[6]; char temp_val; short int temp_dataX; // short int: 16 bits. This allows easy negative results short int temp_dataY; // short int: 16 bits. This allows easy negative results short int temp_dataZ; // short int: 16 bits. This allows easy negative results - -/* From AccelWaveForms -In Loop: -*/ +float t_msec; int main() { unsigned char LowB_IR,HighB_IR,LowB_660,HighB_660; - char Reg_Val = 0x00; - char Reg_Num; myled4 = 0; // ODD: if this line not included, there is a compiler "internal error" pc.baud(230400); - i2c_start(); //sets i2c bus at 400,000. Also set by photodiode setup/reset - - Reg_Num = 0x20; // CTRL_REG1 - Reg_Val = 0x57; // Nib 1 of 0101: Normal mode, 100 Hz; Nib 2 of 0111: Normal mode, XYZ enabled - Init_Accel (Reg_Num, Reg_Val); - - wait(0.050); // Delay needed, or 2nd write doesn't work + Init_Accel(); // starts LIS3DH + restart(); // starts Si1142 - Reg_Num = 0x21; // CTRL_REG2 - Reg_Val = 0xA0; // 7-6 10: Normal filter mode; 5-4 10: Cut off freq; 3-0 0000: bypass interrupts - // High-pass filter bits 5-4: @ 100 Hz: 00 - 2Hz 01 - 1Hz 10- 0.5Hz 11- 0.2Hz - Init_Accel (Reg_Num, Reg_Val); - wait(0.050); // Delay needed? + wait_ms(30); + command (PS_AUTO); //start measuring + wait (0.5); - pc.printf ("Hello\n"); + while(1) { + if(!int_pin) { - Get_Accel_Register (0x0F); - pc.printf ("I am: %x",accel_data[0]); //in hex + myled3 = !myled3; // LED on mbed, to follow along - while (1) { + t.reset(); + t.start(); - Get_Accel_Reg_6 (0x28); - LSB = accel_data[0]; - MSB = accel_data[1]; - temp_dataX = (MSB * 256) + LSB; - pc.printf ("%d, ",temp_dataX); + write_reg(IRQ_STATUS,0x04); // clear the interrupt. - LSB = accel_data[2]; - MSB = accel_data[3]; - temp_dataY = (MSB * 256) + LSB; - pc.printf ("%d, ",temp_dataY); + read_reg2(PS1_DATA0); + LowB_IR = rx_data[0]; + HighB_IR = rx_data[1]; - LSB = accel_data[4]; - MSB = accel_data[5]; - temp_dataZ = (MSB * 256) + LSB; - pc.printf ("%d\n",temp_dataZ); + LowB_660 = rx_data[2]; + HighB_660 = rx_data[3]; + reading_IR = (HighB_IR * 256) + LowB_IR; + reading_660 = (HighB_660 * 256) + LowB_660; - wait(0.02); - } - /* - restart(); - wait_ms(30); - command (PS_AUTO); //start measuring - wait (0.5); + pc.printf ("%d, %d, ", reading_IR,reading_660); - while(1) { - if(!int_pin) { + Get_Accel_Reg_6 (0x28); - myled3 = !myled3; // LED on mbed, to follow along + temp_dataX = (accel_data[1] * 256) + accel_data[0]; + pc.printf ("%d, ",temp_dataX); - // t.reset(); - // t.start(); - write_reg(IRQ_STATUS,0x04); // clear the interrupt. + temp_dataY = (accel_data[3] * 256) + accel_data[2]; + pc.printf ("%d, ",temp_dataY); - read_reg2(PS1_DATA0); - LowB_IR = rx_data[0]; - HighB_IR = rx_data[1]; + temp_dataZ = (accel_data[5] * 256) + accel_data[4]; + pc.printf ("%d, ",temp_dataZ); - LowB_660 = rx_data[2]; - HighB_660 = rx_data[3]; + t.stop(); + t_msec = t.read() * 1000; + printf("%4.1f msec\n", t_msec); + } + } - reading_IR = (HighB_IR * 256) + LowB_IR; - reading_660 = (HighB_660 * 256) + LowB_660; - - pc.printf ("%d,%d\n", reading_IR,reading_660); - } - } - */ } /*