Chest tune 2
Summary
In this page I revisit the design for chest tune, a gadget that plays a melody when a container is opened. I explore different ways to drive a piezo buzzer and design and produce a funcitoning prototype.
Buzzer tricks
Originally, the design utilized an op-amp to combine the three square wave melodies and drive the buzzer. Evidently, using an op-amp is not necessary because the capacitive nature of the buzzer allows it to be driven with low enough current for the attiny microcontrller to handle directly. The op-amp design was scrapped and two different approaches were tested for driving the buzzer directly.
XOR summing
This method of driving the buzzer produces a loud sound, while keeping all the melodies equally audible. The output can be produced by a digital out pin so there is no need for PWM hardware. The downside of this method is that the timbre of the 1/4 duty cycle square wave is lost.
This method works by combining all square wave melodies using an exclusive or operation. The XOR's output toggles each time any of the individual melodies toggle, and through this mechanism all the original frequencies are maintained.
In short, this method:
- Produces loud sound
- Does not require PWM capabilities
- Can combine many melodies
- The timbre is rough
Regular summing
This method diitally summs the melodies in code and uses a PWM output to drive the buzzer. It lacks in volume slightly in comparison to the previous method, but it is able to maintain the timbre and character of the 1/4 duty cycle square wave.
In short, this method:
- Can combine many melodies
- The timbre is maintained
- Produces lower volumes
- Requires PWM capabilities
Inverted signal feeding
There is a simple trick that can be used to boost the voltage the buzzer receives, and thus increase the output sound volume!
In many cases, the buzzer's + side is used to feed the produced signal and the - side is tied to ground. In those cases when 3V are fed to the + side, the total voltage diference between the two sides of the buzzer is 3V since the ground sits at 0V, hence 3-0=3V.
It is possible to increase this voltage if the - side is fed with the inverted signal. In the same scenario, when 3V are being fed to the + side, the - side would be receiving 0V since that is the inverse of a 0-3V square wave. This makes no difference so far. The key hides in the case where the signal on the + side decreases, and as it does, the inverse onee increases. Now when the + side reaches 0V the - side should reach +3V. This causes the buzzer to perceive a total of -3V, essentially increasing the voltage range that the buzzer sees from 3-0=3V to 3-(-3)=6V, essentially doubling it.
To perform this using reglar summing, two PWM channels are needed, while in the case of XOR summing two digital outputs.
Selecting methods
All above mentioned methods were tested and I selected the regular summing while also using the invert signal feeding technique. This yields a loud enough output while also maintaining the classic 8-bit timbre. In comparison with previous design, this will also allow the use of much less components and make the PCB design and assembly much easier.
Schematic
The schematic and board were drawn in KiCad this time.
- The battery powers the ATtiny13A.
- Two PWM outputs produce the inverted regularly summed waves
- One pin is used to read the LDR divider
- One pin is used to drive a small led that light on trigger
Board
The board was designed to be as small as possible, but this time, the buttery and buzzer were positioned right across one another. This is definitely not a textboook solution for soldering THT components but it helped keep things tight and the PCB even smaller. It should be able to fit in small presents and containers, for successful chest-open sound delivery!
In order to make manufacturing easier, the boards were stacked in a 4x4 matrix for V-scoring. Different silkscreen designs were chosen for potentially adding different sounds in the future.
Code
The code was changed according to the selected canges for summing the three melodies internally, and using two PWM outputs for outputting the summed wave and its inverted result. The code is still available on the same page in GitHub, here!
- When the gadget is armed, it will play the melody the next time it detects light
- The gadget will become armed only if there is no light
- The gadget attemts to arm 30" after the first boot (i.e. after inserting a battery)
- After a trigger, the melody plays and the gadget will attemt to arm only after spending 1hour in darkness
- The watchdog timer and interrupt are used to read the LDR while the chip sleeps
Prototype
The PCBs and stencil arrived after about 2 weeks and they were put to use to create the first prototype. Here is how it sounds:
The sound is greatly improved compared to the previous design and the PCB is much smaller so that it can fit in smaller boxes. The sound is also much louder and the timbre is preserved.