My Thoughts and Know-how

Displaying entries tagged with 'electronics'. Show all

Microcontroller Class D Amplifier, Rev2

11 March 2012

A problem of the first revision of this amplifier was the limited precision at low volumes. Although the PWM of the ATtiny45 is just 8-bit, I realized that it can produce arbitrary precision output. Timer1 can be clocked at 64 MHz from the high frequency PLL, which combined with the double-buffered counter compare value and the overflow interrupt, can get 9 and even 10-bit precision in the audible range. Lets say we want to DAC the value 300/512. We set OCR1A to 255 (which will hold the output high) and on the timer overflow, we write 300-255 = 45. Writing this 9-bit value takes 2 timer cycles.

Continue reading
amplifiers electronics Comment


23 Feb 2012

Monosynth is a MIDI controlled monophonic synthesizer.

The buttons change the menu and the slider inputs the parameter values


Block diagram

There are 2 concurrent threads of execution: a control thread for computationally intensive tasks, such as envelope updates and the user interface, and a fast sample generating thread that preempts everything else. MIDI messages are received by the serial interface interrupt handler and are quickly queued for parsing by the control thread.

Continue reading
music electronics Comment

Microcontroller Class D Amplifier

5 Feb 2012

This article is about an obsolete version of the amplifier. For the new revision, go here.

Class D amplifiers are very efficient and could be simple to build. They operate the power stage in a binary mode and pass the delivered pulse train through a low-pass filter (which might involve the speaker itself) to filter all frequency components introduced by the switching of current.

I designed a 70W bridged amplifier based on the Atmel Tiny (attiny45) microcontroller. Vcc is 12V and it requires no heat sink, nor has a feed-back loop of any kind. The output power is limited by 2 factors:

  • Precision in the digital domain. Making the gain very high will hurt quality at lower levels.
  • Isd of the power MOSFETs. The ones I had are rated at 6A, potentially delivering P = I^2 R = 144W at 4 Ohm or 72W at 2 Ohm..

Continue reading
amplifiers electronics Comment

Sound Distorter

06 Oct 2011

Making a synthesizer is fun because it's so cross-discipline - hardware, firmware, music theory and very importantly - lots of low-level performance tricks. It is also simple enough that a single person can design and build it. I passionately made one and here's how it works: the sequencer plays a chiptune, the basic I/O and the display allow us to change parameters on the fly and the tone generators deliver all this to our ears.

Sound Distorter runs mostly in software - a tool chain preprocesses a midi file so that it can be efficiently stored and played on the 8-bit Atmega168 microcontroller. After loading the chiptune midi file, sconv runs a series of filters to compact it and to preprocess operations to save cycles on the microcontroller. For example, instead of storing the tone (such as C#4), it could store the frequency. To be more efficient, it actually stores the wavetable offsets in samples per sample. Thus, playing a tone becomes a matter of just incrementing the wave-table index. The optimized file format I call .sad, short for sound distorter and the reminiscence of the C64 .sid should be obvious :) Finally, the .sad file gets converted to an assembly listing because the only way it can fit into the Atmega168 is in the text segment as program instructions.

The synth runs in 2 threads - a heavy-duty control thread that schedules events (such as note on, pitch-bend change, volume, etc.) and a fast, sample generating thread. The sample generator has real-time constraints and may preempt the control thread. To guarantee fairness, if overrun occurs and the control thread doesn't get to run, the synth drops (but does not delay) a sample. The sound generators use 2 shape wave-table - a sinusoid and a sharp, noisy wave. Besides the volume envelope, there is a blend envelope that linearly mixes the two shapes so that the sound changes in time. For example, during attack, primarily the noisy shape can be used, eventually resolving to a sinusoidal soft tone to mimic a plucking sound. Initially, I implemented FM modulation, but since the two wave shapes actually produce similar sound quality computationally much faster, I dropped it. There is also per channel pan mask to produce simple stereo effects.

The generated wave is then converted to an analog signal using 2 of the on-chip pulse-width modulators. To filter out the pulses and the bit flipping, the signals go through second order Sallen-Key low-pass filters.

The circuit board.

I feel I've made the project fairly easy to understand - code, schematic, mp3 and more pics. A secret prize goes to the one who figures out what the 3rd chip is for :)

music electronics Comment
Home Top