DIY Projects

Build a Pocket Signal Generator With the AVR16EB28 and an OLED

Build a Pocket Signal Generator With the AVR16EB28 and an OLED

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 128×64 I2C OLED on SDA and SCL will stand in for the display.

Frequently Asked Questions

What frequency range does this AVR signal generator cover?

It produces square waves from 2 Hz up to 33,554,430 Hz, selectable anywhere in that range in 2 Hz steps. Timing comes from a 4.194304 MHz crystal rated at 20 ppm, and you enter the frequency either on the keypad or with the rotary encoder.

Why does it need that Event System oscillator trick instead of a normal crystal?

The newer AVR EB series does not support an external high-frequency crystal the way older AVRs did. Instead of adding an oscillator IC, PC3 is configured as an inverted input and PC2 as an event output, linked by an internal event channel, with the crystal between them and PC2 fed back into EXTCLK. TTL input mode with a 1 megohm feedback resistor and two 18 pF load capacitors gave the most stable result.

What will I learn if I build this?

You get hands-on practice with crystal oscillator design and load capacitor selection, the AVR Event System for routing signals between peripherals without CPU involvement, I2C OLED drivers, rotary encoder decoding with a push-switch mode change, and UPDI programming through DxCore. You also end up owning a piece of test gear, which makes every project after this one easier to debug.

This article was inspired by reporting from Hackster. Find the parts and modules to build it at Circuitrocks.

// written by Ann Arandia

Ann Arandia covers community projects and maker events for the Circuitrocks blog. She writes about local workshops, kid-friendly electronics, and the Philippine maker scene — the people, the meet-ups, the projects that come out of them.