Tone generator

Most of the AVR microcontroller have a timer with a PWM channel. With this project a tone is generated using the PWM channel of the microcontroller. By changing the PWM duty cycle different tones can be generated. The microcontroller used is the ATTiny2313 miucrocontroller.

Overview

The ATTiny2313 has four hardware PWM channels on Timer0 and Timer1, we use the PWM channel 0 (PB2) to drive a transisitor via a 2.2kohm resistor. A loudspeaker is connected to the collector of transistor and a 56ohm serie resistor limits the current. The loudspeaker then emits the sound that is generated by the microcontroller.

Circuit

Fabrication

The circuit is build on a breadboard and connected to the ATTiny2313 board wich can be purchased at www.bizztronix.eu

Design code

The code runs at a clock frequency of 20Mhz. First the PWM channel is initiated, then in the infinite loop two tones are generated by changing the duty cycle of the PWM timer.

/*

program name: tone generatordate: 24.04.2015author: www.avrprojects.netgenerate a two tone with PWM channel*/