3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Reading Switches with ATtiny2313

Step 5Using Timer/Counter 0 for Beeps

Using Timer/Counter 0 for Beeps
The ATtiny2313 has two powerful timer/counter resources: one 8-bit and one 16-bit. These may be configured as frequency generators, variable pulse width modulation controllers, and output compare registers. The full functionality of these is described in 49 pages of the data sheet. However, we'll use a simple case. Only Timer/Counter 0 (the 8-bit one) will be used and it will be used simply as a frequency generator. The frequency will be routed to a small speaker to produce a beep. Timer/Counter 0 is fully described in pages 66 to 83 of the ATtiny2313 data sheet. A close reading of this material will provide one with a complete understanding of Time/Counter 0. Happily, a fairly simple mode, Clear Timer on Compare (CTC), is all that is required to generate the beep tone we want.

For the mode we'll use, operation of the Timer/Counter is straight-forward. When a clock signal is selected, the counter starts at zero and increments each clock pulse. When the counter value reaches the value in the Output Compare Register (TOP), the counter resets to zero and counting starts again. The output bit associated with the Timer/Counter is toggled to produce a square wave output. This directly drives an audio transducer to make a beep sound.

A small TDK Audio Transducer produces the beep. A suitable unit is Digikey 445-2530-ND, TDK SD1209T3-A1 (I used an early version of this). This is a 3 volt version; the 5 volt version will also work I expect. I drive this directly off the output port of the Attiny2313 and it seems to work fine. Sparkfun has a similar device.
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
41
Followers
8
Author:doctek