Metronome

Disclaimer

Introduction

Schematic

Circuit Board Layout

Construction

Software

Parts List

Conclusions

Disclaimer

Please read and understand the following paragraph before continuing.

The contents of this article are for personal, educational and non-commercial uses only. The information is provided "as is", without any warranty of any kind, and without any guarantee as to fitness for purpose. The content of this article is copyrighted Mike Perks, 2006.

Introduction

This article, first published on 5 February 2006, describes an AVR-based metronome. The circuit and AVR software is based on the Circuit Cellar AVR 2004 Design Contest Entry A3721. Credit is due to the original author, Michael Kirkhart, as I was able to prototype the circuit on a breadboard in a few hours.

 

There are a number of changes I made to the original project to suit my requirements and personal preferences. You may also find some of these useful or interesting. The summary of changes is as follows:

·        Removed the soft-power off circuitry and supporting software. The reason is that an additional power switch is still needed so I simply used a mechanical toggle switch to power the metronome on and off and added a simple 5V regulator.

·        Added the ability to produce notes for instrument tuning. The original author plays a piano so this feature wasn’t needed but the intended user plays a violin.

·        Mounted the hardware in a small enclosure so that the metronome is portable.

·        Changed LCD display to 2x16 partly as that was what I had available. I plan some software changes in the future that will utilize the 2 line display more fully. The second line can be used to indicate the button usage for the menus.

·        Eliminated the JTAG port but kept the AVRISP port for programming.

·        Replaced the two display LEDs by a bicolor LED to reduce the number of front panel components. Some further programming could be done to eliminate the LED by providing a visual beat indicator on the second line of the LCD.

·        Added 8MHz external crystal for better timing accuracy.

Schematic

As the original author did not provide a softcopy of the schematic so I have created a EAGLE schematic as shown below. I did not include the original power support circuitry but that could be easily added.

Circuit Board Layout

After breadboarding I usually use stripboard (aka Veroboard) for one-off projects. I create a board layout using the EAGLE schematic as shown in the diagram below. The blue bottom layer shows the strips and the red top layer shows the 37 wire links. The dashed wire links need to be insulated. The EAGLE BRD file is available by emailing me.

 

Because I wanted the circuit to fit into an enclosure, I needed to design a stacked PCB design with the upper layer containing the LCD, buttons, speaker, and LED. The bottom board is shown on the right with black dashed outlines of the two stacked boards. On the left is the daughter board that contains the buttons, speaker, and LED. The LCD display daughter board is not shown because it already exists. I used female header sockets on the bottom board to seat the two daughter boards. The mounting holes on the main board match up with the internal mounting holes for the enclosure. Note the additional mounting hole for the button board to provide additional stability.

 

 

An additional consideration for the board layout is the height of the components on the main board. Several changes were made to take into account the height restriction:

·        The electrolytic capacitors were moved to one side so they were not under a daughter board

·        A cylinder crystal package was used because it is compact and can be laid flat horizontally.

·        Right angle versions of the toggle switch and IDC header were used to both reduce height and provide external access from the sides of the enclosure.

·        The AVR reset button and serial RX/TX header used for debugging are placed on the main PCB so they are accessible even when the daughter boards are installed.

 

The bottom layer of the stripboard needs cuts and breaks in the strips. The diagram below shows the 84 breaks that are needed. I use holes (EAGLE layer 45) in the board to represent these breaks. One size of hole represents a break that can be drilled out and the other size hole represents a break between holes that needs to be cut using a knife. Of the 84 breaks needed, only six are the harder to produce breaks between holes. After the process of making breaks (drilling and cutting), I always check the underside of the board for any unintended shorts. This saves time later when debugging the circuit after it is built.

Construction

Building a circuit to fit into an enclosure is always harder than simply soldering up the circuit board. I spent quite a bit of time making paper templates and checking the fit of the boards and components in my chosen enclosure. I used the HP-9VB from Pac-Tec which includes a separate compartment for a 9V battery. This enclosure is fairly common and is available from Mouser and Fry’s Electronics for just over $5. An additional benefit of this enclosure is that it stands upright by itself on top of a piano, table or other flat surface.

 

The photograph below shows the main PCB installed into the enclosure. Two screws hold the left-hand side of the PCB and a third screw and spacer is used to hold the LCD display and main PCB. Note that there is a fair amount of spare room on this board, but that it is used to get the correct placement of the various components. There is space around port C which could be utilized for a R2R ladder or DAC to provide a cleaner output than the PWM currently used.

 

Two cuts have been made in the sides of the enclosure bottom to accommodate the toggle switch and the shrouded header used for the AVRISP port. The AVRISP port allows reprogramming of the ATmega16 without removing the enclosure lid. Below is a picture of the main board with the two daughter boards installed in the three female header sockets.

 

 

The LCD mount height turns out to be just right in that it is flush with the top of the lid to the enclosure. The PCB mounted speaker is below the lid of the enclosure and so one or more holes can be drilled for it.

 

The buttons and LED however are not the correct height. I used two layers of female sockets for the buttons to get them to the same height as the LCD display. The flat surfaces of the buttons are flush with the top of the enclosure and the buttons themselves just stick up above this surface. The lid itself stops the buttons from moving side to side too much.  The lid is too thick to allow just the button knob to show through. Another alternative would be to use panel mounted push buttons. The LED is slightly below the lid of the enclosure as I soldered it in the lowest position possible. Although I haven’t done it yet, it makes more sense for the LED to be mounted higher so it just peeks through the lid.

 

Here is a picture of the enclosure with the lid in place. It was very time consuming to position and cut the holes for the LCD display and buttons. I am not particularly skilled in this area but I think the result is serviceable.

The LCD display in the picture shows part of the user interface for playing a note. The red button is the run/stop push button.

Software

The software provided with the original metronome is written in C and even provides for a Windows emulation of the LCD display and interaction. Although this is perhaps not the most efficient code, it is quite straightforward to modify. The modifications I made to the software are as follows:

·        Changed the splash screen message in SplashScreen.C.

·        Changed the makefile to generate dwarf2 symbol files that could be used by AVR Studio 4.

·        Removed the code that controlled the soft power switch and shutdown event. The code modules named PowerOveride.C and ShutdownMenu.C were removed from the makefile. As a consequence of this modification, the configuration is persisted in EEPROM every time the Run/Stop button is pressed in all the modules that process the UI_KEY_RUN_STOP event.

·        Added support for playing notes C4 (middle C) through B4 for instrument tuning. This modification required changes to the menus, sound producing routines and the addition of a new module called Tune.h and Tune.c to control the menu and playing the note. I used a direct digital synthesis (DDS) technique to create a sine wave of the correct frequency. The note frequency determines when the Timer1 “output compare A” interrupt is issued. At each interrupt the next byte from a 64 byte sine wave table is retrieved and output to the Audio PWM (OCR0). The additional support for a variable timer play function was added to the existing function in Sound.C.

 

Probably the best way to understand the software modifications is to do a compare of the code “before” and “after”. See the zip file for the 24 files that I modified or created, and the binary files for download.

 

The various fuse values needed to program the ATmega16 were missing from the original article. With the use of the external crystal the fuse high byte is 0xc7 and the fuse low byte is 0xef. Below is a screen capture from AVRPROG that shows the fuse, boot, and lock options that I used. The zip file for the source code also contains a simple Windows batch command file for use with Avrdude version 5.0.

 

 

Below is a picture of the metronome connected to my AVR programmer. I have a project that describes how to build this AVR910 compatible programmer for under $9. In the picture the programming LED is red as it is middle of a verify and the metronome is showing the splash screen from a reset that occurred after the programming cycle.

 

Parts List

Here is the complete parts list and for those people in the USA, the order numbers and prices from Mouser. The total cost is $34.39 not including the stripboard/PCB, sales tax and shipping. The best source I have found for buying stripboard in the USA is AllElectronics. The part number is ECS-4 and costs $5.50 for a stripboard that is 38 strips by 55 holes.

 

Part

Value

Description

Mouser Part #

Quantity

Cost

B1

HP-9VB

Enclosure and 9V clip

616-60620-510-0001

1

$5.49

C11, C12

27pF

Ceramic Cap

140-50N2-270J

2

$0.14

C4

4.7nF

Metal film Cap

581-BF014D0472J

1

$0.10

C3

47nF

Metal film Cap

581-BF014D0473J

1

$0.12

C1, C2, C5

0.1uF

Ceramic Cap

80-C320C104K5R

3

$0.48

C7

2.2uF

35V Electrolytic Cap

140-XRL25V2.2

1

$0.06

C6, C9, C10

10uF

35V Electrolytic Cap

140-XRL35V10

3

$0.18

C8

470uF

35V Electrolytic Cap

140-XRL35V470

1

$0.25

D1

1N4001

Rectifier Diode

625-1N4001

1

$0.04

IC1

ATmega16

Atmel ATmega16 40pin DIP

556-ATMEGA16L-8PC

1

$7.16

 

40p Socket

 

575-199640

1

$0.96

IC2

LP2950

5V 100mA regulator

Parts box

1

$0.10

IC3

TDA7052A

Voltage controlled 1W amp

568-1138-5-ND3

1

$1.10

 

8p Socket

 

575-199308

1

$0.20

JP1A, JP2A, JP3A

 

Female headers

(total 24 pins)

517-974-01-36

1

$1.87

JP1B, JP2B, JP3A, JP5

 

Male headers

(total 28 pins)

517-6111TG

1

$0.81

JP4

10p

Shrouded low-profile header

571-1033111

1

$0.62

LCD display

16x2

16x2 LCD parallel display

696-LCM-S01602DTRM4

1

$5.88

LED1/2

Duo LED

Red/green 2 lead LED

512-MV5491A

1

$0.30

Q1

8 MHz

Cylinder crystal

815-AB308-8.000

1

$0.54

R4

330R

¼ watt resistor

Parts box

1

$0.02

R6

470R

¼ watt resistor

Parts box

1

$0.02

R3

1K

¼ watt resistor

Parts box

1

$0.02

R1

1.2K

¼ watt resistor

Parts box

1

$0.02

R5

2.2K

¼ watt resistor

Parts box

1

$0.02

R2

12K

¼ watt resistor

Parts box

1

$0.02

RN2

10K

10 SIL resistor array

652-4610M-1LF-10K

1

$0.32

S1, S2, S3, S4, S5, S6

SPST

Tactile 6mmx6mm switch PCB mount

101-TS6111T1601-EV5

6

$0.78

 

 

SIL socket (total 50 pins)

575-193132

2

$1.86

S7

SPDT

Toggle switch PCB mount

108-2MS1T2B2M6QE5

1

$3.41

SP1

8 Ohm

Speaker PCB mount

665-AT-415

1

$1.50

 

 

Various mounting hardware

Parts box

 

N/A

 

Notes:

  1. I prefer looking at boxes before I buy them so I got this same box at Fry’s Electronics for $5.19 excluding tax.
  2. Digikey carries a better selection of AVR chips.
  3. The TDA7052 is not stocked by Mouser. This is a Digikey part number and price.
  4. There are numerous sources for the LCD display that may be cheaper or better than Mouser. The display must support the standard Hitachi HD44780 interface.
  5. It is usually possible to get these parts cheaper from other online “discount” retailers.

Other Enhancements

There are a number of other enhancements that could be implemented such as:

  1. Use the second line of the LCD display to dynamically indicate what each button is for e.g. show “Stop” for the Run/Stop button.
  2. Use the second line of the LCD to display a beat indicator (e.g. a filled blob) that moves across the display for each beat.
  3. Recognize when a button is being held down (new keypad events) and use these events to implement fast change of values such as the tempo.
  4. Allow for other beat combinations where only the first and last beat of each measure is sounded
  5. Add an earphone jack.
  6. Indicate when the tap tempo is slower than 40 (Low) or faster than 240 (High).
  7. Allow the frequency of “A” note or other notes to be fine-tuned (currently fixed at 440.14 Hz).
  8. Port the design to an ATmega168 which has a 28pin package. The design may need to use the Reset pin for I/O (fuse RSTDISL) or a software change so the LCD display I/O pins can be split across ports.

Conclusions

I got a great deal of satisfaction in making this metronome project. The circuit and software worked correctly first time and the software modifications were easy to make. The cost of the project is about the same as buying a commercial metronome although I actually spent very little additional money as almost all of the parts except the TDA7052A amplifier came from my parts box. So although the end-product is not as compact or “finished” as a commercial product, the ability to add features and “fine-tune” the software for years to come easily outweighs this disadvantage.

 

© Mike Perks 2006 – All views expressed in this document are my own and have been derived from Internet research and/or personal discovery. Please let me know if I have unintentionally infringed any copyrights or patents. All copyrights and trademarks belong to their respective owners and are not explicitly marked. BasicX website visited times.