Yoichi Nagashima
/
CQ_nagasm_08_notch_test
add 60Hz/50Hz notch filter
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "sub.hpp" 00003 #include "FIR_LPF.hpp" 00004 #include "notch.hpp" 00005 00006 int main(){ 00007 common_setup(); 00008 xbee.baud(38400); 00009 xbee.attach(&rx_fifoset, xbee.RxIrq); 00010 timer_setup.attach_us(&timer_interrupt, 5); // 5usec 00011 notch_1 = notch_2 = 1; 00012 coef_set(60); // Ham notch filter set 00013 while(1){ 00014 tx_fifo_check(); 00015 if(timer_value[1] > 19){ // 0.1msec sampling 00016 timer_value[1] = 0; 00017 float data1 = (float)gain * (analog_value2.read() - 0.5f); // A/D in (3) 00018 if (data1 < 0) data1 = -data1; // always detection ON 00019 if (fir_lpf != 0) data1 = FIR_calc1(data1); // FIR calc (1) call 00020 if (notch_1 != 0) data1 = notch_filter1(data1); 00021 if(timer_value[2] > 2999){ // 15msec 00022 timer_value[2] = 0; 00023 if(max_count != 0) data1 = move_mean_calc1(data1); 00024 tx_message((uint16_t)((data1 + 1.0f) * 2047)<<4); 00025 } 00026 } 00027 if(timer_value[3] > 19){ // 0.1msec sampling 00028 timer_value[3] = 0; 00029 float data2 = (float)gain * (analog_value3.read() - 0.5f); // A/D in (4) 00030 if (data2 < 0) data2 = -data2; // always detection ON 00031 if (fir_lpf != 0) data2 = FIR_calc2(data2); // FIR calc (1) call 00032 if (notch_2 != 0) data2 = notch_filter2(data2); 00033 if(timer_value[4] > 2999){ // 15msec 00034 timer_value[4] = 0; 00035 if(max_count != 0) data2 = move_mean_calc2(data2); 00036 tx_message(0x400000 + ((uint16_t)((data2 + 1.0f) * 2047)<<4)); 00037 } 00038 } 00039 if(timer_value[0] > 199999){ // 1000msec 00040 timer_value[0] = 0; 00041 myled = !myled; 00042 } 00043 if(rx_fifo_check() == 1){ 00044 int sum = 0; 00045 for (int i=0; i<6; i++) sum += conv_hex(raw_data[i])<<(4*(5-i)); 00046 tx_message(sum); // Echo Back 00047 if(sum>>16 == 0x80){ 00048 switch((sum & 0xff00)>>8){ 00049 case 0x00: 00050 fir_lpf = sum & 0x01; 00051 break; 00052 case 0x01: 00053 gain = sum & 0x0f; 00054 break; 00055 case 0x02: 00056 max_count = sum & 0x7f; 00057 if (max_count>100) max_count = 100; 00058 sum_clear(); 00059 break; 00060 case 0x03: 00061 notch_1 = sum & 0x01; 00062 break; 00063 case 0x04: 00064 notch_2 = sum & 0x01; 00065 break; 00066 case 0x05: 00067 coef_set(sum & 0x3f); 00068 break; 00069 } 00070 } 00071 } 00072 } 00073 }
Generated on Wed Jul 13 2022 21:57:35 by 1.7.2