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/
main.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 / Frequency Counter with GPS 1PPS Compensation |
kenjiArai | 14:ba6ea409ab05 | 3 | * Only for ST Nucleo-F746ZG on mbed-OS5 |
kenjiArai | 13:1041596c416c | 4 | * |
kenjiArai | 14:ba6ea409ab05 | 5 | * Copyright (c) 2014,'15,'16,'19 Kenji Arai / JH1PJL |
kenjiArai | 13:1041596c416c | 6 | * http://www.page.sannet.ne.jp/kenjia/index.html |
kenjiArai | 13:1041596c416c | 7 | * http://mbed.org/users/kenjiArai/ |
kenjiArai | 13:1041596c416c | 8 | * Created: October 18th, 2014 |
kenjiArai | 13:1041596c416c | 9 | * Revised: January 2nd, 2015 |
kenjiArai | 13:1041596c416c | 10 | * Re-started: June 25th, 2016 ported from F411 to F746 |
kenjiArai | 14:ba6ea409ab05 | 11 | * Revised: December 12th, 2019 |
kenjiArai | 13:1041596c416c | 12 | * |
kenjiArai | 13:1041596c416c | 13 | * Base program: Frequency_counter_w_GPS_1PPS (only for Nucleo-F411RE board) |
kenjiArai | 13:1041596c416c | 14 | * https://developer.mbed.org/users/kenjiArai/code/Frequency_Counter_w_GPS_1PPS/ |
kenjiArai | 13:1041596c416c | 15 | */ |
kenjiArai | 13:1041596c416c | 16 | |
kenjiArai | 13:1041596c416c | 17 | /* |
kenjiArai | 13:1041596c416c | 18 | -------------------------------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 19 | Frequency Counter Functions |
kenjiArai | 13:1041596c416c | 20 | Mesurement frequency range: |
kenjiArai | 13:1041596c416c | 21 | 10Hz to 100MHz (BNC Connector) |
kenjiArai | 13:1041596c416c | 22 | Extended range: |
kenjiArai | 13:1041596c416c | 23 | Up to 1GHz (1/10 prescaler) or more over (1/20) (SMA) |
kenjiArai | 13:1041596c416c | 24 | Gate time: |
kenjiArai | 13:1041596c416c | 25 | 1 sec to 4095sec (extend to more if RAM is avairable) |
kenjiArai | 13:1041596c416c | 26 | Reciprocal measurement: |
kenjiArai | 13:1041596c416c | 27 | 0.01Hz to 5KHz (extend more lower frequency change input I/F) |
kenjiArai | 13:1041596c416c | 28 | Base Internal Clock: |
kenjiArai | 13:1041596c416c | 29 | 50MHz VCTCXO (Connor-Winfield TB514-050.0M) |
kenjiArai | 13:1041596c416c | 30 | 1 PPS: |
kenjiArai | 13:1041596c416c | 31 | GPS receiver(u-blux7/NEO-7) with an external antenna (SMA) |
kenjiArai | 13:1041596c416c | 32 | Temperature controlled Oven: |
kenjiArai | 13:1041596c416c | 33 | 32 degree Celsius +/-0.2 for 50MHz VCTCXO & 3.3V regulater |
kenjiArai | 13:1041596c416c | 34 | Hardware Configration |
kenjiArai | 13:1041596c416c | 35 | frequency input: PC_6 & PA_3 |
kenjiArai | 13:1041596c416c | 36 | 50MHz base clock input: PA_5 |
kenjiArai | 13:1041596c416c | 37 | GPS 1PPS input: PA_1 |
kenjiArai | 13:1041596c416c | 38 | Connect (for 1sec gate): PA_7, PB_10 and PC_7 connected together |
kenjiArai | 13:1041596c416c | 39 | IMPORTANT!!!! |
kenjiArai | 13:1041596c416c | 40 | SB13 & SB181 must REMOVE from Nucleo-F746ZG board |
kenjiArai | 13:1041596c416c | 41 | -------------------------------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 42 | */ |
kenjiArai | 13:1041596c416c | 43 | |
kenjiArai | 13:1041596c416c | 44 | #define USE_COM // use Communication with PC(UART) |
kenjiArai | 13:1041596c416c | 45 | #define USE_DEBUG |
kenjiArai | 13:1041596c416c | 46 | //#define HW_TEST_GO // activate Hardware test mode |
kenjiArai | 13:1041596c416c | 47 | |
kenjiArai | 13:1041596c416c | 48 | // Include -------------------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 49 | #include "mbed.h" |
kenjiArai | 14:ba6ea409ab05 | 50 | //#include "rtos.h" |
kenjiArai | 13:1041596c416c | 51 | #include "GPSrcvr.h" |
kenjiArai | 13:1041596c416c | 52 | #include "DRV8830.h" |
kenjiArai | 13:1041596c416c | 53 | #include "ADT7410.h" |
kenjiArai | 13:1041596c416c | 54 | #include "PID.h" |
kenjiArai | 13:1041596c416c | 55 | #include "frq_cuntr_f746.h" |
kenjiArai | 13:1041596c416c | 56 | #include "TextLCD.h" |
kenjiArai | 13:1041596c416c | 57 | #include "QEI.h" |
kenjiArai | 13:1041596c416c | 58 | #include "uif.h" |
kenjiArai | 13:1041596c416c | 59 | |
kenjiArai | 13:1041596c416c | 60 | // Definition ----------------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 61 | #ifdef USE_COM |
kenjiArai | 13:1041596c416c | 62 | #define BAUD(x) pc.baud(x) |
kenjiArai | 13:1041596c416c | 63 | #define GETC(x) pc.getc(x) |
kenjiArai | 13:1041596c416c | 64 | #define PUTC(x) pc.putc(x) |
kenjiArai | 13:1041596c416c | 65 | #define PRINTF(...) pc.printf(__VA_ARGS__) |
kenjiArai | 13:1041596c416c | 66 | #define READABLE(x) pc.readable(x) |
kenjiArai | 13:1041596c416c | 67 | #else |
kenjiArai | 13:1041596c416c | 68 | #define BAUD(x) {;} |
kenjiArai | 13:1041596c416c | 69 | #define GETC(x) {;} |
kenjiArai | 13:1041596c416c | 70 | #define PUTC(x) {;} |
kenjiArai | 13:1041596c416c | 71 | #define PRINTF(...) {;} |
kenjiArai | 13:1041596c416c | 72 | #define READABLE(x) {;} |
kenjiArai | 13:1041596c416c | 73 | #endif |
kenjiArai | 13:1041596c416c | 74 | |
kenjiArai | 13:1041596c416c | 75 | #ifdef USE_DEBUG |
kenjiArai | 13:1041596c416c | 76 | #define U_DEBUGBAUD(x) pc.baud(x) |
kenjiArai | 13:1041596c416c | 77 | #define U_DEBUG(...) pc.printf(__VA_ARGS__) |
kenjiArai | 13:1041596c416c | 78 | #define DBG(c) pc.putc(c) |
kenjiArai | 13:1041596c416c | 79 | #else |
kenjiArai | 13:1041596c416c | 80 | #define U_DEBUGBAUD(x) {;} |
kenjiArai | 13:1041596c416c | 81 | #define U_DEBUG(...) {;} |
kenjiArai | 13:1041596c416c | 82 | #define DBG(c) {;} |
kenjiArai | 13:1041596c416c | 83 | #endif |
kenjiArai | 13:1041596c416c | 84 | |
kenjiArai | 13:1041596c416c | 85 | #define CLEAR_PD_2_RX_LINE() {UART5->ICR = 0; UART5->CR1 = 0; UART5->CR1 = 5;} |
kenjiArai | 13:1041596c416c | 86 | |
kenjiArai | 13:1041596c416c | 87 | #define CLOCK_BASE (50.000000f) // MHz |
kenjiArai | 13:1041596c416c | 88 | #define TRGT_TEMP (32.0f) // degC |
kenjiArai | 13:1041596c416c | 89 | |
kenjiArai | 13:1041596c416c | 90 | #define RECIPRO_OVRFLW 10000 // = 5KHz |
kenjiArai | 13:1041596c416c | 91 | #define RECIPRO_TIMEOUT 1000000 // = 0.001Hz |
kenjiArai | 13:1041596c416c | 92 | |
kenjiArai | 13:1041596c416c | 93 | #define GSP_BUF_B (128 * 3) |
kenjiArai | 13:1041596c416c | 94 | #define GPS_BUF_S (128 * 2) |
kenjiArai | 13:1041596c416c | 95 | |
kenjiArai | 13:1041596c416c | 96 | using namespace Frequency_counter; |
kenjiArai | 13:1041596c416c | 97 | |
kenjiArai | 13:1041596c416c | 98 | // Object --------------------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 99 | DigitalOut led_gate(LED1); |
kenjiArai | 13:1041596c416c | 100 | DigitalOut in_frq_slct(PC_9); |
kenjiArai | 13:1041596c416c | 101 | DigitalInOut prescaler10or20(PC_5); |
kenjiArai | 13:1041596c416c | 102 | DigitalIn pa1(PA_1); |
kenjiArai | 13:1041596c416c | 103 | Timer tmr0; |
kenjiArai | 13:1041596c416c | 104 | Timer tmr1; |
kenjiArai | 13:1041596c416c | 105 | Timer tmr2; |
kenjiArai | 13:1041596c416c | 106 | Ticker enter_irq; |
kenjiArai | 13:1041596c416c | 107 | |
kenjiArai | 13:1041596c416c | 108 | //**** UART |
kenjiArai | 13:1041596c416c | 109 | Serial pc(USBTX, USBRX); |
kenjiArai | 13:1041596c416c | 110 | |
kenjiArai | 13:1041596c416c | 111 | //**** Req. Counter |
kenjiArai | 13:1041596c416c | 112 | FRQ_CUNTR fc(CLOCK_BASE); // External clock freq. |
kenjiArai | 13:1041596c416c | 113 | |
kenjiArai | 13:1041596c416c | 114 | //**** Peltier temperature control |
kenjiArai | 13:1041596c416c | 115 | I2C i2cBus(PB_9,PB_8); // SDA, SCL |
kenjiArai | 13:1041596c416c | 116 | DRV8830 heater(i2cBus, (uint8_t)DRV8830ADDR_00); // H brige |
kenjiArai | 13:1041596c416c | 117 | PID pid(8.0f, 85.0f, 4.0f, 0.7f); // PID for oven |
kenjiArai | 13:1041596c416c | 118 | ADT7410 t(i2cBus, ADT7410ADDR_NN); // inside oven temp. |
kenjiArai | 13:1041596c416c | 119 | |
kenjiArai | 13:1041596c416c | 120 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 13:1041596c416c | 121 | // all display data |
kenjiArai | 13:1041596c416c | 122 | dispDef disp_data; |
kenjiArai | 13:1041596c416c | 123 | // Freq. |
kenjiArai | 13:1041596c416c | 124 | double new_frequency; |
kenjiArai | 13:1041596c416c | 125 | double freq_recipro; |
kenjiArai | 13:1041596c416c | 126 | uint32_t interval_recipro; |
kenjiArai | 13:1041596c416c | 127 | uint8_t recipro_new_data_ready; |
kenjiArai | 13:1041596c416c | 128 | uint8_t recipro_overflow; |
kenjiArai | 13:1041596c416c | 129 | |
kenjiArai | 13:1041596c416c | 130 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 131 | |
kenjiArai | 13:1041596c416c | 132 | |
kenjiArai | 13:1041596c416c | 133 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 13:1041596c416c | 134 | extern void dispay_LCD_and_UART(dispDef *dt); |
kenjiArai | 13:1041596c416c | 135 | extern void select_input_div_1or10or20(uint8_t mode); |
kenjiArai | 13:1041596c416c | 136 | |
kenjiArai | 13:1041596c416c | 137 | //------------------------------------------------------------------------------ |
kenjiArai | 13:1041596c416c | 138 | // Control Program |
kenjiArai | 13:1041596c416c | 139 | //------------------------------------------------------------------------------ |
kenjiArai | 13:1041596c416c | 140 | // Frequency measurement |
kenjiArai | 13:1041596c416c | 141 | void measure_freq(void const *args) |
kenjiArai | 13:1041596c416c | 142 | { |
kenjiArai | 13:1041596c416c | 143 | while(true) { |
kenjiArai | 13:1041596c416c | 144 | if (fc.status_freq_update() != 0) { |
kenjiArai | 13:1041596c416c | 145 | new_frequency = fc.read_freq_data(); |
kenjiArai | 13:1041596c416c | 146 | disp_data.m_frq = new_frequency; |
kenjiArai | 13:1041596c416c | 147 | disp_data.m_frq_comp = fc.read_compensated_freq_data_w_gt(1); |
kenjiArai | 13:1041596c416c | 148 | disp_data.m_frq_10 = fc.read_compensated_freq_data_w_gt(10); |
kenjiArai | 13:1041596c416c | 149 | disp_data.m_frq_100 = fc.read_compensated_freq_data_w_gt(100); |
kenjiArai | 13:1041596c416c | 150 | disp_data.m_frq_1000 = fc.read_compensated_freq_data_w_gt(1000); |
kenjiArai | 13:1041596c416c | 151 | } |
kenjiArai | 13:1041596c416c | 152 | if (fc.status_1pps() != 0) { |
kenjiArai | 13:1041596c416c | 153 | disp_data.b_1pps_new = fc.read_newest_1pps(); |
kenjiArai | 13:1041596c416c | 154 | disp_data.b_1pps_lng = fc.read_avarage_1pps(); |
kenjiArai | 13:1041596c416c | 155 | } |
kenjiArai | 14:ba6ea409ab05 | 156 | ThisThread::sleep_for(100); // 0.1sec |
kenjiArai | 13:1041596c416c | 157 | } |
kenjiArai | 13:1041596c416c | 158 | } |
kenjiArai | 13:1041596c416c | 159 | |
kenjiArai | 13:1041596c416c | 160 | // Frequency measurement / Reciprocal measurement |
kenjiArai | 13:1041596c416c | 161 | void measure_freq_recipro(void const *args) |
kenjiArai | 13:1041596c416c | 162 | { |
kenjiArai | 13:1041596c416c | 163 | int32_t run2stop; |
kenjiArai | 13:1041596c416c | 164 | |
kenjiArai | 13:1041596c416c | 165 | while(true) { |
kenjiArai | 13:1041596c416c | 166 | tmr0.reset(); |
kenjiArai | 13:1041596c416c | 167 | tmr0.start(); |
kenjiArai | 13:1041596c416c | 168 | fc.recipro_start_measure(); |
kenjiArai | 13:1041596c416c | 169 | while (fc.recipro_check_trigger() == 0){ |
kenjiArai | 14:ba6ea409ab05 | 170 | ThisThread::sleep_for(1); // 1mS |
kenjiArai | 13:1041596c416c | 171 | run2stop = tmr0.read_ms(); |
kenjiArai | 13:1041596c416c | 172 | if (run2stop >= RECIPRO_TIMEOUT){ |
kenjiArai | 13:1041596c416c | 173 | break; |
kenjiArai | 13:1041596c416c | 174 | } |
kenjiArai | 13:1041596c416c | 175 | } |
kenjiArai | 13:1041596c416c | 176 | if (run2stop >= RECIPRO_TIMEOUT){ |
kenjiArai | 13:1041596c416c | 177 | freq_recipro = 0; |
kenjiArai | 13:1041596c416c | 178 | } else { |
kenjiArai | 13:1041596c416c | 179 | interval_recipro = fc.recipro_read_data(); |
kenjiArai | 13:1041596c416c | 180 | if (interval_recipro >= RECIPRO_OVRFLW){ |
kenjiArai | 13:1041596c416c | 181 | // Measure less than 5KHz frequency |
kenjiArai | 13:1041596c416c | 182 | freq_recipro = CLOCK_BASE/(double)interval_recipro * 1000000; |
kenjiArai | 13:1041596c416c | 183 | recipro_overflow = 0; |
kenjiArai | 13:1041596c416c | 184 | } else { |
kenjiArai | 13:1041596c416c | 185 | freq_recipro = 0; |
kenjiArai | 13:1041596c416c | 186 | recipro_overflow = 1; |
kenjiArai | 13:1041596c416c | 187 | } |
kenjiArai | 13:1041596c416c | 188 | } |
kenjiArai | 13:1041596c416c | 189 | recipro_new_data_ready = 1; |
kenjiArai | 13:1041596c416c | 190 | disp_data.m_frq_recipro = freq_recipro; |
kenjiArai | 13:1041596c416c | 191 | disp_data.recipro_of = recipro_overflow; |
kenjiArai | 13:1041596c416c | 192 | run2stop = tmr0.read_ms(); |
kenjiArai | 13:1041596c416c | 193 | if (run2stop > 1000){ |
kenjiArai | 14:ba6ea409ab05 | 194 | ThisThread::sleep_for(run2stop % 1000); // next interval |
kenjiArai | 13:1041596c416c | 195 | } else { |
kenjiArai | 13:1041596c416c | 196 | run2stop = 1000 - run2stop; |
kenjiArai | 13:1041596c416c | 197 | /* Wait until it is time to check again. */ |
kenjiArai | 14:ba6ea409ab05 | 198 | ThisThread::sleep_for(run2stop); // 1sec interval |
kenjiArai | 13:1041596c416c | 199 | } |
kenjiArai | 13:1041596c416c | 200 | } |
kenjiArai | 13:1041596c416c | 201 | } |
kenjiArai | 13:1041596c416c | 202 | |
kenjiArai | 13:1041596c416c | 203 | // Constant temperature oven control |
kenjiArai | 13:1041596c416c | 204 | void temp_control(void const *args) |
kenjiArai | 13:1041596c416c | 205 | { |
kenjiArai | 13:1041596c416c | 206 | static double volt = 0.0; |
kenjiArai | 13:1041596c416c | 207 | static double tmp = 0; |
kenjiArai | 13:1041596c416c | 208 | static double pid_val = 0; |
kenjiArai | 13:1041596c416c | 209 | static uint32_t error_count = 3600; |
kenjiArai | 13:1041596c416c | 210 | static int32_t keep_1sec; |
kenjiArai | 13:1041596c416c | 211 | |
kenjiArai | 13:1041596c416c | 212 | t.set_config(OPERATION_MODE_CONT + RESOLUTION_16BIT); |
kenjiArai | 13:1041596c416c | 213 | pid.setInputLimits(0.0f, 5.0f); |
kenjiArai | 13:1041596c416c | 214 | pid.setOutputLimits(0.0f, 5.0f); |
kenjiArai | 13:1041596c416c | 215 | pid.setSetPoint(TRGT_TEMP/10.0f); |
kenjiArai | 13:1041596c416c | 216 | while(true) { |
kenjiArai | 13:1041596c416c | 217 | tmr2.reset(); |
kenjiArai | 13:1041596c416c | 218 | tmr2.start(); |
kenjiArai | 13:1041596c416c | 219 | tmp = t.read_temp(); |
kenjiArai | 13:1041596c416c | 220 | disp_data.box_tmp = tmp; |
kenjiArai | 13:1041596c416c | 221 | //PRINTF("Temp=%f degC\r\n", tmp); |
kenjiArai | 13:1041596c416c | 222 | pid.setProcessValue(tmp / 10.0f); |
kenjiArai | 13:1041596c416c | 223 | pid_val = pid.compute(); |
kenjiArai | 13:1041596c416c | 224 | volt = pid_val - (TRGT_TEMP/10.0f); |
kenjiArai | 13:1041596c416c | 225 | if (volt < -5.0f) { |
kenjiArai | 13:1041596c416c | 226 | volt = -5.0f; |
kenjiArai | 13:1041596c416c | 227 | } else if (volt > 5.0f) { |
kenjiArai | 13:1041596c416c | 228 | volt = 5.0f; |
kenjiArai | 13:1041596c416c | 229 | } |
kenjiArai | 13:1041596c416c | 230 | if ((volt == -5.0f) || (volt == 5.0f)){ |
kenjiArai | 13:1041596c416c | 231 | if (--error_count == 0){ |
kenjiArai | 13:1041596c416c | 232 | pid.reset(); |
kenjiArai | 13:1041596c416c | 233 | error_count = 3600; |
kenjiArai | 13:1041596c416c | 234 | pid.setInputLimits(0.0f, 5.0f); |
kenjiArai | 13:1041596c416c | 235 | pid.setOutputLimits(0.0f, 5.0f); |
kenjiArai | 13:1041596c416c | 236 | pid.setSetPoint(TRGT_TEMP/10.0f); |
kenjiArai | 13:1041596c416c | 237 | } |
kenjiArai | 13:1041596c416c | 238 | } else { |
kenjiArai | 13:1041596c416c | 239 | error_count = 3600; |
kenjiArai | 13:1041596c416c | 240 | } |
kenjiArai | 13:1041596c416c | 241 | heater.set_voltage(-volt); |
kenjiArai | 13:1041596c416c | 242 | //PRINTF("Volt=%f V\r\n", volt); |
kenjiArai | 13:1041596c416c | 243 | if (heater.status()) { |
kenjiArai | 13:1041596c416c | 244 | heater.reset(); |
kenjiArai | 13:1041596c416c | 245 | } |
kenjiArai | 13:1041596c416c | 246 | if ((tmp > (TRGT_TEMP + 0.2f)) || (tmp < (TRGT_TEMP - 0.4f))){ |
kenjiArai | 13:1041596c416c | 247 | disp_data.temp_is_okay = 0; |
kenjiArai | 13:1041596c416c | 248 | } else { |
kenjiArai | 13:1041596c416c | 249 | disp_data.temp_is_okay = 1; |
kenjiArai | 13:1041596c416c | 250 | } |
kenjiArai | 13:1041596c416c | 251 | #if defined(HW_TEST_GO) |
kenjiArai | 13:1041596c416c | 252 | pc.printf("Volt=%+4.3f [V] , Oven Temp. %+6.3f [degC]", volt, tmp); |
kenjiArai | 13:1041596c416c | 253 | pc.printf(", Diff=%3.1f-x= %+6.3f \r\n", TRGT_TEMP, TRGT_TEMP - tmp); |
kenjiArai | 13:1041596c416c | 254 | #endif |
kenjiArai | 13:1041596c416c | 255 | keep_1sec = 1000 - keep_1sec; |
kenjiArai | 14:ba6ea409ab05 | 256 | ThisThread::sleep_for(keep_1sec); // 1sec interval |
kenjiArai | 13:1041596c416c | 257 | } |
kenjiArai | 13:1041596c416c | 258 | } |
kenjiArai | 13:1041596c416c | 259 | |
kenjiArai | 13:1041596c416c | 260 | void display_data(void const *args) |
kenjiArai | 13:1041596c416c | 261 | { |
kenjiArai | 13:1041596c416c | 262 | int32_t tim_remain; |
kenjiArai | 13:1041596c416c | 263 | |
kenjiArai | 13:1041596c416c | 264 | while(true){ |
kenjiArai | 13:1041596c416c | 265 | tmr1.reset(); |
kenjiArai | 13:1041596c416c | 266 | tmr1.start(); |
kenjiArai | 13:1041596c416c | 267 | disp_data.gps_1pps_ave = fc.read_num_in_buffer(); |
kenjiArai | 13:1041596c416c | 268 | disp_data.ready_1pps = check_gps_3d(); |
kenjiArai | 13:1041596c416c | 269 | // User_IF |
kenjiArai | 13:1041596c416c | 270 | dispay_LCD_and_UART(&disp_data); // separate files uif.cpp & uif.h |
kenjiArai | 13:1041596c416c | 271 | /* Wait */ |
kenjiArai | 13:1041596c416c | 272 | tim_remain = 1000 - tmr1.read_ms(); |
kenjiArai | 14:ba6ea409ab05 | 273 | ThisThread::sleep_for(tim_remain); |
kenjiArai | 13:1041596c416c | 274 | } |
kenjiArai | 13:1041596c416c | 275 | } |
kenjiArai | 13:1041596c416c | 276 | |
kenjiArai | 13:1041596c416c | 277 | void receive_gps(void const *args) |
kenjiArai | 13:1041596c416c | 278 | { |
kenjiArai | 13:1041596c416c | 279 | gps_data_rcv(); // infinit loop -> never return |
kenjiArai | 13:1041596c416c | 280 | // separate files GPSrcvr.cpp & GPSrcvr.h |
kenjiArai | 13:1041596c416c | 281 | } |
kenjiArai | 13:1041596c416c | 282 | |
kenjiArai | 13:1041596c416c | 283 | #if !defined(HW_TEST_GO) // Normal control mode |
kenjiArai | 13:1041596c416c | 284 | |
kenjiArai | 13:1041596c416c | 285 | // Thread definition |
kenjiArai | 13:1041596c416c | 286 | osThreadDef(measure_freq, osPriorityNormal,1024); |
kenjiArai | 13:1041596c416c | 287 | osThreadDef(measure_freq_recipro, osPriorityNormal,1024); |
kenjiArai | 13:1041596c416c | 288 | osThreadDef(temp_control, osPriorityNormal,2048); |
kenjiArai | 13:1041596c416c | 289 | osThreadDef(receive_gps, osPriorityNormal,1024); |
kenjiArai | 13:1041596c416c | 290 | osThreadDef(display_data, osPriorityNormal,2048); |
kenjiArai | 13:1041596c416c | 291 | |
kenjiArai | 13:1041596c416c | 292 | int main(){ |
kenjiArai | 13:1041596c416c | 293 | disp_first_msg(); |
kenjiArai | 14:ba6ea409ab05 | 294 | ThisThread::sleep_for(1000); // 1sec |
kenjiArai | 13:1041596c416c | 295 | disp_wait_gps(); |
kenjiArai | 13:1041596c416c | 296 | osThreadCreate(osThread(receive_gps), NULL); |
kenjiArai | 13:1041596c416c | 297 | PRINTF("\r\nStart GPS receiving!\r\n"); |
kenjiArai | 13:1041596c416c | 298 | while (check_gps_is_okay() == false){;} // wait till "true" |
kenjiArai | 13:1041596c416c | 299 | PRINTF("GPS data is valid!\r\n"); |
kenjiArai | 13:1041596c416c | 300 | fc.debug_printf_internal_data(); |
kenjiArai | 13:1041596c416c | 301 | osThreadCreate(osThread(measure_freq), NULL); |
kenjiArai | 14:ba6ea409ab05 | 302 | ThisThread::sleep_for(5); //wait |
kenjiArai | 13:1041596c416c | 303 | osThreadCreate(osThread(temp_control), NULL); |
kenjiArai | 14:ba6ea409ab05 | 304 | ThisThread::sleep_for(8); //wait |
kenjiArai | 13:1041596c416c | 305 | osThreadCreate(osThread(measure_freq_recipro), NULL); |
kenjiArai | 14:ba6ea409ab05 | 306 | ThisThread::sleep_for(3); //wait |
kenjiArai | 13:1041596c416c | 307 | osThreadCreate(osThread(display_data), NULL); |
kenjiArai | 14:ba6ea409ab05 | 308 | ThisThread::sleep_for(10); //wait |
kenjiArai | 13:1041596c416c | 309 | select_input_div_1or10or20(0); // BNC (none presclaer) |
kenjiArai | 13:1041596c416c | 310 | while(true) { |
kenjiArai | 13:1041596c416c | 311 | /* Wait until it is time to check again. */ |
kenjiArai | 14:ba6ea409ab05 | 312 | ThisThread::sleep_for(60000); // 1min. |
kenjiArai | 13:1041596c416c | 313 | } |
kenjiArai | 13:1041596c416c | 314 | } |
kenjiArai | 13:1041596c416c | 315 | |
kenjiArai | 13:1041596c416c | 316 | #else // Hardware Test mode |
kenjiArai | 13:1041596c416c | 317 | |
kenjiArai | 13:1041596c416c | 318 | #include "hw_tst.h" |
kenjiArai | 13:1041596c416c | 319 | extern void hardware_test(void); |
kenjiArai | 13:1041596c416c | 320 | |
kenjiArai | 13:1041596c416c | 321 | int main(){ |
kenjiArai | 13:1041596c416c | 322 | hardware_test(); |
kenjiArai | 13:1041596c416c | 323 | } |
kenjiArai | 13:1041596c416c | 324 | |
kenjiArai | 13:1041596c416c | 325 | double read_temperature(uint8_t n) |
kenjiArai | 13:1041596c416c | 326 | { |
kenjiArai | 13:1041596c416c | 327 | if (n == 0){ |
kenjiArai | 13:1041596c416c | 328 | t.set_config(OPERATION_MODE_CONT + RESOLUTION_16BIT); |
kenjiArai | 13:1041596c416c | 329 | return 0; |
kenjiArai | 13:1041596c416c | 330 | } else if (n == 1){ |
kenjiArai | 13:1041596c416c | 331 | return t.read_temp(); |
kenjiArai | 13:1041596c416c | 332 | } |
kenjiArai | 13:1041596c416c | 333 | return 0; |
kenjiArai | 13:1041596c416c | 334 | } |
kenjiArai | 13:1041596c416c | 335 | |
kenjiArai | 13:1041596c416c | 336 | #endif // !defined(HW_TEST_GO) |