The completed "Word Metronome". There are two recessed
buttons on the front and the lights on on the left side.
Click on the image for a larger version.
Thus, he asked me to make a "word metronome" - a stand-alone device that would provide a visual cue for speaking cadence. The idea wasn't to make the speech robotic and staccato in its nature, but rather providing a mental cue to provide pacing - something that is always a concern when trying to make a given amount of material fit in a specific time window: You don't want to go too fast - and you certainly don't want to be too slow and run over the desired time and, of course, you don't want to randomly change your rate of speech over time - unless there's a dramatic or context-sensitive reason to do so.
To be sure, there are likely phone apps to do this, but I tend to think of a phone as a general-purpose device, not super-well suited for most of the things done with it, so a purpose-built, simple-to-operate device with visual indicators on its side that could just sit on a shelf or desk (rather than a phone, which would have to be propped up) couldn't be beat in terms of ease-of-use.
The schematic of the Word Metronome is depicted in Figure 2, below:
Schematic of the "Word Metronome"
(As noted in the text, the LiIon "cell protection" board is not included in the drawing).
Click on the image for a larger version.
This device was built around the PIC16F688, a 14 pin device with a built-in oscillator. This oscillator isn't super-accurate - probably within +/-3% or so - but it's plenty good for this application.
One of the complications of this circuit is that of the LEDs: Of the five LEDs, three of them are of the silicon nitride "blue-green" type (which includes "white" LEDs) and the other two are high-brightness red and yellow - and this mix of LED types poses a problem: How does one maintain consistent brightness over varying voltage.
As seen in Figure 3, below, this unit is powered by a single lithium-ion cell, which can have a voltage ranging from 4.2 volts while on the charger to less than 3 volts when it is (mostly) discharged. What this means is that the range of voltage - at least for the silicon nitride types of LEDs, can range from "more than enough to light it" to "being so dim that you may need to strike a match to see if it's lighting up". For the red and yellow LEDs, which need only a bit above two volts, this isn't quite the issue, but if one used a simple dropping resistor, the LED brightness would change dramatically over the range of voltages available from the battery during its discharge curve.
As one of the goals of this device was to have the LEDs be both of consistent brightness - and to be dimmable - a different approach was required - and this required several bits of circuity and a bit of attention to detail in the programming.
The Charge Pump:
Perhaps the most obvious feature of this circuit is the "Charge Pump". Popularized by the well-known ICL7660 and its many (many!) clones, this circuit uses a "flying capacitor" to step up the voltage - specifically, that surrounding Q1 and Q2. In software - at a rate of several kHz - a pulse train is created, and its operation is thus:
- Let is start by assuming that pin RC4 is set high (which turns off Q1) and pin RA4 is set low (which turns off Q2.)
- Pin RA4 is set high, turning on Q2, which drags the negative side of capacitor C2 to ground. This capacitor is charged to nearly the power supply voltage (minus the "diode drop") via D1 when this happens.
- Pin RA4 is then set low, and Q2 is turned off.
- At this point nothing else is done for a brief moment, allowing both transistors to turn themselves off. This very brief pause is necessary as pulling RC4 low the instant RA4 is set low would result in both Q1 and Q2 being on for an instant, causing "shoot through" - a condition where the power supply is momentarily shorted out when both transistors are on, resulting in a loss of efficiency. This "pause" need only be a few hundred nanoseconds, so waiting for a few instruction cycles to go by in the processor is enough.
- After just a brief moment, pin RC4 is pulled low, turning on Q1, which then drags the negative side of C2 high. When this happens, the positive side of C2 - which already has (approximately) the power supply voltage is at a potential well above that of the power supply voltage.
- This higher voltage flows through diode D3 and charges capacitor C4, which acts as a reservoir: This voltage on the positive side of C4 is now a volt or so less than twice the battery voltage.
- Pin RC4 is then pulled high, turning of Q1.
- There is a brief pause, as described above to prevent "shoot through", before we set RA4 high and turn Q2 on for the next cycle.
It is by this method that we generate a voltage several volts higher than that of the battery voltage, and this gives us a bit of "headroom" in our control of the LED current - and thus the brightness.
Transistors Q3 and Q4 form a very simple current limiter: In this case it is "upside-down" from the more familiar configuration as it uses PNP transistors - something that I did for no particular reason as the NPN configuration would have been just fine.
This circuit works by monitoring the voltage across R3: If this voltage exceeds the turn-on threshold of Q3 - around 0.6 volts - it will turn on, and when this does it pulls the base voltage, provided by R5, toward Q4's emitter, turning off Q3. By this action, the current will actually come to equilibrium at that which results in about 0.6 volts across R3 - and in this case, Ohm's law tells us that 0.6 volts across 47 ohms implies (0.6/47=0.0128 amps) around 13 milliamps: At room temperature, this current was measured to be a bit above 14 milliamps - very close to that predicted.
With this current being limited, the voltage of the power supply has very little effect on the current - in this case, that through the LEDs which means that it didn't matter whether the LED was of the 2 or 3 volt type, or the state-of-of charge of the battery: The most that could ever flow through an LED no matter what was 14 milliamps.
With the current fixed in this manner, brightness could be adjusted using PWM (Pulse Width Modulation) techniques. In this method, the duty cycle ("On" time) of the LED is varied to adjust the brightness. If the duty cycle is 100% (on all of the time) the LED will be at maximum brightness, but if the duty cycle is 50% (on half of the time) the LED will be at half-brightness - and so-on. Because the current is held constant, no matter what by the current limiter circuit, we know that the only think that affects brightness of the LED is the duty cycle.
The final aspect of the LED drive circuitry is the fact that the LEDs are all connected in parallel, with transistors Q5-Q9 being used to turn them on. When wiring LEDs in parallel, one must make absolutely sure that each LED is of the exact-same type or else that with the lowest voltage will consume the most current.
In this case, we definitely do NOT have same-type of LEDs (they are ALL different from each other) which means that if we were to turn on two LEDs at once, it's likely that only one of them would illuminate: That would certainly be the case if, say, the red and blue LEDs would turn on: With the red's forward voltage being in the 2.5 volt area, the voltage would be too low for the green, blue or white to even light up.
What this means is that only ONE LED must be turned on at any given instant - but this is fine, considering how the LEDs are used. The red, yellow or green are intended to be on constantly to indicate the current beat rate (100, 130 or 160 BPM, respectively) with the blue LED being flashed to the beat (and the white LED flashing once-per-minute) - but by blanking the "rate" LED (red, yellow or green) LED when we want to flash the blue or white one, we avoid the problem altogether.
Not shown in the schematic is the USB battery charging circuit. Implementing this was very easy: I just bought some LiIon charger boards from Amazon. These small circuit boards came with a small USB connector (visible in the video, below) and a chip that controlled both charging and "cell protection" - that is, they would disconnect the cell if the battery voltage got too low (below 2.5-2.7 volts) to protect it. Since its use is so straightforward - and covered by others - I'm only mentioning it in passing.
Because of its familiarity to me, I wrote the code for this device in C using the "PICC" compiler by CCS Computer Systems. As it is my practice, this code was written for the "bare metal" meaning that it interfaces directly with the PIC's built-in peripherals and porting it to other platforms would require a bit of work.
The unit is controlled via two pushbuttons, using the PIC's own pull-up resistors. One button primarily controls the rate while the other sets the brightness level between several steps, and pressing and holding the rate button will turn it off and on. When "off", the processor isn't really off, but rather the internal clock is switched to 31 kHz and the charge pump and LED drivers are turned off, reducing the operating current of the processor to a few microamps at most.
Built into the software, there is a timer that, if there is no button press within 90 minutes or so, will cause the unit to automatically power down. This "auto power off" feature is important as this device makes no noise and it would be very easy to accidentally leave it running.
Below is a short (wordless!) video showing the operation of the "Word Metronome" - enjoy!
This page stolen from ka7oei.blogspot.com