2014-12-10 5:41 1 second pulse (serial)
Dependencies: MODSERIALhacked Convert SLCD mbed-src
Diff: main.cpp
- Revision:
- 12:c97d6cd17314
- Parent:
- 11:79eabc671800
--- a/main.cpp Thu Dec 18 06:31:26 2014 +0000 +++ b/main.cpp Thu Dec 18 10:56:52 2014 +0000 @@ -45,9 +45,9 @@ Timer timer; long long offset = 0; -DoubleBuffer<unsigned short, 20> light_sensor_buffer; -DoubleBuffer<unsigned short, 250> adc_buffer; -DoubleBuffer<long long, 100> d_event_buffer; +DoubleBuffer<unsigned short, 50> light_sensor_buffer; +DoubleBuffer<unsigned short, 500> adc_buffer; +DoubleBuffer<long long, 30> d_event_buffer; //initialize variables Ticker ticker; @@ -185,7 +185,7 @@ // get data from the (2) light sensor (3) analog pin //let_there_be_light = my_light_sensor.read(); unsigned short light_val = my_light_sensor.read_u16(); - light_sensor_buffer.write(light_val); + light_sensor_buffer.write(light_val, ((long long) timer.read_us()) - offset); //my_analog_value = my_analog_pin.read(); // print the analog values to uart @@ -270,19 +270,19 @@ case ADC_SAMP_FREQ_1HZ: if (tick_count % 10000 == 0) { //read_adc(); - adc_buffer.write(my_analog_pin.read_u16()); + adc_buffer.write(my_analog_pin.read_u16(), ((long long) timer.read_us()) - offset); } break; case ADC_SAMP_FREQ_10HZ: if (tick_count % 1000 == 0) { //read_adc(); - adc_buffer.write(my_analog_pin.read_u16()); + adc_buffer.write(my_analog_pin.read_u16(), ((long long) timer.read_us()) - offset); } break; case ADC_SAMP_FREQ_100HZ: if (tick_count % 100 == 0) { //read_adc(); - adc_buffer.write(my_analog_pin.read_u16()); + adc_buffer.write(my_analog_pin.read_u16(), ((long long) timer.read_us()) - offset); } break; case ADC_SAMP_FREQ_OFF: @@ -324,12 +324,14 @@ light_sensor_buffer.swapBuff(); unsigned short* sensor_data = light_sensor_buffer.getReadBuffer(); int sensor_data_size = light_sensor_buffer.getReadBufferSize(); + long long* ts = light_sensor_buffer.getTimestampReadBuffer(); // send header pc.putc('l'); send_int(sensor_data_size); for (int i = 0; i < sensor_data_size; i++) { + send_ull(ts[i]); send_us(sensor_data[i]); } } @@ -338,12 +340,14 @@ adc_buffer.swapBuff(); unsigned short* adc_data = adc_buffer.getReadBuffer(); int adc_data_size = adc_buffer.getReadBufferSize(); + long long* ts = adc_buffer.getTimestampReadBuffer(); // send header pc.putc('a'); send_int(adc_data_size); for (int i = 0; i < adc_data_size; i++) { + send_ull(ts[i]); send_us(adc_data[i]); } } @@ -374,7 +378,7 @@ void d_event(){ // take timestamp, send it to thingspeak later long long ts = timer.read_us() - offset; - d_event_buffer.write(ts); + d_event_buffer.write(ts, ts); } int sync_timestamp = 0; @@ -393,6 +397,9 @@ { redled = true; timer.start(); + light_sensor_buffer.init(&offset, &timer); + adc_buffer.init(&offset, &timer); + d_event_buffer.init(&offset, &timer); //initialize hardware systick_attach(); d_event_pin.rise(&d_event); @@ -490,7 +497,10 @@ long long time_s = time_us / 1000000; long long time_m = time_s / 60; long long time_h = time_m / 60; - pc.printf("time: %lld:%lld:%lld:%lld\n", time_h % 24, time_m % 60, time_s % 60, time_us % 1000000); + //pc.printf("time: %lld:%lld:%lld:%lld\n", time_h % 24, time_m % 60, time_s % 60, time_us % 1000000); + long long* lsdt1 = light_sensor_buffer.db_timestamps[0]; + long long* lsdt2 = light_sensor_buffer.db_timestamps[1]; + pc.printf("lsd[0][0] %lld [0][1] %lld [0][2] %lld [1][0] %lld [1][1] %lld [1][2] %lld\n", lsdt1[0], lsdt1[1], lsdt1[2], lsdt2[0], lsdt2[1], lsdt2[2]); // detach the systick, then reattach at the right time