SX based 15 MHz frequency counter.
( by Alberto Geraci of BTX Sistemas Argentina )
This is a simple frequency counter project based in a SX28 microcontroller from Ubicom. It doesn't try to be an exact instrument measurement, only try to demonstrate, with a very low cost and low quantity of materials, ( only two ICs ) how much we could get from an SX28 plus the RS232 serial port in a PC.
Let me to leave to the people who read this article to experiment with it, make some changes, or apply new ideas. If you like you could write to me at btxsistemas@ciudad.com.ar .
In this article, you have the complete schematic diagram for the frequency counter, the Windows software and installer, a picture with the software in action, and all source code, including the SX assembly code and the PC Visual Foxpro 6.0 code. {ed: in the install directory }
The project is in a basis of two parts, one is the SX code which implement all frequency count, and the RS232 serial communication.
The second part is the PC software that only reads the data sent by the SX and shows it in a window of a simulated standard frequency counter.
This lets the PC software to be not responsible about the maximum wave frequency to be tested, and leave to the SX code all the quickly job, taking advantage of the 50 MIPS.
I think that using a different external counter in this project, you could get much more than 15 MHz wide of band for the frequency counter.
About SX code:
The original idea to measure the external input frequency as quickly as possible with the SX28 in this project is the following:
The signal to be measured need to be an square wave ( you could do this with any schmitt trigger gate ) and it will be the clock for an external counter, that count how many input pulses receive during a exactly elapsed time.
This time, is the called "time base" of the frequency counter and its given by the SX software, like this instrument is totally auto-range, the SX software will take more than one measure to know exactly the value of the input frequency, giving in only 12 bits of resolution ( 12 bits external counter ) a complete result in 8 decimal digits in the display. ( PC software display ).
How to do this ?, Ok we will take first a 0.5 seconds ( time base ) value of the counter, and after that a 1/4096 seconds value, this two measures will give us, four byte of data to be send to the PC software.
And that is all we need, then the PC soft will make some calculation to get the decimal frequency value.
{ed: Here is the main part of the code. The rest is mostly delay routines and setup.}
begin setb rescount ; clr the counter call res_delay ; delay for the counter reset clrb rescount ; finish clr the counter. call half_sec ; let's the input freq to run the counter for 1/2 sec. mov data1p,rc ; mov to data1p variable, the content of rb register. mov data1s,ra ; mov to data1s variable, the content of ra register. setb rescount ; clr the counter call res_delay ; delay for the counter reset clrb rescount ; finish clr the counter. call short_time ; let's the input freq to run the counter for 1/4096 sec. mov data2p,rc ; mov to data2p variable, the content of rb register. mov data2s,ra ; mov to data2s variable, the content of ra register. ; at this point we finished to measure the input frequency. Now we'll send it to serial port. mov !option,#%10011111 ; for RS232 enable mov w,data1p call send_byte call send_delay and data1s,#%00001111 ; to avoid the undesired data at high niblle of port RA. mov w,data1s call send_byte call send_delay mov w,data2p call send_byte call send_delay and data2s,#%00001111 ; to avoid the undesired data at high niblle of port RA. mov w,data2s call send_byte call send_delay mov !option,#%11011111 ; for RS232 disable ; finished to sent the data to serial port, all begins again. mov data1p,#0 ; mov data1s,#0 ; mov data2p,#0 ; mov data2s,#0 ; jmp begin
OK at this point we have a lot of different possibilities to change or to add, I think the first and most important to get more speed, for measure higher frequencies, is the change of the external counter, in this project to demonstrate the work, I was using the 74HC4040 which have a 12 bits of resolution, so think about a 16 bits counter to get a 4.29 GHz (theoretical) or real= the maximum input clock frequency. of the counter.
You must use (change in SX soft) the entire rb and rc port to read all this 16 bits and let the ra.x bit to implement the serial communication.
About the PC software:
The PC software was entire programmed in Visual Fox 6.0, all the code is not available for you , the idea was to create an small window into a dialog based application, which shows you the frequency. measured with the hardware.
You can install the software by clicking only in the setup icon, be carefully to get installed and registered the Microsoft MSCOMM 6.0 control in your windows version, This software is only for windows application, you cant use it with another operating system. {ed: the installer is in Spanish, but most options are standard and easy to figure out. There is a point where there appears to only be buttons for changeing the install directory and canceling the install, but there is, in fact, another, larger, button above and to the left with a picture of a computer on it. Click on that to continue.)
When you start the software, you can see an rectangle window with a pict simulating the frequency counter, it has only two buttons to control it, one is the power button to close the software and the another is the COMX select button to choose which COM port to use.
COM1
COM2
Like we said before, the frequency counter is full auto range and you dont
need to make changes in the time base of it, this software will receive four
bytes of data every 0.6 seconds ( approximately ) and it will convert it
in a big decimal display to be read for you, in the case the hardware is
not connected the software will show the display as off; NO error is
advised.
The software language is only in English version to get Spanish version write to btxsistemas please.
OK Thats all folks, and I hope, that you enjoy it
Alberto Geraci
BTX Sistemas.
NOTE: YOU CAN USE THIS PROJECT ONLY FREE, FOR NON COMMERCIAL PURPOSES WITHOUT MY AUTHORIZATION.