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 Kenji Arai

Please refer following.
/users/kenjiArai/notebook/frequency-counters/

Committer:
kenjiArai
Date:
Wed Oct 22 00:41:14 2014 +0000
Revision:
7:0c09d29c4cf3
Parent:
6:44c2bcbdd77b
Child:
8:7b033903c8fb
Added mbed LPC1114FN28 board based on Tetsuya Suzuki/fc1114 program

Who changed what in which revision?

UserRevisionLine numberNew 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 7:0c09d29c4cf3 8 * Revised: October 22nd, 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 7:0c09d29c4cf3 18 #define USE_TEXT_LCD // use Text LCD/I2C Interface
kenjiArai 7:0c09d29c4cf3 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 7:0c09d29c4cf3 49 #define CLK_REFRENCE() PWM6_SETCLK(19)
kenjiArai 5:af9fa3d0731c 50 // Outout mbed's "PWM6" pin to 96MHZ/96 = 1.000MHz (Approx)
kenjiArai 7:0c09d29c4cf3 51 //#define CLK_REFRENCE() PWM6_SETCLK(96)
kenjiArai 7:0c09d29c4cf3 52 #elif defined(TARGET_LPC1114)
kenjiArai 7:0c09d29c4cf3 53 #define led_not_zero temp_ram
kenjiArai 7:0c09d29c4cf3 54 #define led_01 temp_ram
kenjiArai 7:0c09d29c4cf3 55 #define led_10 temp_ram
kenjiArai 7:0c09d29c4cf3 56 #define CLK_REFRENCE() clock_out()
kenjiArai 7:0c09d29c4cf3 57 #warning "Don't forget LPC1114 runs with internal clock. Measurement data is not accurate!!"
kenjiArai 6:44c2bcbdd77b 58 #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
kenjiArai 6:44c2bcbdd77b 59 #define led_not_zero temp_ram
kenjiArai 6:44c2bcbdd77b 60 #define led_01 temp_ram
kenjiArai 6:44c2bcbdd77b 61 #define led_10 temp_ram
kenjiArai 7:0c09d29c4cf3 62 #define CLK_REFRENCE() port_mco1_mco2_set()
kenjiArai 6:44c2bcbdd77b 63 #else
kenjiArai 6:44c2bcbdd77b 64 #error "No support for this CPU"
kenjiArai 6:44c2bcbdd77b 65 #endif
kenjiArai 6:44c2bcbdd77b 66
kenjiArai 5:af9fa3d0731c 67 // Object ----------------------------------------------------------------------------------------
kenjiArai 6:44c2bcbdd77b 68 #if defined(TARGET_LPC1768)
kenjiArai 6:44c2bcbdd77b 69
kenjiArai 5:af9fa3d0731c 70 DigitalOut led_gate(LED1);
kenjiArai 5:af9fa3d0731c 71 DigitalOut led_not_zero(LED2);
kenjiArai 5:af9fa3d0731c 72 DigitalOut led_01(LED3);
kenjiArai 5:af9fa3d0731c 73 DigitalOut led_10(LED4);
kenjiArai 5:af9fa3d0731c 74 DigitalIn sw_01(p19);
kenjiArai 5:af9fa3d0731c 75 DigitalIn sw_10(p20);
kenjiArai 5:af9fa3d0731c 76 Serial pc(USBTX, USBRX);
kenjiArai 5:af9fa3d0731c 77 I2C i2cBus(p9, p10); // SDA, SCL
kenjiArai 6:44c2bcbdd77b 78 #if defined(USE_TEXT_LCD)
kenjiArai 5:af9fa3d0731c 79 TextLCD_I2C_N lcd(&i2cBus, 0x7c, TextLCD::LCD8x2); // LCD(Akizuki AQM0802A)
kenjiArai 6:44c2bcbdd77b 80 #endif
kenjiArai 6:44c2bcbdd77b 81 #if defined(USE_GRAP_LCD)
kenjiArai 6:44c2bcbdd77b 82 ST7565 glcd(p5, p7, p19, p8, p20, ST7565::AD12864SPI); // mosi, sck, reset, a0, ncs
kenjiArai 6:44c2bcbdd77b 83 #endif
kenjiArai 5:af9fa3d0731c 84 PwmOut fmclck(p21); // for RESERVE pin21 as PWM1[6]
kenjiArai 5:af9fa3d0731c 85 F_COUNTER fc(p30);
mio 0:c988614df67a 86
kenjiArai 7:0c09d29c4cf3 87 #elif defined(TARGET_LPC1114)
kenjiArai 7:0c09d29c4cf3 88
kenjiArai 7:0c09d29c4cf3 89 DigitalOut led_gate(LED2);
kenjiArai 7:0c09d29c4cf3 90 DigitalIn sw_01(dp25);
kenjiArai 7:0c09d29c4cf3 91 DigitalIn sw_10(dp26);
kenjiArai 7:0c09d29c4cf3 92 Serial pc(dp16,dp15); // Communication with Host
kenjiArai 7:0c09d29c4cf3 93 I2C i2cBus(dp5,dp27); // SDA, SCL
kenjiArai 7:0c09d29c4cf3 94 #if defined(USE_TEXT_LCD)
kenjiArai 7:0c09d29c4cf3 95 TextLCD_I2C_N lcd(&i2cBus, 0x7c, TextLCD::LCD8x2); // LCD(Akizuki AQM0802A)
kenjiArai 7:0c09d29c4cf3 96 #endif
kenjiArai 7:0c09d29c4cf3 97 #if defined(USE_GRAP_LCD)
kenjiArai 7:0c09d29c4cf3 98 ST7565 glcd(dp2, dp6, dp10, dp4, dp9, ST7565::AQM1248A); // mosi, sck, reset, a0, ncs
kenjiArai 7:0c09d29c4cf3 99 #endif
kenjiArai 7:0c09d29c4cf3 100 F_COUNTER fc(dp14);
kenjiArai 7:0c09d29c4cf3 101 // dp24 uses for CLOCKOUT -> Clock output for checking
kenjiArai 7:0c09d29c4cf3 102
kenjiArai 6:44c2bcbdd77b 103 #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
kenjiArai 6:44c2bcbdd77b 104
kenjiArai 6:44c2bcbdd77b 105 DigitalOut led_gate(LED1);
kenjiArai 6:44c2bcbdd77b 106 DigitalIn sw_01(PC_0);
kenjiArai 6:44c2bcbdd77b 107 DigitalIn sw_10(PC_1);
kenjiArai 6:44c2bcbdd77b 108 Serial pc(USBTX, USBRX);
kenjiArai 6:44c2bcbdd77b 109 I2C i2cBus(PB_9,PB_8); // SDA, SCL
kenjiArai 6:44c2bcbdd77b 110 #if defined(USE_TEXT_LCD)
kenjiArai 6:44c2bcbdd77b 111 TextLCD_I2C_N lcd(&i2cBus, 0x7c, TextLCD::LCD8x2); // LCD(Akizuki AQM0802A)
kenjiArai 6:44c2bcbdd77b 112 #endif
kenjiArai 6:44c2bcbdd77b 113 #if defined(USE_GRAP_LCD)
kenjiArai 6:44c2bcbdd77b 114 ST7565 glcd(PB_5, PB_3, PA_10, PB_10, PA_9, ST7565::AD12864SPI); // mosi, sck, reset, a0, ncs
kenjiArai 6:44c2bcbdd77b 115 #endif
kenjiArai 6:44c2bcbdd77b 116 F_COUNTER fc(PA_0);
kenjiArai 6:44c2bcbdd77b 117 // PA8 & PC9 uses for MCO_1 % MCO_2 -> Clock output for checking
kenjiArai 6:44c2bcbdd77b 118
kenjiArai 6:44c2bcbdd77b 119 #else
kenjiArai 6:44c2bcbdd77b 120 #error "No support for this CPU"
kenjiArai 6:44c2bcbdd77b 121 #endif
kenjiArai 6:44c2bcbdd77b 122
kenjiArai 5:af9fa3d0731c 123 // RAM -------------------------------------------------------------------------------------------
kenjiArai 5:af9fa3d0731c 124 float freqency;
kenjiArai 6:44c2bcbdd77b 125 double t_gate;
kenjiArai 5:af9fa3d0731c 126 uint8_t sw;
kenjiArai 5:af9fa3d0731c 127
kenjiArai 6:44c2bcbdd77b 128 uint32_t temp_ram; // dummy ram (please keep it!)
kenjiArai 6:44c2bcbdd77b 129
kenjiArai 5:af9fa3d0731c 130 // ROM / Constant data ---------------------------------------------------------------------------
mio 1:2a347c40b1da 131
kenjiArai 5:af9fa3d0731c 132 // Function prototypes ---------------------------------------------------------------------------
kenjiArai 5:af9fa3d0731c 133
kenjiArai 5:af9fa3d0731c 134 // Function prototypes ---------------------------------------------------------------------------
kenjiArai 5:af9fa3d0731c 135
kenjiArai 5:af9fa3d0731c 136 //-------------------------------------------------------------------------------------------------
kenjiArai 5:af9fa3d0731c 137 // Control Program
kenjiArai 5:af9fa3d0731c 138 //-------------------------------------------------------------------------------------------------
kenjiArai 5:af9fa3d0731c 139 #if defined(TARGET_LPC1768)
kenjiArai 7:0c09d29c4cf3 140
mio 1:2a347c40b1da 141 // Clock Output From pin21(PWM6)
mio 1:2a347c40b1da 142 // Set Clock Freq with div.
mio 1:2a347c40b1da 143 // if mbed is running at 96MHz, div is set 96 to Get 1MHz.
mio 1:2a347c40b1da 144 void PWM6_SETCLK(int div)
mio 1:2a347c40b1da 145 {
kenjiArai 5:af9fa3d0731c 146 LPC_PWM1->TCR = (1 << 1); // 1)Reset counter, disable PWM
kenjiArai 5:af9fa3d0731c 147 LPC_SC->PCLKSEL0 &= ~(0x3 << 12);
kenjiArai 5:af9fa3d0731c 148 LPC_SC->PCLKSEL0 |= (1 << 12); // 2)Set peripheral clock divider to /1, i.e. system clock
kenjiArai 5:af9fa3d0731c 149 LPC_PWM1->MR0 = div - 1; // 3)Match Register 0 is shared period counter for all PWM1
kenjiArai 5:af9fa3d0731c 150 LPC_PWM1->MR6 = (div + 1)>> 1; //
kenjiArai 5:af9fa3d0731c 151 LPC_PWM1->LER |= 1; // 4)Start updating at next period start
kenjiArai 5:af9fa3d0731c 152 LPC_PWM1->TCR = (1 << 0) || (1 << 3); // 5)Enable counter and PWM
kenjiArai 5:af9fa3d0731c 153 }
kenjiArai 7:0c09d29c4cf3 154
kenjiArai 7:0c09d29c4cf3 155 #elif defined(TARGET_LPC1114)
kenjiArai 7:0c09d29c4cf3 156
kenjiArai 7:0c09d29c4cf3 157 // CLOCKOUT from pin24(dp18)
kenjiArai 7:0c09d29c4cf3 158 // Freq = 48MHz/4 = 12MHz
kenjiArai 7:0c09d29c4cf3 159 void clock_out(void)
kenjiArai 7:0c09d29c4cf3 160 {
kenjiArai 7:0c09d29c4cf3 161 LPC_SYSCON->CLKOUTCLKSEL = 3; // System clock
kenjiArai 7:0c09d29c4cf3 162 LPC_SYSCON->CLKOUTDIV = 4; // div 1/4
kenjiArai 7:0c09d29c4cf3 163 LPC_IOCON->PIO0_1 = 1; // select CLKOUT to P0_1(pin24)/dp18
kenjiArai 7:0c09d29c4cf3 164 LPC_SYSCON->CLKOUTUEN = 1; // enable output
kenjiArai 7:0c09d29c4cf3 165 }
kenjiArai 7:0c09d29c4cf3 166
kenjiArai 6:44c2bcbdd77b 167 #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
kenjiArai 7:0c09d29c4cf3 168
kenjiArai 6:44c2bcbdd77b 169 void port_mco1_mco2_set(void)
kenjiArai 6:44c2bcbdd77b 170 {
kenjiArai 6:44c2bcbdd77b 171 uint32_t temp = 0x00;
kenjiArai 6:44c2bcbdd77b 172
kenjiArai 6:44c2bcbdd77b 173 // PA8 -> MCO_1
kenjiArai 6:44c2bcbdd77b 174 temp = ((uint32_t)(GPIO_AF0_MCO) << (((uint32_t)8 & (uint32_t)0x07) * 4)) ;
kenjiArai 6:44c2bcbdd77b 175 GPIOA->AFR[8 >> 3] &= ~((uint32_t)0xf << ((uint32_t)(8 & (uint32_t)0x07) * 4)) ;
kenjiArai 6:44c2bcbdd77b 176 GPIOA->AFR[8 >> 3] |= temp;
kenjiArai 6:44c2bcbdd77b 177 GPIOA->MODER &= ~(GPIO_MODER_MODER0 << (8 * 2));
kenjiArai 6:44c2bcbdd77b 178 GPIOA->MODER |= (0x2 << (8 * 2));
kenjiArai 6:44c2bcbdd77b 179 // PC9 -> MCO_2
kenjiArai 6:44c2bcbdd77b 180 temp = ((uint32_t)(GPIO_AF0_MCO) << (((uint32_t)9 & (uint32_t)0x07) * 4)) ;
kenjiArai 6:44c2bcbdd77b 181 GPIOC->AFR[9 >> 3] &= ~((uint32_t)0xf << ((uint32_t)(9 & (uint32_t)0x07) * 4)) ;
kenjiArai 6:44c2bcbdd77b 182 GPIOC->AFR[9 >> 3] |= temp;
kenjiArai 6:44c2bcbdd77b 183 GPIOC->MODER &= ~(GPIO_MODER_MODER0 << (9 * 2));
kenjiArai 6:44c2bcbdd77b 184 GPIOC->MODER |= (0x2 << (9 * 2));
kenjiArai 6:44c2bcbdd77b 185 // Select output clock source
kenjiArai 6:44c2bcbdd77b 186 RCC->CFGR &= 0x009fffff;
kenjiArai 6:44c2bcbdd77b 187 // MC0_1 output HSE 1/4, MCO_2 output SYSCLK 1/4
kenjiArai 6:44c2bcbdd77b 188 // MCO2 MCO2PRE MCO1PRE MCO1
kenjiArai 6:44c2bcbdd77b 189 RCC->CFGR |= (0x0 << 30) + (0x6 << 27) + (0x6 << 24) + (0x3 << 22);
kenjiArai 6:44c2bcbdd77b 190 }
kenjiArai 7:0c09d29c4cf3 191
kenjiArai 5:af9fa3d0731c 192 #else
kenjiArai 5:af9fa3d0731c 193 #error "No support for this CPU"
kenjiArai 5:af9fa3d0731c 194 #endif
kenjiArai 5:af9fa3d0731c 195
kenjiArai 5:af9fa3d0731c 196 void read_sw_and_set_gate_time(void)
kenjiArai 5:af9fa3d0731c 197 {
kenjiArai 5:af9fa3d0731c 198 if (sw_10) {
kenjiArai 5:af9fa3d0731c 199 led_10 = 1;
kenjiArai 5:af9fa3d0731c 200 sw = 2;
kenjiArai 5:af9fa3d0731c 201 } else {
kenjiArai 5:af9fa3d0731c 202 led_10 = 0;
kenjiArai 5:af9fa3d0731c 203 sw = 0;
kenjiArai 5:af9fa3d0731c 204 }
kenjiArai 5:af9fa3d0731c 205 if (sw_01) {
kenjiArai 5:af9fa3d0731c 206 led_01 = 1;
kenjiArai 5:af9fa3d0731c 207 sw += 1;
kenjiArai 5:af9fa3d0731c 208 } else {
kenjiArai 5:af9fa3d0731c 209 led_01 = 0;
kenjiArai 5:af9fa3d0731c 210 }
kenjiArai 5:af9fa3d0731c 211 switch (sw) {
kenjiArai 5:af9fa3d0731c 212 case 0:
kenjiArai 5:af9fa3d0731c 213 t_gate = 0.001;
kenjiArai 5:af9fa3d0731c 214 break;
kenjiArai 5:af9fa3d0731c 215 case 1:
kenjiArai 5:af9fa3d0731c 216 t_gate = 0.01;
kenjiArai 5:af9fa3d0731c 217 break;
kenjiArai 5:af9fa3d0731c 218 case 2:
kenjiArai 5:af9fa3d0731c 219 t_gate = 0.1;
kenjiArai 5:af9fa3d0731c 220 break;
kenjiArai 5:af9fa3d0731c 221 case 3:
kenjiArai 5:af9fa3d0731c 222 default:
kenjiArai 5:af9fa3d0731c 223 t_gate = 1.0;
kenjiArai 5:af9fa3d0731c 224 break;
kenjiArai 5:af9fa3d0731c 225 }
mio 1:2a347c40b1da 226 }
mio 0:c988614df67a 227
kenjiArai 5:af9fa3d0731c 228 int main()
kenjiArai 5:af9fa3d0731c 229 {
kenjiArai 6:44c2bcbdd77b 230 PRINTF("\r\nFrequency Counter by JH1PJL created on "__DATE__"\r\n");
kenjiArai 5:af9fa3d0731c 231 t_gate = 1.0;
kenjiArai 5:af9fa3d0731c 232 // Initialize LCD
kenjiArai 6:44c2bcbdd77b 233 #if defined(USE_TEXT_LCD)
kenjiArai 5:af9fa3d0731c 234 lcd.locate(0, 0); // 1st line top
kenjiArai 5:af9fa3d0731c 235 // 12345678
kenjiArai 5:af9fa3d0731c 236 lcd.printf("Fre-Cntr");
kenjiArai 5:af9fa3d0731c 237 lcd.locate(0, 1); // 2nd line top
kenjiArai 5:af9fa3d0731c 238 // 12345678
kenjiArai 5:af9fa3d0731c 239 lcd.puts(" JH1PJL ");
kenjiArai 5:af9fa3d0731c 240 lcd.setContrast(0x16);
kenjiArai 6:44c2bcbdd77b 241 #endif
kenjiArai 6:44c2bcbdd77b 242 #if defined(USE_GRAP_LCD)
kenjiArai 6:44c2bcbdd77b 243 glcd.cls();
kenjiArai 6:44c2bcbdd77b 244 glcd.locate(0, 0);
kenjiArai 6:44c2bcbdd77b 245 glcd.printf("--- Frequency Counter --\r\n");
kenjiArai 6:44c2bcbdd77b 246 glcd.printf(" Kenji Arai / JH1PJL\r\n" );
kenjiArai 6:44c2bcbdd77b 247 glcd.printf(" \r\n");
kenjiArai 6:44c2bcbdd77b 248 #if defined(TARGET_LPC1768)
kenjiArai 7:0c09d29c4cf3 249 glcd.set_contrast(0x06);
kenjiArai 6:44c2bcbdd77b 250 glcd.printf(" Input: P30 PWM out: P21\r\n" );
kenjiArai 6:44c2bcbdd77b 251 glcd.printf(" LED1:Gate LED2:signal \r\n" );
kenjiArai 7:0c09d29c4cf3 252 #elif defined(TARGET_LPC1114)
kenjiArai 7:0c09d29c4cf3 253 glcd.set_contrast(0x01);
kenjiArai 7:0c09d29c4cf3 254 glcd.printf(" LED2:Gate " );
kenjiArai 6:44c2bcbdd77b 255 #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
kenjiArai 7:0c09d29c4cf3 256 glcd.set_contrast(0x06);
kenjiArai 6:44c2bcbdd77b 257 glcd.printf(" Input: PA0 PWM out: PA8\r\n" );
kenjiArai 6:44c2bcbdd77b 258 glcd.printf(" LED1:Gate \r\n" );
kenjiArai 6:44c2bcbdd77b 259 #else
kenjiArai 6:44c2bcbdd77b 260 #error "No support for this CPU"
kenjiArai 6:44c2bcbdd77b 261 #endif
kenjiArai 6:44c2bcbdd77b 262 #endif // defined(USE_GRAP_LCD)
kenjiArai 6:44c2bcbdd77b 263 #if defined(USE_TEXT_LCD)
kenjiArai 5:af9fa3d0731c 264 wait(5.0);
kenjiArai 5:af9fa3d0731c 265 lcd.locate(0, 1); // 2nd line top
kenjiArai 5:af9fa3d0731c 266 // 12345678
kenjiArai 5:af9fa3d0731c 267 lcd.puts(" ");
kenjiArai 6:44c2bcbdd77b 268 #endif
kenjiArai 7:0c09d29c4cf3 269 // Set Internalclock for reference
kenjiArai 7:0c09d29c4cf3 270 CLK_REFRENCE();
kenjiArai 5:af9fa3d0731c 271 freqency = 0;
kenjiArai 5:af9fa3d0731c 272 while(true) {
kenjiArai 5:af9fa3d0731c 273 led_gate = 1;
kenjiArai 5:af9fa3d0731c 274 freqency = (float)fc.read_frequency(t_gate);
kenjiArai 5:af9fa3d0731c 275 led_gate = 0;
kenjiArai 5:af9fa3d0731c 276 wait(1.1 - t_gate);
kenjiArai 5:af9fa3d0731c 277 if (freqency == 0) {
kenjiArai 5:af9fa3d0731c 278 led_not_zero = 1;
kenjiArai 5:af9fa3d0731c 279 } else {
kenjiArai 5:af9fa3d0731c 280 led_not_zero = 0;
kenjiArai 5:af9fa3d0731c 281 }
kenjiArai 5:af9fa3d0731c 282 read_sw_and_set_gate_time();
kenjiArai 6:44c2bcbdd77b 283 PRINTF("f= %9.0f [Hz], gate= %4.3f [Sec]\r\n", freqency/t_gate, t_gate);
kenjiArai 6:44c2bcbdd77b 284 #if defined(USE_TEXT_LCD)
kenjiArai 5:af9fa3d0731c 285 lcd.locate(0, 0); // 1st line top
kenjiArai 5:af9fa3d0731c 286 lcd.printf("%8.0f", freqency);
kenjiArai 5:af9fa3d0731c 287 lcd.locate(0, 1); // 2nd line top
kenjiArai 6:44c2bcbdd77b 288 #endif
kenjiArai 6:44c2bcbdd77b 289 #if defined(USE_GRAP_LCD)
kenjiArai 6:44c2bcbdd77b 290 glcd.locate(0, 10);
kenjiArai 6:44c2bcbdd77b 291 glcd.printf(" \r\n");
kenjiArai 6:44c2bcbdd77b 292 glcd.locate(10, 10);
kenjiArai 6:44c2bcbdd77b 293 glcd.printf("%8.0f Hz", freqency);
kenjiArai 6:44c2bcbdd77b 294 glcd.locate(10, 20);
kenjiArai 6:44c2bcbdd77b 295 #endif
kenjiArai 5:af9fa3d0731c 296 switch (sw) {
kenjiArai 5:af9fa3d0731c 297 case 0:
kenjiArai 6:44c2bcbdd77b 298 #if defined(USE_TEXT_LCD)
kenjiArai 5:af9fa3d0731c 299 // 12345678
kenjiArai 5:af9fa3d0731c 300 lcd.printf("x1000 Hz");
kenjiArai 6:44c2bcbdd77b 301 #endif
kenjiArai 6:44c2bcbdd77b 302 #if defined(USE_GRAP_LCD)
kenjiArai 6:44c2bcbdd77b 303 glcd.printf(" x1000 ");
kenjiArai 6:44c2bcbdd77b 304 #endif
kenjiArai 5:af9fa3d0731c 305 break;
kenjiArai 5:af9fa3d0731c 306 case 1:
kenjiArai 6:44c2bcbdd77b 307 #if defined(USE_TEXT_LCD)
kenjiArai 5:af9fa3d0731c 308 // 12345678
kenjiArai 5:af9fa3d0731c 309 lcd.printf("x100 Hz");
kenjiArai 6:44c2bcbdd77b 310 #endif
kenjiArai 6:44c2bcbdd77b 311 #if defined(USE_GRAP_LCD)
kenjiArai 6:44c2bcbdd77b 312 glcd.printf(" x100 ");
kenjiArai 6:44c2bcbdd77b 313 #endif
kenjiArai 5:af9fa3d0731c 314 break;
kenjiArai 5:af9fa3d0731c 315 case 2:
kenjiArai 6:44c2bcbdd77b 316 #if defined(USE_TEXT_LCD)
kenjiArai 5:af9fa3d0731c 317 // 12345678
kenjiArai 5:af9fa3d0731c 318 lcd.printf("x10 Hz");
kenjiArai 6:44c2bcbdd77b 319 #endif
kenjiArai 6:44c2bcbdd77b 320 #if defined(USE_GRAP_LCD)
kenjiArai 6:44c2bcbdd77b 321 glcd.printf("x10 ");
kenjiArai 6:44c2bcbdd77b 322 #endif
kenjiArai 5:af9fa3d0731c 323 break;
kenjiArai 5:af9fa3d0731c 324 case 3:
kenjiArai 5:af9fa3d0731c 325 default:
kenjiArai 6:44c2bcbdd77b 326 #if defined(USE_TEXT_LCD)
kenjiArai 5:af9fa3d0731c 327 // 12345678
kenjiArai 5:af9fa3d0731c 328 lcd.printf("x1 Hz");
kenjiArai 6:44c2bcbdd77b 329 #endif
kenjiArai 6:44c2bcbdd77b 330 #if defined(USE_GRAP_LCD)
kenjiArai 6:44c2bcbdd77b 331 glcd.printf(" x1 ");
kenjiArai 6:44c2bcbdd77b 332 #endif
kenjiArai 5:af9fa3d0731c 333 break;
kenjiArai 5:af9fa3d0731c 334 }
mio 1:2a347c40b1da 335 }
mio 1:2a347c40b1da 336 }