One of my very first forays into programming microcontrollers came when I needed a square-wave generator. It was super simple, based on a Tiny25, only had sixteen discrete frequencies (each frequency was double the previous), and was housed in a rough wood container I made for it. Now, I’ve made something better.
An ATTiny25 still forms the core of it, but it’s a whole lot better. The frequency range is 256 steps, increasing exponentially from approximately 1HZ to 40KHz. It outputs simultaneous sine, triangle, and square waves, with adjustable duty cycle/triangle wave shape. It has independent amplitude control on each output. And it’s all on one palm-sized, single-sided PCB.
The output isn’t perfect–it’s only 6-bit, although the firmware originally was 8-bit and can easily be reverted. The output filter could probably be improved (it’s currently a simple RC filter). The maximum frequency is limited by 1) the speed of the built-in PLL on the microcontroller (64MHz), which I use for the PWM clock and 2) how fast I can load the timer with the proper values for generating PWM. I have it down to 20 cycles + ISR overhead. And it updates the output 48 times per cycle maximum (and fewer at high frequencies, so the triangle and sine waves aren’t as accurate up there).
But it works pretty well. Here’s an o-scope screenshot (yes, someday I need to hook up the o-scope to the computer):
I got enough parts for several prototypes, and since it works, I’ve put together some kits in the store. You can find those here.