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.
Dependencies: MCP23017 SDFileSystem USBDevice WattBob_TextLCD mbed
FreqMesure.h
00001 /*************************************************************************************** 00002 Measure the frequency of a 3.3v square wave signal once every second. The frequency range 00003 is 500Hz to 1000Hz with 50% duty cycle). In this code the on complet cycle is peiod is 00004 masured after detcting the edge also a timeout timer is seting to detect open loop. 00005 *****************************************************************************************/ 00006 00007 void FreqMsur(){ 00008 FreqMsurPin = ! (FreqMsurPin); //Pin 23 00009 FreqTimeOut.start(); 00010 // Ignore first part of the signal to detect the edge 00011 if(!FrequencyIn){ 00012 while(!FrequencyIn){ 00013 if (FreqTimeOut.read_ms() > 3) 00014 break; 00015 } 00016 } 00017 else{ 00018 while(FrequencyIn){ 00019 if (FreqTimeOut.read_ms() > 3) 00020 break; 00021 } 00022 } 00023 //This is the begining of the edge start the timer to masure 00024 FreqMsurT.start(); 00025 if (FreqTimeOut.read_ms() > 3){ 00026 FreqTimeOutHpn=1; 00027 } 00028 else{ 00029 FreqTimeOutHpn=0; 00030 } 00031 FreqTimeOut.stop(); 00032 FreqTimeOut.reset(); 00033 if(!FreqTimeOutHpn){ 00034 if(!FrequencyIn){ 00035 while(!FrequencyIn){ 00036 } 00037 while(FrequencyIn){ 00038 } 00039 } 00040 else{ 00041 while(FrequencyIn){ 00042 } 00043 while(!FrequencyIn){ 00044 } 00045 } 00046 FreqMsurT.stop(); 00047 float Period=FreqMsurT.read_us(); 00048 Freq=1/Period*1000000.0+0.5; //Adding 0.5 to round the frequency to nearst int 00049 } 00050 else{ 00051 Freq=0xffff; 00052 } 00053 FreqTimeOut.stop(); 00054 FreqMsurT.reset(); 00055 //FreqMsurPin = ! (FreqMsurPin); 00056 }
Generated on Tue Jul 12 2022 21:34:48 by
