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@6:44c2bcbdd77b, 2014-10-21 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue Oct 21 12:37:05 2014 +0000
- Revision:
- 6:44c2bcbdd77b
- Parent:
- 5:af9fa3d0731c
- Child:
- 7:0c09d29c4cf3
Frequency Counter program w/ LCD & Com output. Only for mbed LPC1768, Nucleo-F401 and Nucleo-F411. Now way to change pin assign.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 5:af9fa3d0731c | 1 | /* |
kenjiArai | 5:af9fa3d0731c | 2 | * mbed Application program / Frequency Counter |
kenjiArai | 5:af9fa3d0731c | 3 | * |
kenjiArai | 5:af9fa3d0731c | 4 | * Copyright (c) 2014 Kenji Arai / JH1PJL |
kenjiArai | 5:af9fa3d0731c | 5 | * http://www.page.sannet.ne.jp/kenjia/index.html |
kenjiArai | 5:af9fa3d0731c | 6 | * http://mbed.org/users/kenjiArai/ |
kenjiArai | 5:af9fa3d0731c | 7 | * Created: October 18th, 2014 |
kenjiArai | 6:44c2bcbdd77b | 8 | * Revised: October 21st, 2014 |
kenjiArai | 5:af9fa3d0731c | 9 | * |
kenjiArai | 5:af9fa3d0731c | 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
kenjiArai | 5:af9fa3d0731c | 11 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
kenjiArai | 5:af9fa3d0731c | 12 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kenjiArai | 5:af9fa3d0731c | 13 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kenjiArai | 5:af9fa3d0731c | 14 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kenjiArai | 5:af9fa3d0731c | 15 | */ |
mio | 0:c988614df67a | 16 | |
kenjiArai | 6:44c2bcbdd77b | 17 | #define USE_COM // use Communication with PC(UART) |
kenjiArai | 6:44c2bcbdd77b | 18 | //#define USE_TEXT_LCD // use Text LCD/I2C Interface |
kenjiArai | 6:44c2bcbdd77b | 19 | //#define USE_GRAP_LCD // use Grafic LCD/SPI interface |
kenjiArai | 6:44c2bcbdd77b | 20 | |
kenjiArai | 5:af9fa3d0731c | 21 | // Include --------------------------------------------------------------------------------------- |
mio | 0:c988614df67a | 22 | #include "mbed.h" |
kenjiArai | 6:44c2bcbdd77b | 23 | #include "freq_counter.h" |
kenjiArai | 6:44c2bcbdd77b | 24 | #if defined(USE_TEXT_LCD) |
kenjiArai | 5:af9fa3d0731c | 25 | #include "TextLCD.h" // Std. lib./ LCD control |
kenjiArai | 6:44c2bcbdd77b | 26 | #endif |
kenjiArai | 6:44c2bcbdd77b | 27 | #if defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 28 | #include "ST7565_SPI_LCD.h" |
kenjiArai | 6:44c2bcbdd77b | 29 | #endif |
mio | 0:c988614df67a | 30 | |
kenjiArai | 5:af9fa3d0731c | 31 | // Definition ------------------------------------------------------------------------------------ |
kenjiArai | 5:af9fa3d0731c | 32 | #ifdef USE_COM |
kenjiArai | 5:af9fa3d0731c | 33 | #define BAUD(x) pc.baud(x) |
kenjiArai | 5:af9fa3d0731c | 34 | #define GETC(x) pc.getc(x) |
kenjiArai | 5:af9fa3d0731c | 35 | #define PUTC(x) pc.putc(x) |
kenjiArai | 5:af9fa3d0731c | 36 | #define PRINTF(...) pc.printf(__VA_ARGS__) |
kenjiArai | 5:af9fa3d0731c | 37 | #define READABLE(x) pc.readable(x) |
kenjiArai | 5:af9fa3d0731c | 38 | #else |
kenjiArai | 5:af9fa3d0731c | 39 | #define BAUD(x) {;} |
kenjiArai | 5:af9fa3d0731c | 40 | #define GETC(x) {;} |
kenjiArai | 5:af9fa3d0731c | 41 | #define PUTC(x) {;} |
kenjiArai | 5:af9fa3d0731c | 42 | #define PRINTF(...) {;} |
kenjiArai | 5:af9fa3d0731c | 43 | #define READABLE(x) {;} |
kenjiArai | 5:af9fa3d0731c | 44 | #endif |
mio | 1:2a347c40b1da | 45 | |
kenjiArai | 6:44c2bcbdd77b | 46 | #if defined(TARGET_LPC1768) |
kenjiArai | 5:af9fa3d0731c | 47 | // LPC1768 Frequency example |
kenjiArai | 5:af9fa3d0731c | 48 | // Outout mbed's "PWM6" pin to 96MHZ/19 = 5.052MHz (Approx) |
kenjiArai | 5:af9fa3d0731c | 49 | #define PWM_EAMPLE() PWM6_SETCLK(19) |
kenjiArai | 5:af9fa3d0731c | 50 | // Outout mbed's "PWM6" pin to 96MHZ/96 = 1.000MHz (Approx) |
kenjiArai | 5:af9fa3d0731c | 51 | //#define PWM_EAMPLE() PWM6_SETCLK(96) |
kenjiArai | 6:44c2bcbdd77b | 52 | #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) |
kenjiArai | 6:44c2bcbdd77b | 53 | #define led_not_zero temp_ram |
kenjiArai | 6:44c2bcbdd77b | 54 | #define led_01 temp_ram |
kenjiArai | 6:44c2bcbdd77b | 55 | #define led_10 temp_ram |
kenjiArai | 6:44c2bcbdd77b | 56 | #define PWM_EAMPLE() port_mco1_mco2_set() |
kenjiArai | 6:44c2bcbdd77b | 57 | #else |
kenjiArai | 6:44c2bcbdd77b | 58 | #error "No support for this CPU" |
kenjiArai | 6:44c2bcbdd77b | 59 | #endif |
kenjiArai | 6:44c2bcbdd77b | 60 | |
kenjiArai | 5:af9fa3d0731c | 61 | // Object ---------------------------------------------------------------------------------------- |
kenjiArai | 6:44c2bcbdd77b | 62 | #if defined(TARGET_LPC1768) |
kenjiArai | 6:44c2bcbdd77b | 63 | |
kenjiArai | 5:af9fa3d0731c | 64 | DigitalOut led_gate(LED1); |
kenjiArai | 5:af9fa3d0731c | 65 | DigitalOut led_not_zero(LED2); |
kenjiArai | 5:af9fa3d0731c | 66 | DigitalOut led_01(LED3); |
kenjiArai | 5:af9fa3d0731c | 67 | DigitalOut led_10(LED4); |
kenjiArai | 5:af9fa3d0731c | 68 | DigitalIn sw_01(p19); |
kenjiArai | 5:af9fa3d0731c | 69 | DigitalIn sw_10(p20); |
kenjiArai | 5:af9fa3d0731c | 70 | Serial pc(USBTX, USBRX); |
kenjiArai | 5:af9fa3d0731c | 71 | I2C i2cBus(p9, p10); // SDA, SCL |
kenjiArai | 6:44c2bcbdd77b | 72 | #if defined(USE_TEXT_LCD) |
kenjiArai | 5:af9fa3d0731c | 73 | TextLCD_I2C_N lcd(&i2cBus, 0x7c, TextLCD::LCD8x2); // LCD(Akizuki AQM0802A) |
kenjiArai | 6:44c2bcbdd77b | 74 | #endif |
kenjiArai | 6:44c2bcbdd77b | 75 | #if defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 76 | ST7565 glcd(p5, p7, p19, p8, p20, ST7565::AD12864SPI); // mosi, sck, reset, a0, ncs |
kenjiArai | 6:44c2bcbdd77b | 77 | #endif |
kenjiArai | 5:af9fa3d0731c | 78 | PwmOut fmclck(p21); // for RESERVE pin21 as PWM1[6] |
kenjiArai | 5:af9fa3d0731c | 79 | F_COUNTER fc(p30); |
mio | 0:c988614df67a | 80 | |
kenjiArai | 6:44c2bcbdd77b | 81 | #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) |
kenjiArai | 6:44c2bcbdd77b | 82 | |
kenjiArai | 6:44c2bcbdd77b | 83 | DigitalOut led_gate(LED1); |
kenjiArai | 6:44c2bcbdd77b | 84 | DigitalIn sw_01(PC_0); |
kenjiArai | 6:44c2bcbdd77b | 85 | DigitalIn sw_10(PC_1); |
kenjiArai | 6:44c2bcbdd77b | 86 | Serial pc(USBTX, USBRX); |
kenjiArai | 6:44c2bcbdd77b | 87 | I2C i2cBus(PB_9,PB_8); // SDA, SCL |
kenjiArai | 6:44c2bcbdd77b | 88 | #if defined(USE_TEXT_LCD) |
kenjiArai | 6:44c2bcbdd77b | 89 | TextLCD_I2C_N lcd(&i2cBus, 0x7c, TextLCD::LCD8x2); // LCD(Akizuki AQM0802A) |
kenjiArai | 6:44c2bcbdd77b | 90 | #endif |
kenjiArai | 6:44c2bcbdd77b | 91 | #if defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 92 | ST7565 glcd(PB_5, PB_3, PA_10, PB_10, PA_9, ST7565::AD12864SPI); // mosi, sck, reset, a0, ncs |
kenjiArai | 6:44c2bcbdd77b | 93 | #endif |
kenjiArai | 6:44c2bcbdd77b | 94 | F_COUNTER fc(PA_0); |
kenjiArai | 6:44c2bcbdd77b | 95 | // PA8 & PC9 uses for MCO_1 % MCO_2 -> Clock output for checking |
kenjiArai | 6:44c2bcbdd77b | 96 | |
kenjiArai | 6:44c2bcbdd77b | 97 | #else |
kenjiArai | 6:44c2bcbdd77b | 98 | #error "No support for this CPU" |
kenjiArai | 6:44c2bcbdd77b | 99 | #endif |
kenjiArai | 6:44c2bcbdd77b | 100 | |
kenjiArai | 5:af9fa3d0731c | 101 | // RAM ------------------------------------------------------------------------------------------- |
kenjiArai | 5:af9fa3d0731c | 102 | float freqency; |
kenjiArai | 6:44c2bcbdd77b | 103 | double t_gate; |
kenjiArai | 5:af9fa3d0731c | 104 | uint8_t sw; |
kenjiArai | 5:af9fa3d0731c | 105 | |
kenjiArai | 6:44c2bcbdd77b | 106 | uint32_t temp_ram; // dummy ram (please keep it!) |
kenjiArai | 6:44c2bcbdd77b | 107 | |
kenjiArai | 5:af9fa3d0731c | 108 | // ROM / Constant data --------------------------------------------------------------------------- |
mio | 1:2a347c40b1da | 109 | |
kenjiArai | 5:af9fa3d0731c | 110 | // Function prototypes --------------------------------------------------------------------------- |
kenjiArai | 5:af9fa3d0731c | 111 | |
kenjiArai | 5:af9fa3d0731c | 112 | // Function prototypes --------------------------------------------------------------------------- |
kenjiArai | 5:af9fa3d0731c | 113 | |
kenjiArai | 5:af9fa3d0731c | 114 | //------------------------------------------------------------------------------------------------- |
kenjiArai | 5:af9fa3d0731c | 115 | // Control Program |
kenjiArai | 5:af9fa3d0731c | 116 | //------------------------------------------------------------------------------------------------- |
kenjiArai | 5:af9fa3d0731c | 117 | #if defined(TARGET_LPC1768) |
mio | 1:2a347c40b1da | 118 | // Clock Output From pin21(PWM6) |
mio | 1:2a347c40b1da | 119 | // Set Clock Freq with div. |
mio | 1:2a347c40b1da | 120 | // if mbed is running at 96MHz, div is set 96 to Get 1MHz. |
mio | 1:2a347c40b1da | 121 | void PWM6_SETCLK(int div) |
mio | 1:2a347c40b1da | 122 | { |
kenjiArai | 5:af9fa3d0731c | 123 | LPC_PWM1->TCR = (1 << 1); // 1)Reset counter, disable PWM |
kenjiArai | 5:af9fa3d0731c | 124 | LPC_SC->PCLKSEL0 &= ~(0x3 << 12); |
kenjiArai | 5:af9fa3d0731c | 125 | LPC_SC->PCLKSEL0 |= (1 << 12); // 2)Set peripheral clock divider to /1, i.e. system clock |
kenjiArai | 5:af9fa3d0731c | 126 | LPC_PWM1->MR0 = div - 1; // 3)Match Register 0 is shared period counter for all PWM1 |
kenjiArai | 5:af9fa3d0731c | 127 | LPC_PWM1->MR6 = (div + 1)>> 1; // |
kenjiArai | 5:af9fa3d0731c | 128 | LPC_PWM1->LER |= 1; // 4)Start updating at next period start |
kenjiArai | 5:af9fa3d0731c | 129 | LPC_PWM1->TCR = (1 << 0) || (1 << 3); // 5)Enable counter and PWM |
kenjiArai | 5:af9fa3d0731c | 130 | } |
kenjiArai | 6:44c2bcbdd77b | 131 | #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) |
kenjiArai | 6:44c2bcbdd77b | 132 | void port_mco1_mco2_set(void) |
kenjiArai | 6:44c2bcbdd77b | 133 | { |
kenjiArai | 6:44c2bcbdd77b | 134 | uint32_t temp = 0x00; |
kenjiArai | 6:44c2bcbdd77b | 135 | |
kenjiArai | 6:44c2bcbdd77b | 136 | // PA8 -> MCO_1 |
kenjiArai | 6:44c2bcbdd77b | 137 | temp = ((uint32_t)(GPIO_AF0_MCO) << (((uint32_t)8 & (uint32_t)0x07) * 4)) ; |
kenjiArai | 6:44c2bcbdd77b | 138 | GPIOA->AFR[8 >> 3] &= ~((uint32_t)0xf << ((uint32_t)(8 & (uint32_t)0x07) * 4)) ; |
kenjiArai | 6:44c2bcbdd77b | 139 | GPIOA->AFR[8 >> 3] |= temp; |
kenjiArai | 6:44c2bcbdd77b | 140 | GPIOA->MODER &= ~(GPIO_MODER_MODER0 << (8 * 2)); |
kenjiArai | 6:44c2bcbdd77b | 141 | GPIOA->MODER |= (0x2 << (8 * 2)); |
kenjiArai | 6:44c2bcbdd77b | 142 | // PC9 -> MCO_2 |
kenjiArai | 6:44c2bcbdd77b | 143 | temp = ((uint32_t)(GPIO_AF0_MCO) << (((uint32_t)9 & (uint32_t)0x07) * 4)) ; |
kenjiArai | 6:44c2bcbdd77b | 144 | GPIOC->AFR[9 >> 3] &= ~((uint32_t)0xf << ((uint32_t)(9 & (uint32_t)0x07) * 4)) ; |
kenjiArai | 6:44c2bcbdd77b | 145 | GPIOC->AFR[9 >> 3] |= temp; |
kenjiArai | 6:44c2bcbdd77b | 146 | GPIOC->MODER &= ~(GPIO_MODER_MODER0 << (9 * 2)); |
kenjiArai | 6:44c2bcbdd77b | 147 | GPIOC->MODER |= (0x2 << (9 * 2)); |
kenjiArai | 6:44c2bcbdd77b | 148 | // Select output clock source |
kenjiArai | 6:44c2bcbdd77b | 149 | RCC->CFGR &= 0x009fffff; |
kenjiArai | 6:44c2bcbdd77b | 150 | // MC0_1 output HSE 1/4, MCO_2 output SYSCLK 1/4 |
kenjiArai | 6:44c2bcbdd77b | 151 | // MCO2 MCO2PRE MCO1PRE MCO1 |
kenjiArai | 6:44c2bcbdd77b | 152 | RCC->CFGR |= (0x0 << 30) + (0x6 << 27) + (0x6 << 24) + (0x3 << 22); |
kenjiArai | 6:44c2bcbdd77b | 153 | } |
kenjiArai | 5:af9fa3d0731c | 154 | #else |
kenjiArai | 5:af9fa3d0731c | 155 | #error "No support for this CPU" |
kenjiArai | 5:af9fa3d0731c | 156 | #endif |
kenjiArai | 5:af9fa3d0731c | 157 | |
kenjiArai | 5:af9fa3d0731c | 158 | void example_freq_out(void) |
kenjiArai | 5:af9fa3d0731c | 159 | { |
kenjiArai | 5:af9fa3d0731c | 160 | PWM_EAMPLE(); |
kenjiArai | 5:af9fa3d0731c | 161 | } |
kenjiArai | 5:af9fa3d0731c | 162 | |
kenjiArai | 5:af9fa3d0731c | 163 | void read_sw_and_set_gate_time(void) |
kenjiArai | 5:af9fa3d0731c | 164 | { |
kenjiArai | 5:af9fa3d0731c | 165 | if (sw_10) { |
kenjiArai | 5:af9fa3d0731c | 166 | led_10 = 1; |
kenjiArai | 5:af9fa3d0731c | 167 | sw = 2; |
kenjiArai | 5:af9fa3d0731c | 168 | } else { |
kenjiArai | 5:af9fa3d0731c | 169 | led_10 = 0; |
kenjiArai | 5:af9fa3d0731c | 170 | sw = 0; |
kenjiArai | 5:af9fa3d0731c | 171 | } |
kenjiArai | 5:af9fa3d0731c | 172 | if (sw_01) { |
kenjiArai | 5:af9fa3d0731c | 173 | led_01 = 1; |
kenjiArai | 5:af9fa3d0731c | 174 | sw += 1; |
kenjiArai | 5:af9fa3d0731c | 175 | } else { |
kenjiArai | 5:af9fa3d0731c | 176 | led_01 = 0; |
kenjiArai | 5:af9fa3d0731c | 177 | } |
kenjiArai | 5:af9fa3d0731c | 178 | switch (sw) { |
kenjiArai | 5:af9fa3d0731c | 179 | case 0: |
kenjiArai | 5:af9fa3d0731c | 180 | t_gate = 0.001; |
kenjiArai | 5:af9fa3d0731c | 181 | break; |
kenjiArai | 5:af9fa3d0731c | 182 | case 1: |
kenjiArai | 5:af9fa3d0731c | 183 | t_gate = 0.01; |
kenjiArai | 5:af9fa3d0731c | 184 | break; |
kenjiArai | 5:af9fa3d0731c | 185 | case 2: |
kenjiArai | 5:af9fa3d0731c | 186 | t_gate = 0.1; |
kenjiArai | 5:af9fa3d0731c | 187 | break; |
kenjiArai | 5:af9fa3d0731c | 188 | case 3: |
kenjiArai | 5:af9fa3d0731c | 189 | default: |
kenjiArai | 5:af9fa3d0731c | 190 | t_gate = 1.0; |
kenjiArai | 5:af9fa3d0731c | 191 | break; |
kenjiArai | 5:af9fa3d0731c | 192 | } |
mio | 1:2a347c40b1da | 193 | } |
mio | 0:c988614df67a | 194 | |
kenjiArai | 5:af9fa3d0731c | 195 | int main() |
kenjiArai | 5:af9fa3d0731c | 196 | { |
kenjiArai | 6:44c2bcbdd77b | 197 | PRINTF("\r\nFrequency Counter by JH1PJL created on "__DATE__"\r\n"); |
kenjiArai | 5:af9fa3d0731c | 198 | t_gate = 1.0; |
kenjiArai | 5:af9fa3d0731c | 199 | // Initialize LCD |
kenjiArai | 6:44c2bcbdd77b | 200 | #if defined(USE_TEXT_LCD) |
kenjiArai | 5:af9fa3d0731c | 201 | lcd.locate(0, 0); // 1st line top |
kenjiArai | 5:af9fa3d0731c | 202 | // 12345678 |
kenjiArai | 5:af9fa3d0731c | 203 | lcd.printf("Fre-Cntr"); |
kenjiArai | 5:af9fa3d0731c | 204 | lcd.locate(0, 1); // 2nd line top |
kenjiArai | 5:af9fa3d0731c | 205 | // 12345678 |
kenjiArai | 5:af9fa3d0731c | 206 | lcd.puts(" JH1PJL "); |
kenjiArai | 5:af9fa3d0731c | 207 | lcd.setContrast(0x16); |
kenjiArai | 6:44c2bcbdd77b | 208 | #endif |
kenjiArai | 6:44c2bcbdd77b | 209 | #if defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 210 | glcd.cls(); |
kenjiArai | 6:44c2bcbdd77b | 211 | glcd.set_contrast(0x06); |
kenjiArai | 6:44c2bcbdd77b | 212 | glcd.locate(0, 0); |
kenjiArai | 6:44c2bcbdd77b | 213 | glcd.printf("--- Frequency Counter --\r\n"); |
kenjiArai | 6:44c2bcbdd77b | 214 | glcd.printf(" Kenji Arai / JH1PJL\r\n" ); |
kenjiArai | 6:44c2bcbdd77b | 215 | glcd.printf(" \r\n"); |
kenjiArai | 6:44c2bcbdd77b | 216 | #if defined(TARGET_LPC1768) |
kenjiArai | 6:44c2bcbdd77b | 217 | glcd.printf(" Input: P30 PWM out: P21\r\n" ); |
kenjiArai | 6:44c2bcbdd77b | 218 | glcd.printf(" LED1:Gate LED2:signal \r\n" ); |
kenjiArai | 6:44c2bcbdd77b | 219 | #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) |
kenjiArai | 6:44c2bcbdd77b | 220 | glcd.printf(" Input: PA0 PWM out: PA8\r\n" ); |
kenjiArai | 6:44c2bcbdd77b | 221 | glcd.printf(" LED1:Gate \r\n" ); |
kenjiArai | 6:44c2bcbdd77b | 222 | #else |
kenjiArai | 6:44c2bcbdd77b | 223 | #error "No support for this CPU" |
kenjiArai | 6:44c2bcbdd77b | 224 | #endif |
kenjiArai | 6:44c2bcbdd77b | 225 | #endif // defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 226 | #if defined(USE_TEXT_LCD) |
kenjiArai | 5:af9fa3d0731c | 227 | wait(5.0); |
kenjiArai | 5:af9fa3d0731c | 228 | lcd.locate(0, 1); // 2nd line top |
kenjiArai | 5:af9fa3d0731c | 229 | // 12345678 |
kenjiArai | 5:af9fa3d0731c | 230 | lcd.puts(" "); |
kenjiArai | 6:44c2bcbdd77b | 231 | #endif |
kenjiArai | 5:af9fa3d0731c | 232 | // Set PWM for example |
kenjiArai | 5:af9fa3d0731c | 233 | example_freq_out(); |
kenjiArai | 5:af9fa3d0731c | 234 | freqency = 0; |
kenjiArai | 5:af9fa3d0731c | 235 | while(true) { |
kenjiArai | 5:af9fa3d0731c | 236 | led_gate = 1; |
kenjiArai | 5:af9fa3d0731c | 237 | freqency = (float)fc.read_frequency(t_gate); |
kenjiArai | 5:af9fa3d0731c | 238 | led_gate = 0; |
kenjiArai | 5:af9fa3d0731c | 239 | wait(1.1 - t_gate); |
kenjiArai | 5:af9fa3d0731c | 240 | if (freqency == 0) { |
kenjiArai | 5:af9fa3d0731c | 241 | led_not_zero = 1; |
kenjiArai | 5:af9fa3d0731c | 242 | } else { |
kenjiArai | 5:af9fa3d0731c | 243 | led_not_zero = 0; |
kenjiArai | 5:af9fa3d0731c | 244 | } |
kenjiArai | 5:af9fa3d0731c | 245 | read_sw_and_set_gate_time(); |
kenjiArai | 6:44c2bcbdd77b | 246 | PRINTF("f= %9.0f [Hz], gate= %4.3f [Sec]\r\n", freqency/t_gate, t_gate); |
kenjiArai | 6:44c2bcbdd77b | 247 | #if defined(USE_TEXT_LCD) |
kenjiArai | 5:af9fa3d0731c | 248 | lcd.locate(0, 0); // 1st line top |
kenjiArai | 5:af9fa3d0731c | 249 | lcd.printf("%8.0f", freqency); |
kenjiArai | 5:af9fa3d0731c | 250 | lcd.locate(0, 1); // 2nd line top |
kenjiArai | 6:44c2bcbdd77b | 251 | #endif |
kenjiArai | 6:44c2bcbdd77b | 252 | #if defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 253 | glcd.locate(0, 10); |
kenjiArai | 6:44c2bcbdd77b | 254 | glcd.printf(" \r\n"); |
kenjiArai | 6:44c2bcbdd77b | 255 | glcd.locate(10, 10); |
kenjiArai | 6:44c2bcbdd77b | 256 | glcd.printf("%8.0f Hz", freqency); |
kenjiArai | 6:44c2bcbdd77b | 257 | glcd.locate(10, 20); |
kenjiArai | 6:44c2bcbdd77b | 258 | #endif |
kenjiArai | 5:af9fa3d0731c | 259 | switch (sw) { |
kenjiArai | 5:af9fa3d0731c | 260 | case 0: |
kenjiArai | 6:44c2bcbdd77b | 261 | #if defined(USE_TEXT_LCD) |
kenjiArai | 5:af9fa3d0731c | 262 | // 12345678 |
kenjiArai | 5:af9fa3d0731c | 263 | lcd.printf("x1000 Hz"); |
kenjiArai | 6:44c2bcbdd77b | 264 | #endif |
kenjiArai | 6:44c2bcbdd77b | 265 | #if defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 266 | glcd.printf(" x1000 "); |
kenjiArai | 6:44c2bcbdd77b | 267 | #endif |
kenjiArai | 5:af9fa3d0731c | 268 | break; |
kenjiArai | 5:af9fa3d0731c | 269 | case 1: |
kenjiArai | 6:44c2bcbdd77b | 270 | #if defined(USE_TEXT_LCD) |
kenjiArai | 5:af9fa3d0731c | 271 | // 12345678 |
kenjiArai | 5:af9fa3d0731c | 272 | lcd.printf("x100 Hz"); |
kenjiArai | 6:44c2bcbdd77b | 273 | #endif |
kenjiArai | 6:44c2bcbdd77b | 274 | #if defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 275 | glcd.printf(" x100 "); |
kenjiArai | 6:44c2bcbdd77b | 276 | #endif |
kenjiArai | 5:af9fa3d0731c | 277 | break; |
kenjiArai | 5:af9fa3d0731c | 278 | case 2: |
kenjiArai | 6:44c2bcbdd77b | 279 | #if defined(USE_TEXT_LCD) |
kenjiArai | 5:af9fa3d0731c | 280 | // 12345678 |
kenjiArai | 5:af9fa3d0731c | 281 | lcd.printf("x10 Hz"); |
kenjiArai | 6:44c2bcbdd77b | 282 | #endif |
kenjiArai | 6:44c2bcbdd77b | 283 | #if defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 284 | glcd.printf("x10 "); |
kenjiArai | 6:44c2bcbdd77b | 285 | #endif |
kenjiArai | 5:af9fa3d0731c | 286 | break; |
kenjiArai | 5:af9fa3d0731c | 287 | case 3: |
kenjiArai | 5:af9fa3d0731c | 288 | default: |
kenjiArai | 6:44c2bcbdd77b | 289 | #if defined(USE_TEXT_LCD) |
kenjiArai | 5:af9fa3d0731c | 290 | // 12345678 |
kenjiArai | 5:af9fa3d0731c | 291 | lcd.printf("x1 Hz"); |
kenjiArai | 6:44c2bcbdd77b | 292 | #endif |
kenjiArai | 6:44c2bcbdd77b | 293 | #if defined(USE_GRAP_LCD) |
kenjiArai | 6:44c2bcbdd77b | 294 | glcd.printf(" x1 "); |
kenjiArai | 6:44c2bcbdd77b | 295 | #endif |
kenjiArai | 5:af9fa3d0731c | 296 | break; |
kenjiArai | 5:af9fa3d0731c | 297 | } |
mio | 1:2a347c40b1da | 298 | } |
mio | 1:2a347c40b1da | 299 | } |