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