Questions with regards to ESP8266 Basic and hardware interfacing and control via Basic commands

Moderator: Mmiscool

User avatar
By aphawk
#59971 Hi,

I'm trying to use one Storm detection module, but for the calibration procedure I must measure frequency about 31250 Hz with a good precision ( 1% is ok ).

Any ideas to make this with EspBasic ?

Thanks !

Paulo
User avatar
By PhilTilson
#60027 Assuming you have a reasonably 'digital' input waveform, I would think you could simply start a timer, count, say, 10000 input pulses, stop the timer and then perform simple arithmetic to get the frequency from that. Using, say, IO pin 5 as the input, something like:

Code: Select alldim start
dim stop
dim count
dim freq

start=millis()
do
   do
   loop until io(pi,5)=0
   count=count+1
   do
   loop until io(pi,5)=1
loop until count=10000

stop = millis()
freq=10000/(stop-start)

This should give the frequency in KHz with at least 1% accuracy - assuming the ESP clock is accurate!

Phil
User avatar
By aphawk
#60037 Phill,

The problem is assure that I have one exact millisecond.

The command you have posted catch the milissecond, but not at its start. I can get the 1.0000 millicond, but I can get the 1.7456 millisecond too !

I need the exact time of 1 millisecond to make the calculation without error.

Paulo
User avatar
By heckler
#60043 aphawk,

Without analyzing your exact needs in detail I would suggest you might want to consider offloading this task of accurately measuring frequency for calibration to a separate small 6-8 pin microcontroller.

My experience with this awesome espbasic (and it is awesome) is that it MAY not be ideal for some types of functions where you might need accurate frequency or timing.

For example I don't know what the temperature stability of the inbuilt clock is on various espmodules and the overhead of the OS may make it difficult to calibrate a routine to measure frequency.

Do you have an Oscilliscope?? that is a very useful tool when dealing with frequency of a given signal.

dwight