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