Yoichi Nagashima
/
CQ_nagasm_07_2ch
2-channel version with host PC control
main.cpp@0:0bf587c74eb7, 2014-12-16 (annotated)
- Committer:
- nagasm
- Date:
- Tue Dec 16 02:29:14 2014 +0000
- Revision:
- 0:0bf587c74eb7
2-channel version with host PC control
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nagasm | 0:0bf587c74eb7 | 1 | #include "mbed.h" |
nagasm | 0:0bf587c74eb7 | 2 | #include "sub.hpp" |
nagasm | 0:0bf587c74eb7 | 3 | #include "FIR_LPF.hpp" |
nagasm | 0:0bf587c74eb7 | 4 | |
nagasm | 0:0bf587c74eb7 | 5 | int main(){ |
nagasm | 0:0bf587c74eb7 | 6 | common_setup(); |
nagasm | 0:0bf587c74eb7 | 7 | xbee.baud(38400); |
nagasm | 0:0bf587c74eb7 | 8 | xbee.attach(&rx_fifoset, xbee.RxIrq); |
nagasm | 0:0bf587c74eb7 | 9 | timer_setup.attach_us(&timer_interrupt, 5); // 5usec |
nagasm | 0:0bf587c74eb7 | 10 | while(1){ |
nagasm | 0:0bf587c74eb7 | 11 | tx_fifo_check(); |
nagasm | 0:0bf587c74eb7 | 12 | if(timer_value[1] > 19){ // 0.1msec sampling |
nagasm | 0:0bf587c74eb7 | 13 | timer_value[1] = 0; |
nagasm | 0:0bf587c74eb7 | 14 | float data1 = (float)gain * (analog_value2.read() - 0.5f); // A/D in (3) |
nagasm | 0:0bf587c74eb7 | 15 | if (data1 < 0) data1 = -data1; // always detection ON |
nagasm | 0:0bf587c74eb7 | 16 | if (fir_lpf != 0) data1 = FIR_calc1(data1); // FIR calc (1) call |
nagasm | 0:0bf587c74eb7 | 17 | if(timer_value[2] > 2999){ // 15msec |
nagasm | 0:0bf587c74eb7 | 18 | timer_value[2] = 0; |
nagasm | 0:0bf587c74eb7 | 19 | if(max_count != 0) data1 = move_mean_calc1(data1); |
nagasm | 0:0bf587c74eb7 | 20 | tx_message((uint16_t)((data1 + 1.0f) * 2047)<<4); |
nagasm | 0:0bf587c74eb7 | 21 | } |
nagasm | 0:0bf587c74eb7 | 22 | } |
nagasm | 0:0bf587c74eb7 | 23 | if(timer_value[3] > 19){ // 0.1msec sampling |
nagasm | 0:0bf587c74eb7 | 24 | timer_value[3] = 0; |
nagasm | 0:0bf587c74eb7 | 25 | float data2 = (float)gain * (analog_value3.read() - 0.5f); // A/D in (4) |
nagasm | 0:0bf587c74eb7 | 26 | if (data2 < 0) data2 = -data2; // always detection ON |
nagasm | 0:0bf587c74eb7 | 27 | if (fir_lpf != 0) data2 = FIR_calc2(data2); // FIR calc (1) call |
nagasm | 0:0bf587c74eb7 | 28 | if(timer_value[4] > 2999){ // 15msec |
nagasm | 0:0bf587c74eb7 | 29 | timer_value[4] = 0; |
nagasm | 0:0bf587c74eb7 | 30 | if(max_count != 0) data2 = move_mean_calc2(data2); |
nagasm | 0:0bf587c74eb7 | 31 | tx_message(0x400000 + ((uint16_t)((data2 + 1.0f) * 2047)<<4)); |
nagasm | 0:0bf587c74eb7 | 32 | } |
nagasm | 0:0bf587c74eb7 | 33 | } |
nagasm | 0:0bf587c74eb7 | 34 | if(timer_value[0] > 199999){ // 1000msec |
nagasm | 0:0bf587c74eb7 | 35 | timer_value[0] = 0; |
nagasm | 0:0bf587c74eb7 | 36 | myled = !myled; |
nagasm | 0:0bf587c74eb7 | 37 | } |
nagasm | 0:0bf587c74eb7 | 38 | if(rx_fifo_check() == 1){ |
nagasm | 0:0bf587c74eb7 | 39 | int sum = 0; |
nagasm | 0:0bf587c74eb7 | 40 | for (int i=0; i<6; i++) sum += conv_hex(raw_data[i])<<(4*(5-i)); |
nagasm | 0:0bf587c74eb7 | 41 | tx_message(sum); // Echo Back |
nagasm | 0:0bf587c74eb7 | 42 | if(sum>>16 == 0x80){ |
nagasm | 0:0bf587c74eb7 | 43 | switch((sum & 0xff00)>>8){ |
nagasm | 0:0bf587c74eb7 | 44 | case 0x00: |
nagasm | 0:0bf587c74eb7 | 45 | fir_lpf = sum & 0x01; |
nagasm | 0:0bf587c74eb7 | 46 | break; |
nagasm | 0:0bf587c74eb7 | 47 | case 0x01: |
nagasm | 0:0bf587c74eb7 | 48 | gain = sum & 0x0f; |
nagasm | 0:0bf587c74eb7 | 49 | break; |
nagasm | 0:0bf587c74eb7 | 50 | case 0x02: |
nagasm | 0:0bf587c74eb7 | 51 | max_count = sum & 0x7f; |
nagasm | 0:0bf587c74eb7 | 52 | if (max_count>100) max_count = 100; |
nagasm | 0:0bf587c74eb7 | 53 | sum_clear(); |
nagasm | 0:0bf587c74eb7 | 54 | break; |
nagasm | 0:0bf587c74eb7 | 55 | } |
nagasm | 0:0bf587c74eb7 | 56 | } |
nagasm | 0:0bf587c74eb7 | 57 | } |
nagasm | 0:0bf587c74eb7 | 58 | } |
nagasm | 0:0bf587c74eb7 | 59 | } |