Frequency counter using GPS 1PPS signal and temperature controlled 50MHz Base clock. Ported from F411 Frequency Counter.
Dependencies: QEI DRV8830 PID ADT7410 TextLCD Frq_cuntr_Nucleo-F746ZG RingBuffer
Fork of Frequency_Counter_w_GPS_1PPS by
Please refer following.
/users/kenjiArai/notebook/frequency-counters/
User_IF/uif.cpp@14:ba6ea409ab05, 2019-12-17 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue Dec 17 11:41:18 2019 +0000
- Revision:
- 14:ba6ea409ab05
- Parent:
- 13:1041596c416c
- Child:
- 15:ae0413277bc6
Run on mbed-os5 & small modification
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 13:1041596c416c | 1 | /* |
kenjiArai | 13:1041596c416c | 2 | * mbed Application program / User Interface subroutines |
kenjiArai | 13:1041596c416c | 3 | * |
kenjiArai | 14:ba6ea409ab05 | 4 | * Copyright (c) 2016,'19 Kenji Arai / JH1PJL |
kenjiArai | 13:1041596c416c | 5 | * http://www.page.sannet.ne.jp/kenjia/index.html |
kenjiArai | 13:1041596c416c | 6 | * http://mbed.org/users/kenjiArai/ |
kenjiArai | 13:1041596c416c | 7 | * Created: September 28th, 2016 |
kenjiArai | 14:ba6ea409ab05 | 8 | * Revised: December 12th, 2019 |
kenjiArai | 13:1041596c416c | 9 | */ |
kenjiArai | 13:1041596c416c | 10 | |
kenjiArai | 13:1041596c416c | 11 | #define USE_COM // use Communication with PC(UART) |
kenjiArai | 13:1041596c416c | 12 | |
kenjiArai | 13:1041596c416c | 13 | // Include -------------------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 14 | #include "mbed.h" |
kenjiArai | 13:1041596c416c | 15 | #include "rtos.h" |
kenjiArai | 13:1041596c416c | 16 | #include "frq_cuntr_f746.h" |
kenjiArai | 13:1041596c416c | 17 | #include "TextLCD.h" |
kenjiArai | 13:1041596c416c | 18 | #include "QEI.h" |
kenjiArai | 13:1041596c416c | 19 | #include "uif.h" |
kenjiArai | 13:1041596c416c | 20 | |
kenjiArai | 13:1041596c416c | 21 | // Definition ----------------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 22 | #define ONLY_VALUE 1 // Uart (output only value) |
kenjiArai | 13:1041596c416c | 23 | |
kenjiArai | 13:1041596c416c | 24 | #ifdef USE_COM |
kenjiArai | 13:1041596c416c | 25 | #define BAUD(x) pc.baud(x) |
kenjiArai | 13:1041596c416c | 26 | #define GETC(x) pc.getc(x) |
kenjiArai | 13:1041596c416c | 27 | #define PUTC(x) pc.putc(x) |
kenjiArai | 13:1041596c416c | 28 | #define PRINTF(...) pc.printf(__VA_ARGS__) |
kenjiArai | 13:1041596c416c | 29 | #define READABLE(x) pc.readable(x) |
kenjiArai | 13:1041596c416c | 30 | #else |
kenjiArai | 13:1041596c416c | 31 | #define BAUD(x) {;} |
kenjiArai | 13:1041596c416c | 32 | #define GETC(x) {;} |
kenjiArai | 13:1041596c416c | 33 | #define PUTC(x) {;} |
kenjiArai | 13:1041596c416c | 34 | #define PRINTF(...) {;} |
kenjiArai | 13:1041596c416c | 35 | #define READABLE(x) {;} |
kenjiArai | 13:1041596c416c | 36 | #endif |
kenjiArai | 13:1041596c416c | 37 | |
kenjiArai | 13:1041596c416c | 38 | // Object --------------------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 39 | extern Serial pc; |
kenjiArai | 13:1041596c416c | 40 | extern Ticker enter_irq; |
kenjiArai | 13:1041596c416c | 41 | extern DigitalOut in_frq_slct; |
kenjiArai | 13:1041596c416c | 42 | extern DigitalInOut prescaler10or20; |
kenjiArai | 13:1041596c416c | 43 | |
kenjiArai | 13:1041596c416c | 44 | QEI rotary(PE_9, PF_13, NC, 24, QEI::X4_ENCODING); //Rotary chB,chA |
kenjiArai | 13:1041596c416c | 45 | TextLCD lcd(PD_3, PC_3, PD_4, PD_5, PD_6, PD_7, TextLCD::LCD20x4); |
kenjiArai | 13:1041596c416c | 46 | DigitalOut led_R_gps1pps(PE_7); |
kenjiArai | 13:1041596c416c | 47 | DigitalOut led_G_temp_ok(PE_8); |
kenjiArai | 13:1041596c416c | 48 | DigitalOut led_B_recipro(PG_9); |
kenjiArai | 13:1041596c416c | 49 | DigitalOut led_W_prescaler(PG_14); |
kenjiArai | 13:1041596c416c | 50 | DigitalOut led_R_rotary(PF_15); |
kenjiArai | 13:1041596c416c | 51 | DigitalOut led_G_rotary(PE_13); |
kenjiArai | 13:1041596c416c | 52 | DigitalOut led_B_rotary(PF_14); |
kenjiArai | 13:1041596c416c | 53 | DigitalIn rotary_sw(PE_11); |
kenjiArai | 13:1041596c416c | 54 | |
kenjiArai | 13:1041596c416c | 55 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 13:1041596c416c | 56 | int8_t function_num; |
kenjiArai | 13:1041596c416c | 57 | // working area |
kenjiArai | 13:1041596c416c | 58 | char buf[40]; |
kenjiArai | 13:1041596c416c | 59 | // write mode control |
kenjiArai | 13:1041596c416c | 60 | uint8_t mode_change_flg = 0; |
kenjiArai | 13:1041596c416c | 61 | // Prescaler selct |
kenjiArai | 13:1041596c416c | 62 | uint8_t prescaler_on = 0; |
kenjiArai | 13:1041596c416c | 63 | uint8_t prescaler_div20 = 0; |
kenjiArai | 13:1041596c416c | 64 | // Rotary switch |
kenjiArai | 13:1041596c416c | 65 | uint32_t enter = 0; |
kenjiArai | 13:1041596c416c | 66 | uint8_t enter_first_flg = 0; |
kenjiArai | 13:1041596c416c | 67 | // Time |
kenjiArai | 13:1041596c416c | 68 | time_t seconds; |
kenjiArai | 13:1041596c416c | 69 | time_t seconds_jst; |
kenjiArai | 13:1041596c416c | 70 | // Reciprocal data |
kenjiArai | 13:1041596c416c | 71 | extern |
kenjiArai | 13:1041596c416c | 72 | uint8_t recipro_new_data_ready; |
kenjiArai | 13:1041596c416c | 73 | |
kenjiArai | 13:1041596c416c | 74 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 75 | static int8_t rotary_sw_update(void); |
kenjiArai | 13:1041596c416c | 76 | static void change_setting(void); |
kenjiArai | 13:1041596c416c | 77 | static void uart_output(dispDef *dt); |
kenjiArai | 13:1041596c416c | 78 | static void led_update(dispDef *dt); |
kenjiArai | 13:1041596c416c | 79 | static void dsp_freq(dispDef *dt); |
kenjiArai | 13:1041596c416c | 80 | static void dsp_1pps(dispDef *dt); |
kenjiArai | 13:1041596c416c | 81 | static void dsp_detail(dispDef *dt); |
kenjiArai | 13:1041596c416c | 82 | static void dsp_simple(dispDef *dt); |
kenjiArai | 13:1041596c416c | 83 | static void dsp_recipro(dispDef *dt); |
kenjiArai | 13:1041596c416c | 84 | static void dsp_gps_status(dispDef *dt); |
kenjiArai | 13:1041596c416c | 85 | static void dsp_current_setting(dispDef *dt); |
kenjiArai | 13:1041596c416c | 86 | |
kenjiArai | 13:1041596c416c | 87 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 88 | // 12345678901234567890 |
kenjiArai | 14:ba6ea409ab05 | 89 | static const char *const msg_clear = " "; |
kenjiArai | 14:ba6ea409ab05 | 90 | static const char *const msg_msg0 = "Frequency Counter "; |
kenjiArai | 14:ba6ea409ab05 | 91 | static const char *const msg_msg1 = " mbed Nucleo F746ZG "; |
kenjiArai | 14:ba6ea409ab05 | 92 | static const char *const msg_msg2 = " by JH1PJL K.Arai "; |
kenjiArai | 14:ba6ea409ab05 | 93 | static const char *const msg_msg3 = " " __DATE__" UTC"; |
kenjiArai | 14:ba6ea409ab05 | 94 | static const char *const msg_msg4 = "Getting GPS,pls wait"; |
kenjiArai | 13:1041596c416c | 95 | |
kenjiArai | 13:1041596c416c | 96 | // function table |
kenjiArai | 13:1041596c416c | 97 | void (*functptr[])(dispDef*) = { |
kenjiArai | 13:1041596c416c | 98 | dsp_freq, |
kenjiArai | 13:1041596c416c | 99 | dsp_1pps, |
kenjiArai | 13:1041596c416c | 100 | dsp_detail, |
kenjiArai | 13:1041596c416c | 101 | dsp_simple, |
kenjiArai | 13:1041596c416c | 102 | dsp_recipro, |
kenjiArai | 13:1041596c416c | 103 | dsp_gps_status, |
kenjiArai | 13:1041596c416c | 104 | dsp_current_setting |
kenjiArai | 13:1041596c416c | 105 | }; |
kenjiArai | 13:1041596c416c | 106 | |
kenjiArai | 13:1041596c416c | 107 | //------------------------------------------------------------------------------ |
kenjiArai | 13:1041596c416c | 108 | // Control Program |
kenjiArai | 13:1041596c416c | 109 | //------------------------------------------------------------------------------ |
kenjiArai | 13:1041596c416c | 110 | void dispay_LCD_and_UART(dispDef *dt) |
kenjiArai | 13:1041596c416c | 111 | { |
kenjiArai | 13:1041596c416c | 112 | uint8_t size; |
kenjiArai | 13:1041596c416c | 113 | |
kenjiArai | 13:1041596c416c | 114 | uart_output(dt); |
kenjiArai | 13:1041596c416c | 115 | display_clear_all(); |
kenjiArai | 13:1041596c416c | 116 | led_update(dt); |
kenjiArai | 13:1041596c416c | 117 | if (mode_change_flg == 0){ |
kenjiArai | 13:1041596c416c | 118 | led_B_rotary = !led_B_rotary; |
kenjiArai | 13:1041596c416c | 119 | led_R_rotary = 0; |
kenjiArai | 13:1041596c416c | 120 | function_num += rotary_sw_update(); |
kenjiArai | 13:1041596c416c | 121 | //size = sizeof(*functptr); // doesn't work |
kenjiArai | 13:1041596c416c | 122 | size = 7; |
kenjiArai | 13:1041596c416c | 123 | if (function_num >= size){ |
kenjiArai | 13:1041596c416c | 124 | function_num = 0; |
kenjiArai | 13:1041596c416c | 125 | } else if (function_num < 0){ |
kenjiArai | 13:1041596c416c | 126 | function_num = size - 1; |
kenjiArai | 13:1041596c416c | 127 | } |
kenjiArai | 13:1041596c416c | 128 | (*functptr[function_num])(dt); // pick one function from a table |
kenjiArai | 13:1041596c416c | 129 | } else { |
kenjiArai | 13:1041596c416c | 130 | led_B_rotary = 0; |
kenjiArai | 13:1041596c416c | 131 | led_R_rotary = !led_R_rotary; |
kenjiArai | 13:1041596c416c | 132 | change_setting(); |
kenjiArai | 13:1041596c416c | 133 | } |
kenjiArai | 13:1041596c416c | 134 | } |
kenjiArai | 13:1041596c416c | 135 | |
kenjiArai | 13:1041596c416c | 136 | void change_setting() |
kenjiArai | 13:1041596c416c | 137 | { |
kenjiArai | 13:1041596c416c | 138 | static int8_t n; |
kenjiArai | 13:1041596c416c | 139 | static int8_t old_mode_change_flg; |
kenjiArai | 13:1041596c416c | 140 | uint8_t p; |
kenjiArai | 13:1041596c416c | 141 | |
kenjiArai | 13:1041596c416c | 142 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 143 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 144 | lcd.printf(" 1/1 BNC"); |
kenjiArai | 13:1041596c416c | 145 | lcd.locate(0, 1); |
kenjiArai | 13:1041596c416c | 146 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 147 | lcd.printf(" 1/10 SMA"); |
kenjiArai | 13:1041596c416c | 148 | lcd.locate(0, 2); |
kenjiArai | 13:1041596c416c | 149 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 150 | lcd.printf(" 1/20 SMA"); |
kenjiArai | 13:1041596c416c | 151 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 152 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 153 | lcd.printf("Select then push SW!"); |
kenjiArai | 13:1041596c416c | 154 | n += rotary_sw_update(); |
kenjiArai | 13:1041596c416c | 155 | if (n < 0){ |
kenjiArai | 13:1041596c416c | 156 | p = n * -1; |
kenjiArai | 13:1041596c416c | 157 | } else { |
kenjiArai | 13:1041596c416c | 158 | p = n; |
kenjiArai | 13:1041596c416c | 159 | } |
kenjiArai | 13:1041596c416c | 160 | p %= 3; |
kenjiArai | 13:1041596c416c | 161 | lcd.locate(0, p); |
kenjiArai | 13:1041596c416c | 162 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 163 | lcd.printf("--->>>"); |
kenjiArai | 13:1041596c416c | 164 | if (old_mode_change_flg != mode_change_flg){ |
kenjiArai | 13:1041596c416c | 165 | if (mode_change_flg == 1){ |
kenjiArai | 13:1041596c416c | 166 | old_mode_change_flg = mode_change_flg; |
kenjiArai | 13:1041596c416c | 167 | } else { |
kenjiArai | 13:1041596c416c | 168 | select_input_div_1or10or20(p); |
kenjiArai | 13:1041596c416c | 169 | mode_change_flg = 0; |
kenjiArai | 13:1041596c416c | 170 | old_mode_change_flg = 0; |
kenjiArai | 13:1041596c416c | 171 | } |
kenjiArai | 13:1041596c416c | 172 | } |
kenjiArai | 13:1041596c416c | 173 | } |
kenjiArai | 13:1041596c416c | 174 | |
kenjiArai | 13:1041596c416c | 175 | // Display LED's |
kenjiArai | 13:1041596c416c | 176 | static void led_update(dispDef *dt) |
kenjiArai | 13:1041596c416c | 177 | { |
kenjiArai | 13:1041596c416c | 178 | if (dt->ready_1pps == 3) { |
kenjiArai | 13:1041596c416c | 179 | led_R_gps1pps = 1; |
kenjiArai | 13:1041596c416c | 180 | } else { |
kenjiArai | 13:1041596c416c | 181 | led_R_gps1pps = 0; |
kenjiArai | 13:1041596c416c | 182 | } |
kenjiArai | 13:1041596c416c | 183 | if (prescaler_on){ |
kenjiArai | 13:1041596c416c | 184 | if (prescaler_div20){ |
kenjiArai | 13:1041596c416c | 185 | led_W_prescaler = !led_W_prescaler; |
kenjiArai | 13:1041596c416c | 186 | } else { |
kenjiArai | 13:1041596c416c | 187 | led_W_prescaler = 1; |
kenjiArai | 13:1041596c416c | 188 | } |
kenjiArai | 13:1041596c416c | 189 | } else { |
kenjiArai | 13:1041596c416c | 190 | led_W_prescaler = 0; |
kenjiArai | 13:1041596c416c | 191 | } |
kenjiArai | 13:1041596c416c | 192 | if (dt->recipro_of == 0){ |
kenjiArai | 13:1041596c416c | 193 | led_B_recipro = 1; |
kenjiArai | 13:1041596c416c | 194 | } else { |
kenjiArai | 13:1041596c416c | 195 | led_B_recipro = 0; |
kenjiArai | 13:1041596c416c | 196 | } |
kenjiArai | 13:1041596c416c | 197 | if (dt->temp_is_okay == 1){ |
kenjiArai | 13:1041596c416c | 198 | led_G_temp_ok = 1; |
kenjiArai | 13:1041596c416c | 199 | } else { |
kenjiArai | 13:1041596c416c | 200 | led_G_temp_ok = 0; |
kenjiArai | 13:1041596c416c | 201 | } |
kenjiArai | 13:1041596c416c | 202 | } |
kenjiArai | 13:1041596c416c | 203 | |
kenjiArai | 13:1041596c416c | 204 | // Data output via VCOM line |
kenjiArai | 13:1041596c416c | 205 | static void uart_output(dispDef *dt) |
kenjiArai | 13:1041596c416c | 206 | { |
kenjiArai | 13:1041596c416c | 207 | static uint32_t n = 0; |
kenjiArai | 13:1041596c416c | 208 | |
kenjiArai | 13:1041596c416c | 209 | PRINTF("%9.0f,", dt->m_frq); |
kenjiArai | 13:1041596c416c | 210 | PRINTF("%10d,", dt->b_1pps_new); |
kenjiArai | 13:1041596c416c | 211 | // compensated |
kenjiArai | 13:1041596c416c | 212 | PRINTF("%12.3f,", dt->m_frq_comp); |
kenjiArai | 13:1041596c416c | 213 | PRINTF("%13.3f,", dt->b_1pps_lng); |
kenjiArai | 13:1041596c416c | 214 | // 10sec data |
kenjiArai | 13:1041596c416c | 215 | PRINTF("%10.1f,", dt->m_frq_10); |
kenjiArai | 13:1041596c416c | 216 | // 100sec data |
kenjiArai | 13:1041596c416c | 217 | PRINTF("%11.2f,", dt->m_frq_100); |
kenjiArai | 13:1041596c416c | 218 | // 1000sec data |
kenjiArai | 13:1041596c416c | 219 | PRINTF("%12.3f,", dt->m_frq_1000); |
kenjiArai | 13:1041596c416c | 220 | if (recipro_new_data_ready){ |
kenjiArai | 13:1041596c416c | 221 | recipro_new_data_ready = 0; |
kenjiArai | 13:1041596c416c | 222 | if (dt->recipro_of){ |
kenjiArai | 13:1041596c416c | 223 | PRINTF("over5KHz ,"); |
kenjiArai | 13:1041596c416c | 224 | } else { |
kenjiArai | 13:1041596c416c | 225 | PRINTF("%12.6f,", dt->m_frq_recipro); |
kenjiArai | 13:1041596c416c | 226 | } |
kenjiArai | 13:1041596c416c | 227 | } else { |
kenjiArai | 13:1041596c416c | 228 | PRINTF("measuring ,"); |
kenjiArai | 13:1041596c416c | 229 | } |
kenjiArai | 13:1041596c416c | 230 | if (prescaler_on){ |
kenjiArai | 13:1041596c416c | 231 | if (prescaler_div20){ |
kenjiArai | 13:1041596c416c | 232 | PRINTF("Div20,"); |
kenjiArai | 13:1041596c416c | 233 | } else { |
kenjiArai | 13:1041596c416c | 234 | PRINTF("Div10,"); |
kenjiArai | 13:1041596c416c | 235 | } |
kenjiArai | 13:1041596c416c | 236 | } else { |
kenjiArai | 13:1041596c416c | 237 | PRINTF("Div1 ,"); |
kenjiArai | 13:1041596c416c | 238 | } |
kenjiArai | 13:1041596c416c | 239 | PRINTF("%+6.3f,", dt->box_tmp); |
kenjiArai | 13:1041596c416c | 240 | seconds = time(NULL); |
kenjiArai | 13:1041596c416c | 241 | seconds_jst = seconds + 32400; // +9 hours ->JST |
kenjiArai | 13:1041596c416c | 242 | // 13:12:11 |
kenjiArai | 13:1041596c416c | 243 | strftime(buf, 40, "%H:%M:%S", localtime(&seconds_jst)); |
kenjiArai | 13:1041596c416c | 244 | PRINTF("%s,", buf); |
kenjiArai | 13:1041596c416c | 245 | // Number |
kenjiArai | 13:1041596c416c | 246 | PRINTF("%08d\r\n", n++); |
kenjiArai | 13:1041596c416c | 247 | } |
kenjiArai | 13:1041596c416c | 248 | |
kenjiArai | 13:1041596c416c | 249 | void select_input_div_1or10or20(uint8_t mode) |
kenjiArai | 13:1041596c416c | 250 | { |
kenjiArai | 13:1041596c416c | 251 | if (mode == 2){ // 1/20 |
kenjiArai | 13:1041596c416c | 252 | prescaler_on = 1; |
kenjiArai | 13:1041596c416c | 253 | prescaler_div20 = 1; |
kenjiArai | 13:1041596c416c | 254 | in_frq_slct = 0; // Select SMA input with pre-scaler |
kenjiArai | 13:1041596c416c | 255 | prescaler10or20.input(); |
kenjiArai | 13:1041596c416c | 256 | } else if (mode == 1){ // 1/10 |
kenjiArai | 13:1041596c416c | 257 | prescaler_on = 1; |
kenjiArai | 13:1041596c416c | 258 | prescaler_div20 = 0; |
kenjiArai | 13:1041596c416c | 259 | in_frq_slct = 0; // Select SMA input with pre-scaler |
kenjiArai | 13:1041596c416c | 260 | prescaler10or20.output(); |
kenjiArai | 13:1041596c416c | 261 | prescaler10or20 = 0; |
kenjiArai | 13:1041596c416c | 262 | } else { |
kenjiArai | 13:1041596c416c | 263 | prescaler_on = 0; |
kenjiArai | 13:1041596c416c | 264 | prescaler_div20 = 0; |
kenjiArai | 13:1041596c416c | 265 | in_frq_slct = 1; // Select BNC |
kenjiArai | 13:1041596c416c | 266 | //prescaler10or20 = 1; |
kenjiArai | 13:1041596c416c | 267 | prescaler10or20.output(); |
kenjiArai | 13:1041596c416c | 268 | prescaler10or20 = 0; |
kenjiArai | 13:1041596c416c | 269 | } |
kenjiArai | 13:1041596c416c | 270 | } |
kenjiArai | 13:1041596c416c | 271 | |
kenjiArai | 13:1041596c416c | 272 | // Interrupt handler for Rotary SW Push bottom |
kenjiArai | 13:1041596c416c | 273 | void enter_action() { |
kenjiArai | 13:1041596c416c | 274 | if (rotary_sw == 1){ |
kenjiArai | 13:1041596c416c | 275 | enter_first_flg = 1; |
kenjiArai | 13:1041596c416c | 276 | } else { |
kenjiArai | 13:1041596c416c | 277 | if (enter_first_flg){ |
kenjiArai | 13:1041596c416c | 278 | if (enter++ > 2){ |
kenjiArai | 13:1041596c416c | 279 | enter = 0; |
kenjiArai | 13:1041596c416c | 280 | mode_change_flg++; // action trigger for SW on |
kenjiArai | 13:1041596c416c | 281 | enter_first_flg = 0; |
kenjiArai | 13:1041596c416c | 282 | } |
kenjiArai | 13:1041596c416c | 283 | } |
kenjiArai | 13:1041596c416c | 284 | } |
kenjiArai | 13:1041596c416c | 285 | } |
kenjiArai | 13:1041596c416c | 286 | |
kenjiArai | 13:1041596c416c | 287 | // Detect rotary switch rotation |
kenjiArai | 13:1041596c416c | 288 | static int8_t rotary_sw_update() |
kenjiArai | 13:1041596c416c | 289 | { |
kenjiArai | 13:1041596c416c | 290 | static int8_t position_old; |
kenjiArai | 13:1041596c416c | 291 | int8_t pos, dt; |
kenjiArai | 13:1041596c416c | 292 | |
kenjiArai | 13:1041596c416c | 293 | pos = rotary.getPulses()/4; |
kenjiArai | 13:1041596c416c | 294 | if (pos != position_old){ |
kenjiArai | 13:1041596c416c | 295 | if (pos > position_old){ |
kenjiArai | 13:1041596c416c | 296 | if (pos < 0){ |
kenjiArai | 13:1041596c416c | 297 | dt = -1; |
kenjiArai | 13:1041596c416c | 298 | } else { |
kenjiArai | 13:1041596c416c | 299 | dt = 1; |
kenjiArai | 13:1041596c416c | 300 | } |
kenjiArai | 13:1041596c416c | 301 | } else { |
kenjiArai | 13:1041596c416c | 302 | if (pos < 0){ |
kenjiArai | 13:1041596c416c | 303 | dt = 1; |
kenjiArai | 13:1041596c416c | 304 | } else { |
kenjiArai | 13:1041596c416c | 305 | dt = -1; |
kenjiArai | 13:1041596c416c | 306 | } |
kenjiArai | 13:1041596c416c | 307 | } |
kenjiArai | 13:1041596c416c | 308 | } else { |
kenjiArai | 13:1041596c416c | 309 | dt = 0; |
kenjiArai | 13:1041596c416c | 310 | } |
kenjiArai | 13:1041596c416c | 311 | position_old = pos; |
kenjiArai | 13:1041596c416c | 312 | return dt; |
kenjiArai | 13:1041596c416c | 313 | } |
kenjiArai | 13:1041596c416c | 314 | |
kenjiArai | 13:1041596c416c | 315 | //****************************************************************************** |
kenjiArai | 13:1041596c416c | 316 | static void dsp_freq(dispDef *dt) |
kenjiArai | 13:1041596c416c | 317 | { |
kenjiArai | 13:1041596c416c | 318 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 319 | if (prescaler_on == 0){ |
kenjiArai | 13:1041596c416c | 320 | lcd.printf("Freq = %8.0f Hz", dt->m_frq); |
kenjiArai | 13:1041596c416c | 321 | } else if (prescaler_div20){ |
kenjiArai | 13:1041596c416c | 322 | lcd.printf("Freq = %7.4fMHz", dt->m_frq * 20.0f); // 1/20 |
kenjiArai | 13:1041596c416c | 323 | } else { |
kenjiArai | 13:1041596c416c | 324 | lcd.printf("Freq = %8.5fMHz", dt->m_frq * 10.0f); // 1/10 |
kenjiArai | 13:1041596c416c | 325 | } |
kenjiArai | 13:1041596c416c | 326 | lcd.locate(0, 1); |
kenjiArai | 13:1041596c416c | 327 | if (dt->m_frq_10 == 0.0f){ |
kenjiArai | 13:1041596c416c | 328 | lcd.printf("10s = not yet"); |
kenjiArai | 13:1041596c416c | 329 | } else { |
kenjiArai | 13:1041596c416c | 330 | if (prescaler_on == 0){ |
kenjiArai | 13:1041596c416c | 331 | lcd.printf("10s = %9.1f", dt->m_frq_10); |
kenjiArai | 13:1041596c416c | 332 | } else if (prescaler_div20){ |
kenjiArai | 13:1041596c416c | 333 | lcd.printf("10s = %8.5f", dt->m_frq_10 * 20.0f); // 1/20 |
kenjiArai | 13:1041596c416c | 334 | } else { |
kenjiArai | 13:1041596c416c | 335 | lcd.printf("10s = %9.6f", dt->m_frq_10 * 10.0f); // 1/10 |
kenjiArai | 13:1041596c416c | 336 | } |
kenjiArai | 13:1041596c416c | 337 | } |
kenjiArai | 13:1041596c416c | 338 | lcd.locate(0, 2); |
kenjiArai | 13:1041596c416c | 339 | if (dt->m_frq_100 == 0.0f){ |
kenjiArai | 13:1041596c416c | 340 | lcd.printf("100s = not yet"); |
kenjiArai | 13:1041596c416c | 341 | } else { |
kenjiArai | 13:1041596c416c | 342 | if (prescaler_on == 0){ |
kenjiArai | 13:1041596c416c | 343 | lcd.printf("100s = %10.2f", dt->m_frq_100); |
kenjiArai | 13:1041596c416c | 344 | } else if (prescaler_div20){ |
kenjiArai | 13:1041596c416c | 345 | lcd.printf("100s = %9.6f", dt->m_frq_100 * 20.0f); // 1/20 |
kenjiArai | 13:1041596c416c | 346 | } else { |
kenjiArai | 13:1041596c416c | 347 | lcd.printf("100s = %10.7f", dt->m_frq_100 * 10.0f); // 1/10 |
kenjiArai | 13:1041596c416c | 348 | } |
kenjiArai | 13:1041596c416c | 349 | } |
kenjiArai | 13:1041596c416c | 350 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 351 | if (dt->m_frq_1000 == 0.0f){ |
kenjiArai | 13:1041596c416c | 352 | strftime(buf,40, "%I:%M:%S%p (%m/%d)", localtime(&seconds_jst)); |
kenjiArai | 13:1041596c416c | 353 | lcd.printf("%s %d", buf, function_num); |
kenjiArai | 13:1041596c416c | 354 | } else { |
kenjiArai | 13:1041596c416c | 355 | if (prescaler_on == 0){ |
kenjiArai | 13:1041596c416c | 356 | lcd.printf("1000s= %11.3f", dt->m_frq_1000); |
kenjiArai | 13:1041596c416c | 357 | } else if (prescaler_div20){ |
kenjiArai | 13:1041596c416c | 358 | lcd.printf("1000s= %10.7f", dt->m_frq_1000 * 20.0f); // 1/20 |
kenjiArai | 13:1041596c416c | 359 | } else { |
kenjiArai | 13:1041596c416c | 360 | lcd.printf("1000s= %11.8f", dt->m_frq_1000 * 10.0f); // 1/10 |
kenjiArai | 13:1041596c416c | 361 | } |
kenjiArai | 13:1041596c416c | 362 | } |
kenjiArai | 13:1041596c416c | 363 | } |
kenjiArai | 13:1041596c416c | 364 | |
kenjiArai | 13:1041596c416c | 365 | static void dsp_1pps(dispDef *dt) |
kenjiArai | 13:1041596c416c | 366 | { |
kenjiArai | 13:1041596c416c | 367 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 368 | if (dt->m_frq_10 == 0.0f){ |
kenjiArai | 13:1041596c416c | 369 | lcd.printf("10s = not yet"); |
kenjiArai | 13:1041596c416c | 370 | } else { |
kenjiArai | 13:1041596c416c | 371 | if (prescaler_on == 0){ |
kenjiArai | 13:1041596c416c | 372 | lcd.printf("10s = %9.1f", dt->m_frq_10); |
kenjiArai | 13:1041596c416c | 373 | } else if (prescaler_div20){ |
kenjiArai | 13:1041596c416c | 374 | lcd.printf("10s = %8.5f", dt->m_frq_10 * 20.0f); // 1/20 |
kenjiArai | 13:1041596c416c | 375 | } else { |
kenjiArai | 13:1041596c416c | 376 | lcd.printf("10s = %9.6f", dt->m_frq_10 * 10.0f); // 1/10 |
kenjiArai | 13:1041596c416c | 377 | } |
kenjiArai | 13:1041596c416c | 378 | } |
kenjiArai | 13:1041596c416c | 379 | lcd.locate(0, 1); |
kenjiArai | 13:1041596c416c | 380 | lcd.printf("1PPS = %8d Hz", dt->b_1pps_new); |
kenjiArai | 13:1041596c416c | 381 | lcd.locate(0, 2); |
kenjiArai | 13:1041596c416c | 382 | lcd.printf("Oven Temp= %+5.2f%cC", dt->box_tmp, 0xdf); |
kenjiArai | 13:1041596c416c | 383 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 384 | strftime(buf,40, "%I:%M:%S%p (%m/%d)", localtime(&seconds_jst)); |
kenjiArai | 13:1041596c416c | 385 | lcd.printf("%s %d", buf, function_num); |
kenjiArai | 13:1041596c416c | 386 | } |
kenjiArai | 13:1041596c416c | 387 | |
kenjiArai | 13:1041596c416c | 388 | static void dsp_detail(dispDef *dt) |
kenjiArai | 13:1041596c416c | 389 | { |
kenjiArai | 13:1041596c416c | 390 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 391 | if (dt->m_frq_100 == 0.0f){ |
kenjiArai | 13:1041596c416c | 392 | lcd.printf("100s = not yet"); |
kenjiArai | 13:1041596c416c | 393 | } else { |
kenjiArai | 13:1041596c416c | 394 | if (prescaler_on == 0){ |
kenjiArai | 13:1041596c416c | 395 | lcd.printf("100s = %11.2f", dt->m_frq_100); |
kenjiArai | 13:1041596c416c | 396 | } else if (prescaler_div20){ |
kenjiArai | 13:1041596c416c | 397 | lcd.printf("100s = %9.6f", dt->m_frq_100 * 20.0f); // 1/20 |
kenjiArai | 13:1041596c416c | 398 | } else { |
kenjiArai | 13:1041596c416c | 399 | lcd.printf("100s = %10.7f", dt->m_frq_100 * 10.0f); // 1/10 |
kenjiArai | 13:1041596c416c | 400 | } |
kenjiArai | 13:1041596c416c | 401 | } |
kenjiArai | 13:1041596c416c | 402 | lcd.locate(0, 1); |
kenjiArai | 13:1041596c416c | 403 | if (dt->gps_1pps_ave == 1000){ |
kenjiArai | 13:1041596c416c | 404 | lcd.printf("1PPS = %12.3f ", dt->b_1pps_lng); |
kenjiArai | 13:1041596c416c | 405 | } else if (dt->gps_1pps_ave == 100){ |
kenjiArai | 13:1041596c416c | 406 | lcd.printf("1PPS = %11.2f ", dt->b_1pps_lng); |
kenjiArai | 13:1041596c416c | 407 | } else if (dt->gps_1pps_ave == 10){ |
kenjiArai | 13:1041596c416c | 408 | lcd.printf("1PPS = %10.1f ", dt->b_1pps_lng); |
kenjiArai | 13:1041596c416c | 409 | } else { |
kenjiArai | 13:1041596c416c | 410 | lcd.printf("1PPS = %9.0f " , dt->b_1pps_lng); |
kenjiArai | 13:1041596c416c | 411 | } |
kenjiArai | 13:1041596c416c | 412 | lcd.locate(0, 2); |
kenjiArai | 13:1041596c416c | 413 | lcd.printf("Oven Temp= %+6.3f%cC", dt->box_tmp, 0xdf); |
kenjiArai | 13:1041596c416c | 414 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 415 | strftime(buf,40, "%I:%M:%S%p (%m/%d)", localtime(&seconds_jst)); |
kenjiArai | 13:1041596c416c | 416 | lcd.printf("%s %d", buf, function_num); |
kenjiArai | 13:1041596c416c | 417 | } |
kenjiArai | 13:1041596c416c | 418 | |
kenjiArai | 13:1041596c416c | 419 | static void dsp_simple(dispDef *dt) |
kenjiArai | 13:1041596c416c | 420 | { |
kenjiArai | 13:1041596c416c | 421 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 422 | if (prescaler_on == 0){ |
kenjiArai | 13:1041596c416c | 423 | lcd.printf("Freq = %8.0f Hz", dt->m_frq); |
kenjiArai | 13:1041596c416c | 424 | } else if (prescaler_div20){ |
kenjiArai | 13:1041596c416c | 425 | lcd.printf("Freq = %7.4fMHz", dt->m_frq * 20.0f); // 1/20 |
kenjiArai | 13:1041596c416c | 426 | } else { |
kenjiArai | 13:1041596c416c | 427 | lcd.printf("Freq = %8.5fMHz", dt->m_frq * 10.0f); // 1/10 |
kenjiArai | 13:1041596c416c | 428 | } |
kenjiArai | 13:1041596c416c | 429 | lcd.locate(0, 1); |
kenjiArai | 13:1041596c416c | 430 | lcd.printf("1PPS = %8d Hz", dt->b_1pps_new); |
kenjiArai | 13:1041596c416c | 431 | lcd.locate(0, 2); |
kenjiArai | 13:1041596c416c | 432 | lcd.printf("Oven Temp= %+3.0f%cC", dt->box_tmp, 0xdf); |
kenjiArai | 13:1041596c416c | 433 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 434 | strftime(buf,40, "%I:%M:%S%p (%m/%d)", localtime(&seconds_jst)); |
kenjiArai | 13:1041596c416c | 435 | lcd.printf("%s %d", buf, function_num); |
kenjiArai | 13:1041596c416c | 436 | } |
kenjiArai | 13:1041596c416c | 437 | |
kenjiArai | 13:1041596c416c | 438 | static void dsp_recipro(dispDef *dt) |
kenjiArai | 13:1041596c416c | 439 | { |
kenjiArai | 13:1041596c416c | 440 | if ((prescaler_on != 0) || (dt->recipro_of == 1)){ |
kenjiArai | 13:1041596c416c | 441 | display_clear_all(); |
kenjiArai | 13:1041596c416c | 442 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 443 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 444 | lcd.printf(" Reciprocal data is"); |
kenjiArai | 13:1041596c416c | 445 | lcd.locate(0, 1); |
kenjiArai | 13:1041596c416c | 446 | lcd.printf(" Not avairable "); |
kenjiArai | 13:1041596c416c | 447 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 448 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 449 | lcd.printf(" %d", function_num); |
kenjiArai | 13:1041596c416c | 450 | } else { |
kenjiArai | 13:1041596c416c | 451 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 452 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 453 | lcd.printf("Reciprocal [Hz] "); |
kenjiArai | 13:1041596c416c | 454 | lcd.locate(0, 1); |
kenjiArai | 13:1041596c416c | 455 | if (dt->recipro_of){ |
kenjiArai | 13:1041596c416c | 456 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 457 | lcd.printf(" 5KHz over "); |
kenjiArai | 13:1041596c416c | 458 | } else { |
kenjiArai | 13:1041596c416c | 459 | lcd.printf(" %11.6f,", dt->m_frq_recipro); |
kenjiArai | 13:1041596c416c | 460 | } |
kenjiArai | 13:1041596c416c | 461 | lcd.locate(0, 2); |
kenjiArai | 13:1041596c416c | 462 | lcd.printf("Oven Temp= %+6.3f%cC", dt->box_tmp, 0xdf); |
kenjiArai | 13:1041596c416c | 463 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 464 | strftime(buf,40, "%I:%M:%S%p (%m/%d)", localtime(&seconds_jst)); |
kenjiArai | 13:1041596c416c | 465 | lcd.printf("%s %d", buf, function_num); |
kenjiArai | 13:1041596c416c | 466 | } |
kenjiArai | 13:1041596c416c | 467 | } |
kenjiArai | 13:1041596c416c | 468 | |
kenjiArai | 13:1041596c416c | 469 | static void dsp_current_setting(dispDef *dt) |
kenjiArai | 13:1041596c416c | 470 | { |
kenjiArai | 13:1041596c416c | 471 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 472 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 473 | lcd.printf("Current setting "); |
kenjiArai | 13:1041596c416c | 474 | lcd.locate(0, 1); |
kenjiArai | 13:1041596c416c | 475 | if (prescaler_on == 1){ |
kenjiArai | 13:1041596c416c | 476 | if (prescaler_div20 == 1){ |
kenjiArai | 13:1041596c416c | 477 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 478 | lcd.printf(" Prescaler =ON 1/20"); |
kenjiArai | 13:1041596c416c | 479 | } else { |
kenjiArai | 13:1041596c416c | 480 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 481 | lcd.printf(" Prescaler =ON 1/10"); |
kenjiArai | 13:1041596c416c | 482 | } |
kenjiArai | 13:1041596c416c | 483 | } else { |
kenjiArai | 13:1041596c416c | 484 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 485 | lcd.printf(" None-Prescaler(BNC)"); |
kenjiArai | 13:1041596c416c | 486 | } |
kenjiArai | 13:1041596c416c | 487 | lcd.locate(0, 2); |
kenjiArai | 13:1041596c416c | 488 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 489 | lcd.printf("Change parameter "); |
kenjiArai | 13:1041596c416c | 490 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 491 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 492 | lcd.printf(" -> Push Switch %d", function_num); |
kenjiArai | 13:1041596c416c | 493 | } |
kenjiArai | 13:1041596c416c | 494 | |
kenjiArai | 13:1041596c416c | 495 | static void dsp_gps_status(dispDef *dt) |
kenjiArai | 13:1041596c416c | 496 | { |
kenjiArai | 13:1041596c416c | 497 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 498 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 499 | lcd.printf("GPS status "); |
kenjiArai | 13:1041596c416c | 500 | lcd.locate(0, 1); |
kenjiArai | 13:1041596c416c | 501 | // 12345678901234567890 |
kenjiArai | 13:1041596c416c | 502 | lcd.printf(" 3D or not --> %u ", dt->ready_1pps); |
kenjiArai | 13:1041596c416c | 503 | lcd.locate(0, 2); |
kenjiArai | 13:1041596c416c | 504 | lcd.printf("Oven Temp= %+6.3f%cC", dt->box_tmp, 0xdf); |
kenjiArai | 13:1041596c416c | 505 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 506 | strftime(buf,40, "%I:%M:%S%p (%m/%d)", localtime(&seconds_jst)); |
kenjiArai | 13:1041596c416c | 507 | lcd.printf("%s %d", buf, function_num); |
kenjiArai | 13:1041596c416c | 508 | } |
kenjiArai | 13:1041596c416c | 509 | |
kenjiArai | 13:1041596c416c | 510 | // Clear LCD screen |
kenjiArai | 13:1041596c416c | 511 | void display_clear_all(void) |
kenjiArai | 13:1041596c416c | 512 | { |
kenjiArai | 13:1041596c416c | 513 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 514 | lcd.printf(msg_clear); |
kenjiArai | 13:1041596c416c | 515 | lcd.printf(msg_clear); |
kenjiArai | 13:1041596c416c | 516 | lcd.printf(msg_clear); |
kenjiArai | 13:1041596c416c | 517 | lcd.printf(msg_clear); |
kenjiArai | 13:1041596c416c | 518 | } |
kenjiArai | 13:1041596c416c | 519 | |
kenjiArai | 13:1041596c416c | 520 | // Openning message on LCD & message via VCOM |
kenjiArai | 13:1041596c416c | 521 | void disp_first_msg(void) |
kenjiArai | 13:1041596c416c | 522 | { |
kenjiArai | 13:1041596c416c | 523 | // lcd.setCursor(LCDCursol 0); // Cursol off |
kenjiArai | 13:1041596c416c | 524 | // LCD Initial screen |
kenjiArai | 13:1041596c416c | 525 | lcd.locate(0, 0); |
kenjiArai | 13:1041596c416c | 526 | lcd.printf(msg_msg0); |
kenjiArai | 13:1041596c416c | 527 | lcd.printf(msg_msg1); |
kenjiArai | 13:1041596c416c | 528 | lcd.printf(msg_msg2); |
kenjiArai | 13:1041596c416c | 529 | lcd.printf(msg_msg3); |
kenjiArai | 13:1041596c416c | 530 | // Clear all LED |
kenjiArai | 13:1041596c416c | 531 | led_R_gps1pps = 0; |
kenjiArai | 13:1041596c416c | 532 | led_W_prescaler = 0; |
kenjiArai | 13:1041596c416c | 533 | led_R_rotary = 0; |
kenjiArai | 13:1041596c416c | 534 | led_G_rotary = 0; |
kenjiArai | 13:1041596c416c | 535 | led_B_rotary = 0; |
kenjiArai | 13:1041596c416c | 536 | // VCOM message |
kenjiArai | 13:1041596c416c | 537 | BAUD(9600); |
kenjiArai | 14:ba6ea409ab05 | 538 | //PRINTF("\r\nFrequency Counter by JH1PJL created on \r\n"); |
kenjiArai | 14:ba6ea409ab05 | 539 | PRINTF("\r\nFrequency Counter by JH1PJL created on " __DATE__"\r\n"); |
kenjiArai | 13:1041596c416c | 540 | PRINTF("\r\nStarted!\r\n"); |
kenjiArai | 13:1041596c416c | 541 | PRINTF("SystemCoreClock = %d Hz\r\n", SystemCoreClock); |
kenjiArai | 13:1041596c416c | 542 | // Rotary switch control |
kenjiArai | 13:1041596c416c | 543 | enter_irq.attach_us(&enter_action, 5000); // every 5mS |
kenjiArai | 13:1041596c416c | 544 | } |
kenjiArai | 13:1041596c416c | 545 | |
kenjiArai | 13:1041596c416c | 546 | // GPS waiting message |
kenjiArai | 13:1041596c416c | 547 | void disp_wait_gps(void) |
kenjiArai | 13:1041596c416c | 548 | { |
kenjiArai | 13:1041596c416c | 549 | lcd.locate(0, 3); |
kenjiArai | 13:1041596c416c | 550 | lcd.printf(msg_msg4); |
kenjiArai | 13:1041596c416c | 551 | } |