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@8:7b033903c8fb, 2014-11-22 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat Nov 22 23:09:17 2014 +0000
- Revision:
- 8:7b033903c8fb
- Parent:
- 7:0c09d29c4cf3
- Child:
- 9:e98e94ba17f9
Target is accurate frequency counter using GPS 1PPS compensation function. Separated the frequency counter library. This is only for ST Nucleo F411RE mbed board.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 5:af9fa3d0731c | 1 | /* |
kenjiArai | 8:7b033903c8fb | 2 | * mbed Application program / Frequency Counter with GPS 1PPS Compensation |
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 | 8:7b033903c8fb | 8 | * Revised: Nobember 23rd, 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 | |
kenjiArai | 5:af9fa3d0731c | 19 | // Include --------------------------------------------------------------------------------------- |
mio | 0:c988614df67a | 20 | #include "mbed.h" |
kenjiArai | 8:7b033903c8fb | 21 | #include "frq_cuntr_full.h" |
kenjiArai | 8:7b033903c8fb | 22 | |
kenjiArai | 8:7b033903c8fb | 23 | using namespace Frequency_counter; |
mio | 0:c988614df67a | 24 | |
kenjiArai | 5:af9fa3d0731c | 25 | // Definition ------------------------------------------------------------------------------------ |
kenjiArai | 5:af9fa3d0731c | 26 | #ifdef USE_COM |
kenjiArai | 5:af9fa3d0731c | 27 | #define BAUD(x) pc.baud(x) |
kenjiArai | 5:af9fa3d0731c | 28 | #define GETC(x) pc.getc(x) |
kenjiArai | 5:af9fa3d0731c | 29 | #define PUTC(x) pc.putc(x) |
kenjiArai | 5:af9fa3d0731c | 30 | #define PRINTF(...) pc.printf(__VA_ARGS__) |
kenjiArai | 5:af9fa3d0731c | 31 | #define READABLE(x) pc.readable(x) |
kenjiArai | 5:af9fa3d0731c | 32 | #else |
kenjiArai | 5:af9fa3d0731c | 33 | #define BAUD(x) {;} |
kenjiArai | 5:af9fa3d0731c | 34 | #define GETC(x) {;} |
kenjiArai | 5:af9fa3d0731c | 35 | #define PUTC(x) {;} |
kenjiArai | 5:af9fa3d0731c | 36 | #define PRINTF(...) {;} |
kenjiArai | 5:af9fa3d0731c | 37 | #define READABLE(x) {;} |
kenjiArai | 5:af9fa3d0731c | 38 | #endif |
mio | 1:2a347c40b1da | 39 | |
kenjiArai | 5:af9fa3d0731c | 40 | // Object ---------------------------------------------------------------------------------------- |
kenjiArai | 8:7b033903c8fb | 41 | //DigitalOut led_gate(LED1); |
kenjiArai | 8:7b033903c8fb | 42 | DigitalIn sw_01(PC_0); |
kenjiArai | 8:7b033903c8fb | 43 | DigitalIn sw_10(PC_1); |
kenjiArai | 8:7b033903c8fb | 44 | Serial pc(USBTX, USBRX); |
kenjiArai | 8:7b033903c8fb | 45 | I2C i2cBus(PB_9,PB_8); // SDA, SCL |
kenjiArai | 8:7b033903c8fb | 46 | // PC_6,PC_7 & PB6 use for Timer3 & 4 |
kenjiArai | 8:7b033903c8fb | 47 | // PA_0,PA_1 & PB_10 use for Timer2 |
kenjiArai | 8:7b033903c8fb | 48 | FRQ_CUNTR fc(PC_6, 1.0); // Input port & gate time[sec] |
kenjiArai | 6:44c2bcbdd77b | 49 | |
kenjiArai | 5:af9fa3d0731c | 50 | // RAM ------------------------------------------------------------------------------------------- |
kenjiArai | 6:44c2bcbdd77b | 51 | |
kenjiArai | 5:af9fa3d0731c | 52 | // ROM / Constant data --------------------------------------------------------------------------- |
mio | 1:2a347c40b1da | 53 | |
kenjiArai | 5:af9fa3d0731c | 54 | // Function prototypes --------------------------------------------------------------------------- |
kenjiArai | 5:af9fa3d0731c | 55 | |
kenjiArai | 5:af9fa3d0731c | 56 | // Function prototypes --------------------------------------------------------------------------- |
kenjiArai | 5:af9fa3d0731c | 57 | |
kenjiArai | 5:af9fa3d0731c | 58 | //------------------------------------------------------------------------------------------------- |
kenjiArai | 5:af9fa3d0731c | 59 | // Control Program |
kenjiArai | 5:af9fa3d0731c | 60 | //------------------------------------------------------------------------------------------------- |
kenjiArai | 5:af9fa3d0731c | 61 | int main() |
kenjiArai | 5:af9fa3d0731c | 62 | { |
kenjiArai | 8:7b033903c8fb | 63 | uint32_t counter_1pps = 0; |
kenjiArai | 8:7b033903c8fb | 64 | uint32_t new_frequency = 0; |
kenjiArai | 8:7b033903c8fb | 65 | |
kenjiArai | 8:7b033903c8fb | 66 | BAUD(9600); |
kenjiArai | 8:7b033903c8fb | 67 | // PA8 & PC9 uses for MCO_1 & MCO_2 -> Clock output for checking |
kenjiArai | 8:7b033903c8fb | 68 | fc.port_mco1_mco2_set(2); // Clk/2 ->1/1(100MHz) cannot measure!! |
kenjiArai | 8:7b033903c8fb | 69 | wait(1.0); |
kenjiArai | 8:7b033903c8fb | 70 | fc.read_frequency_TIM2(1.0); |
kenjiArai | 8:7b033903c8fb | 71 | fc.read_frequency_TIM3P4(1.0); |
kenjiArai | 6:44c2bcbdd77b | 72 | PRINTF("\r\nFrequency Counter by JH1PJL created on "__DATE__"\r\n"); |
kenjiArai | 5:af9fa3d0731c | 73 | while(true) { |
kenjiArai | 8:7b033903c8fb | 74 | while (fc.status_1pps() == 0) { |
kenjiArai | 8:7b033903c8fb | 75 | ; |
kenjiArai | 5:af9fa3d0731c | 76 | } |
kenjiArai | 8:7b033903c8fb | 77 | counter_1pps = fc.read_avarage_1pps(); |
kenjiArai | 8:7b033903c8fb | 78 | while (fc.status_freq_update() == 0) { |
kenjiArai | 8:7b033903c8fb | 79 | ; |
kenjiArai | 5:af9fa3d0731c | 80 | } |
kenjiArai | 8:7b033903c8fb | 81 | new_frequency = fc.read_freq_data(); |
kenjiArai | 8:7b033903c8fb | 82 | PRINTF("1PPS/ave = %9d , FREQUENCY = %9d\r\n", counter_1pps, new_frequency); |
mio | 1:2a347c40b1da | 83 | } |
mio | 1:2a347c40b1da | 84 | } |