AVR Twinkle Twinkle Using PWM Project

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 Using PWM Project
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 Using PWM Project
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.
For more detail: AVR Twinkle Twinkle Using PWM Project

About The Author

Ibrar Ayyub

Ibrar Ayyub is an experienced technical writer with a Master's degree in computer science from BZU Multan University. He has written for various industries, mainly home automation, and engineering. He has a clear and simple writing style and is skilled in using infographics and diagrams. He is a great researcher and is able to present information in a well-organized and logical manner.

Follow Us:
Scroll to Top