Another project using the 8042

Now that the 8042 clock project has been published, I'm publishing another project based on the same hardware. As I stated, the board can be turned to many uses. This one posed some interesting design problems.

I was able to use a large fraction of the code from the clock project, for example the TM1637 driver code was used unchanged, so I only had to solve this design problems posed by this project.

Yes, I know you can get apps for your smartphone that do this and more. But we hack to have fun and exercise our brains. Besides a case could be made for a battery-powered design using a cheap low-power consumption MCU. For one thing you would not get interrupted by social media in the middle of practice or a lesson.☺


Design goals

  • Handle tempi between 60 and 236 beats per minute
  • Handle the most common metres: 0 (no accent), 2 (duple time), 3 (triple time), 4 (quadruple time), 5 (quintuple time, like in the jazz standard Take Five), 6 (for 6/8 time).
  • Make a distinctive sound on the first beat when accent is selected
  • Display the current tempo and the current beat


Handling the tempo

This one is a straightforward matter of counting as many ticks (the basic period of work) to get the right tempo. However there are a couple of wrinkles. We do not want every tempo from 60 to 236, the lookup table would be large and it would take longer for the user to set the wanted tempo. We take advantage of the fact that at higher tempi a step of 1 is not as significant as at lower tempi. So we have a scaled table. From 60 to 80, we progress in steps of 1; from 80 to 120 we progress in steps of 2; from 120 to 160 we progress in steps of 3; and from 160 to 236 we progress in steps of 4. In music practice, it is seldom critical to get the exact tempo, we just need to be able to set it approximately. Nobody is going to complain I wanted 83 beats/minute and you can only give me 82 or 84. So instead of storing the tempo, we store an index into the count table. The assembler declarations are generated by a Python script. At the same time we generate a table with the BCD equivalents of the tempo to expedite conversion from decimal to BCD mapping to the 7-segment output.

Incidentally, in this project, the crystal frequency is less constrained than for the 8042 clock. You just need to adjust scandiv in the code to the closest divisor that will give you 4 ms for the tick.


Handling the accent

Mechanical metronomes have a control which turns on accenting of the first beat so that the player knows when to start the bar. For example in 4 beat metre it goes dingtok tok tok.

At first I designed the firmware to produce a longer beep for the accented beat and a shorter bip for the remaining beats. This is using a self-contained piezo-electric beeper that only requires power, not a waveform.

I tested this and found that although one could distinguish the beep from the bips, it wasn't as good as a real metronome. So I searched for a way to generate a ding electronically. I found cheap sound chips used in toys but those generated sirens and space guns. No way.

In an electronics forum I found this post. This turned out to be a good suggestion. I tested it manually with a piezo-electric beeper and although it didn't have the sharp attack of a bell, the exponential decay did sound chime-like. So here's the circuit I designed. A separate ding pin charges a capacitor which discharges into the beeper for about 100 ms after the pin is turned off....

Read more »