Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: FreqCntr_GPS1PPS_F746F4xx_w_recipro Freq_Cntr_GPS1PPS_F746NG_GUI
Fork of Frq_cuntr_full by
fc_GPS1PPS.h
00001 /* 00002 * mbed Library / Frequency Counter using GPS 1PPS gate pulse 00003 * Frequency Counter program 00004 * Only for ST DISCO-F746NG and Nucleo-F411RE+F446RE 00005 * 00006 * Copyright (c) 2014,'15,'16 Kenji Arai / JH1PJL 00007 * http://www.page.sannet.ne.jp/kenjia/index.html 00008 * http://mbed.org/users/kenjiArai/ 00009 * Started: October 18th, 2014 00010 * Revised: January 1st, 2015 00011 * Re-started: June 25th, 2016 ported from F411 board 00012 * Re-started: October 5th, 2016 Change board -> DISCO-F746NG 00013 * Re-started: October 17th, 2016 Continue F746 and back to F411 00014 * Revised: November 13th, 2016 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00019 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00020 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 00021 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 00022 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 /* 00026 -------------------------------------------------------------------------------- 00027 ********* Frequency Counter Functions ********* 00028 Mesurement frequency: 1Hz to 100MHz 00029 Extended range: Up to 1GHz (1/10 prescaler) or more over (1/20) 00030 Gate time: 1 sec to 4095sec (extend to more if RAM is avairable) 00031 1 PPS: GPS receiver(u-blux7/NEO-7) with an external antenna 00032 Additional function: Reciprocal measurement (less tha 10KHz) 00033 00034 ********* Hardware Configration (Board is only ST DISCO-F746NG) ********* 00035 frequency input: PC_6(D1) & PB10(No assign to connector!) 00036 GPS 1PPS: PA_15(D9), PB_8(D15) & PC_7(D0) 00037 00038 ********* Hardware Configration (Board is only ST Nucleo-F411RE) ********* 00039 RESTRICTION -> Max input freqency is 48MHz due to system clock limitation 00040 frequency input: PA_8(D7) & PA_0(A0) 00041 GPS 1PPS: PA_9(D8), PB_0(A3) & PA_1(A1) 00042 -------------------------------------------------------------------------------- 00043 */ 00044 00045 #ifndef MBED_FRQ_CUNTR 00046 #define MBED_FRQ_CUNTR 00047 00048 #include "mbed.h" 00049 00050 #define DEBUG 0 // use Communication with PC(UART) 00051 00052 typedef union 00053 { 00054 struct { 00055 uint64_t f_1sec_dt; 00056 }; 00057 struct { 00058 uint32_t freq_dt; 00059 uint16_t f_sw_dt; 00060 uint16_t t_cnt; 00061 }; 00062 } freq_one; 00063 00064 namespace Frequency_counter 00065 { 00066 00067 /** Frequency Counter program 00068 * Only for ST DISCO-F746NG Board(Nucleo-F411RE & F446RE also) 00069 * 00070 * @code 00071 * #include "mbed.h" 00072 * #include "fc_GPS1PPS.h" 00073 * 00074 * using namespace Frequency_counter; 00075 * 00076 * //----F746---- max input f=100MHz 00077 * // frequency input -> PC_6 & PA15(for reciprocal) 00078 * // GPS 1PPS -> PB_8,PC_7 & PB_10(for reciprocal) 00079 * //----F411---- max input f=48MHz 00080 * //----F446---- max input f=90MHz 00081 * // frequency input -> PA_8 & PA_0(for reciprocal) 00082 * // GPS 1PPS -> PA_9, PB_0 & PA_1(for reciprocal) 00083 * 00084 * FRQ_CUNTR fc; 00085 * 00086 * int main() { 00087 * double frequency = 0; 00088 * while(true) { 00089 * while (fc.status_freq_update() == 0) {;} 00090 * frequency = fc.read_freq_data(); // 1sec gate 00091 * printf("FREQ. = %11.1f\r\n", frequency); 00092 * } 00093 * } 00094 * @endcode 00095 */ 00096 00097 class FRQ_CUNTR 00098 { 00099 00100 public: 00101 00102 /** Configure counter 00103 * @param none 00104 */ 00105 FRQ_CUNTR(void); 00106 00107 /** Read new frequency data (gate time = 1sec) 00108 * @param none 00109 * @return frequency data 00110 */ 00111 double read_freq_data(void); 00112 00113 /** Read new frequency data with specific gate time 00114 * @param gate time [sec] (1 sec to over 1 hour(F746) or 17 minutes) 00115 * @return frequency data 00116 */ 00117 double read_freq_w_gate_time(uint16_t gt); 00118 00119 /** Read status (new frequency data is available or not) 00120 * @param none 00121 * @return !=0: new data is avairable, 0: not yet 00122 */ 00123 uint32_t status_freq_update(void); 00124 00125 /** Reset buffered data 00126 * @param none 00127 * @return none 00128 */ 00129 void reset_buffered_data(void); 00130 00131 /** Reciprocal measurement (Step1) 00132 * preparation for Reciprocal measurement 00133 * @param none 00134 * @return none 00135 */ 00136 void recipro_start_measure(void); 00137 00138 /** Reciprocal measurement (Step2) 00139 * check frequency input as IC trigger 00140 * @param none 00141 * @return 1: done, 0: not yet 00142 */ 00143 uint32_t recipro_check_trigger(void); 00144 00145 /** Reciprocal measurement (Step3) 00146 * read period data 00147 * @param none 00148 * @return frequency data 00149 */ 00150 uint32_t recipro_read_data(void); 00151 00152 /** Reciprocal measurement (Step4) 00153 * read period data 00154 * @param gate time [sec] (1 sec to over 1 hour) 00155 * @return time base clock frequency data 00156 */ 00157 uint32_t recipro_base_clk_data(uint16_t gt); 00158 00159 /** "DEBUG PURPOSE" function 00160 * Check input frequency on TIM8+4 or TIM1+3 00161 * print internal data (need to define "DEBUG") 00162 * @param gate time e.g. 1sec = 1.0f 00163 * @return frequency data 00164 */ 00165 uint32_t debug_read_input_frequency(double gatetime); 00166 00167 /** "DEBUG PURPOSE" function 00168 * Check input frequency on TIM2 00169 * print internal data (need to define "DEBUG") 00170 * @param gate time e.g. 1sec = 1.0f 00171 * @return frequency data 00172 */ 00173 uint32_t debug_read_base_clock_frequency(double gatetime); 00174 00175 /** "DEBUG PURPOSE" function 00176 * print internal data (No need to define "DEBUG") 00177 * @param none 00178 * @return none (just print tha data) 00179 */ 00180 void debug_printf_all_buffer(void); 00181 00182 protected: 00183 void start_action(void); // Start trigger for reciprocal 00184 void initialize_TIMxPy(void); // Initialize Timer_x + _y (16+16bit) 00185 void initialize_TIMz(void); // Initialize Timer_z (32bit) 00186 uint64_t get_diff(uint64_t new_dt, uint64_t old_dt); 00187 00188 private: 00189 double newest_frequency; 00190 00191 }; 00192 00193 /* 00194 Interrupt handler does NOT work following code 00195 NVIC_SetVector(TIM4_IRQn, (uint32_t)FRQ_CUNTR::irq_ic_TIMxPy); 00196 From this reason, I wrote below code and set interrupt handler 00197 out side "FRQ_CUNTR" class 00198 NVIC_SetVector(TIM4_IRQn, (uint32_t)irq_ic_TIMxPy); 00199 */ 00200 void irq_ic_TIMxPy(void); // TIM4(F746) or TIM3(F411) IC Interrupt 00201 void irq_ic_TIMz(void); // TIM2(F746 & F411) IC Interrupt 00202 00203 } // Frequency_counter 00204 00205 #endif // MBED_FRQ_CUNTR
Generated on Thu Jul 14 2022 08:12:39 by
