Your parts list here is short: an AVR16EB28 in an SSOP package, a 4.194304 MHz crystal, a small OLED, a keypad, a rotary encoder, a 3.3 V regulator, and a 150 mAh LiPo if you want it running away from a wall socket. David Johnson-Davies fit all of that onto one PCB and got back a square-wave source that covers 2 Hz to 33,554,430 Hz in exact 2 Hz steps.
What the thing actually does
You key a frequency straight in, up to eight digits in hertz, and the display answers with the closest frequency the chip can really produce. The rotary encoder handles fine adjustment at 2 Hz per detent. Push the encoder shaft and the step size jumps to 1,000 Hz, which saves a few hundred clicks when you are travelling from audio range up toward RF. An earlier version of this generator lived on a breadboard around an AVR32EB28. This one has its own board with a power switch, so it goes in a bag instead of staying pinned to the bench.
The crystal trick worth stealing
Newer AVR parts dropped the external high-frequency crystal support that the older chips had, which is awkward when your whole selling point is 20 ppm accuracy. Rather than adding a separate oscillator IC, Johnson-Davies made the microcontroller build its own oscillator out of two spare pins. PC3 is set up as an inverted input, PC2 as an event output, and an internal Event System channel links them. The crystal is wired externally between the two pins, and PC2 loops back into the EXTCLK input.
Getting it stable took some bench time. He compared Schmitt trigger against TTL input modes and tried several feedback resistor and load capacitor pairings before settling on TTL mode with a 1 megohm feedback resistor and two 18 pF load capacitors. The firmware is nearly the same as the breadboard version, with new code only for the encoder push switch. It compiles under Spence Konde's DxCore Arduino core and flashes to the AVR16EB28 over UPDI.
Worth a slot on a student bench
Most school labs own one function generator and have twenty students queueing behind it. A square-wave source you soldered yourself covers a lot of what a digital design or embedded class actually asks for: clocking a shift register, feeding a timer capture input, sweeping an RC filter to find its corner frequency. Build notes, schematic and firmware are all in the write-up at Hackster. If you want to prototype before committing to a PCB, an AVR32EB28 on a breadboard runs the same code, and any 128x64 I2C OLED on SDA and SCL will stand in for the display.
Originally published on blog.circuit.rocks.
Top comments (0)