AVR Twinkle Twinkle Using PWM Project Using Atmega

AVR Twinkle Twinkle

Would be interesting if we could make our microcontroller to sing for us not just beeping or blinking; this project is all about using the powerful AVR ATmega168 16-bit PWM feature to produce accurate musical notes such as playing the child’s favorite Twinkle-Twinkle Little Star song or we could say beeping with style. The principal we learned here could be applied to other AVR microcontroller families that support 16-bit PWM.

 AVR Twinkle Twinkle

Basic natural sound we usually hear is formed by fast vibration; this vibration can be produced by many sources such as by string like guitar, piano, violin or by our vocal membrane when we sing or talk. All this sound produced the sound wave known as sine or sinusoid wave. By using the same principal we could produce sound electronically using oscillator circuit; this circuit basically is the amplifier with the input signal taken from the output or known as feedback. By amplifying this feedback signal over and over the amplifier become unstable and starts to oscillate; the output of this signal will be feed to the speaker and the speaker will vibrate according to the sound wave frequency.
This behavior can be observed when we talk on the microphone and if the microphone is close enough to the speaker suddenly we will hear the sound coming out from the speaker and usually we call it as the feedback sound.

 Circuit AVR Twinkle Twinkle

In the digital circuit we could create such vibration by using the same feedback principal; but the waveform generated by the digital circuit is a square waveform, therefore we have to change the waveform to the waveform normally produced by nature or the sine waveform. Normally we will use the integrator circuit or known as low pass filter to change the square waveform to the triangle waveform and another low pass filter to change this triangle waveform to the sine waveform.
The explanation of how it works required complex mathematical equations; but we could express it in practical terms that the square wave signal actually is a combination of the fundamental sine wave frequency plus all the odds sine wave harmonic frequencies at diminishing amplitude. This statement is known as a Fourier’s theory. For example if we have a square wave signal with frequency of 1 kHz, according to the Fourier’s theory we could represent this signal as a sum of all series of sine wave signals start from 1 kHz (the fundamental), 3 kHz (third harmonic), 5 kHz (fifth harmonic), 7 kHz (seventh harmonic), 9 kHz (ninth harmonic) and so on.
Therefore by passing the fundamental frequency and filtering all the harmonic frequencies using the low pass filter, we could get the fundamental sine wave signal. Another dirty method is to feed directly the square wave output to the speaker or piezoelectric material which works as the low pass filter; this is the method we used in this project. By using the sophisticated AVR PWM peripheral it’s easy for us to generate this square wave signal.

The following is the list of hardware and software we will use in this project:

  • 1 4K7 Resistor
  • 1 TIP120 Darlington pair transistor
  • 2×16 LCD with back light LED
  • 10 K Trimpot
  • AVRJazz Mega168 board from ermicro which base on the AVR ATmega168 microcontroller (board schema).
  • WinAVR for the GNU’s C compiler
  • Atmel AVR Studio 4 for the coding and debugging environment
  • STK500 programmer from AVR Studio 4, using the AVRJazz Mega168 board STK500 v2.0 bootloader facility

Read more: AVR Twinkle Twinkle Using PWM Project

Leave a Comment

Your email address will not be published. Required fields are marked *