Up until now I had been using a small kit from maplins to generate waveforms. While that was digital and quite accurate, it had a lack of proper controls and was a small device which had a tendency to clutter up the desk. What I needed was a dedicated rack unit.
It had one major drawback; it had no display. Now you could use your multimeter (if it has a frequency counter builtin), but I only have one and I was trying to avoid desk clutter, not create more. So I decided to design and build a small 1U modular frequency counter. I could use an Arduino Uno to calculate the frequency and a few 4051 multiplexer ICs to help display it on an LED display.
The function generator from the ebay listing. |
Requirements
- A single input (for the function generator signal)
- At least 1 output (to allow daisy-chaining with other devices)
- A display of some kind to show the frequency being sent to the input
- The display should have the ability to show commas or have enough digits to display 20MHz (the top limit of my function generator)
- Fit within the physical footprint (width/length) of the function generator (250mm x200mm)
- Use a micro-controller to calculate the frequency from the input and multiplex the display to the output.
- The PCB should support in-system programming (ISP).
Design
Now the Arduino Uno is a great development board for quick prototypes but ideally you want to create your own circuit layouts to host the Arduino Uno's microcontroller (Atmega 328P). You can get tips on how to do this by examining the Arduino Uno schematic itself. Note the 16MHz crystal (Y2 off Pins 9 and 10) is required by the Atmega (in default config).It is also worth noting that the Atmega328 only has 18 output pins, and I would need 24 just for the 8 digit LED display as well as two inputs for the frequency counter function itself. Therefore not only would I need to multiplex the display signal (plotting one digit segment at a time), I would also need further reduce the number of overall pins. To do this I used three CMOS 4051 8:1 digital switches. One 4051 for the 4 digit inhibit pins for both displays and two 4051's for the 8 segments on each display.
This is a top down and front panel view of the design. The main board (MB) would contain the power regulation, the Atmega328P MCU and the multiplexer IC chips.
Since I was panel mounting the LED display I decided to put that on a second "daughter" board (DB) and run connectors to it from the main board.
On the left of the front panel is an on/off switch. I originally planned to have two inputs and two outputs (for BNC and banana connectors) but I decided this was probably overkill, and later reduced this to only 1 input/2 outputs.
Schematic
This is the result of the breadboard development. Note, that some of the LED display molex connectors shown were omitted from the final design - due to space constraints. In this case, the wires were soldered directly to the display board.Software
You can find the source code for the frequency counter on GitHub here.Some things to note:
- I wrote the LED display multiplex code from scratch as it was relatively simple. The code uses arrays of binary literals to store and iterate the 4051 switching truth table and the segment display data for each character (0-9). A single function enables and disables each digit in reverse order, during which each segment for the required character is illuminated. The modulus operator is used to take the least significant digit from the number to be display.
- I used existing FreqCount and FreqMeasure libraries for the frequency calculation. Whilst it is not difficult to write your own code - I did spend some time experimenting with the Atmega timers, interrupts and compare/capture registers for my own curiosity - the aforementioned libraries have been around for some time and are well-tested. To get to the point where my own code was suitably mature and bug-free would have added more development time, and quite frankly would have not served any real advantage.
- Since the FreqCount and FreqMeasure libraries have limitations at particular frequencies I switch between them at the 10KHz point. To avoid conflict, you must call the end() function to disable one library before enabling the other. A software reset of the device is not required.
Layout
Etching
The layout was printed with an inkjet onto glossy paper and transferred onto the copper clad FR4 board with an iron. I etched away the exposed copper with ferric chloride.The ink layer mask was then scrubbed away and the holes were drilled.
After removing the protective mask layer |
Construction
I used these KK254 molex connectors to avoid soldering wires directly into the board. This reduces stress fatigue on solder joints over time, makes it easier to debug connections and correct mistakes. I've also found that its much easier to service the whole assembly when you can unplug all the peripherals from the main board. There are three connectors on the left are for the display signals (one for each corresponding 4051 IC) and a fourth at the bottom-right to allow in-circuit programming of the Atmega IC. The smaller ones are for the panel mount power switch and BNC sockets.At this point I stopped to test if LM4805 was regulating the 9VDC down to 5VDC | correctly |
Display daughter board test success! |
Mainboard mounted into the chasis |
Display board and other sockets mounted |
Pending some minor cosmetic changes at the front, the finished result! |
Comparing the reading with the Extech DMM |
Comments
Post a Comment