Everything related to digital electronics is related to time. Timer, counter, frequency, pulse width, clock and time are the most common words one may find in this arena. Microcontrollers just like humans need heart-beats and these come from clock sources. Apart from system clock, timers are clock sources that can be used as heart-beats for various applications. All modern micros are embedded with timer-counter modules and generally they are used for generating time bases, counting pulses, measuring time periods of waveforms, generating pulse width modulation (PWM) signals, triggering external devices and timing special events. STM32 micros have several timers designed for such applications. However unlike most 8-bit micros which possess two/three timers with limited functionalities, the timers of STM32s are very elaborate and complex. This explains why documentations related to timer modules take about 25% of any STM32 reference manual.
Before we begin exploring STM32 timers, I must point out that I won’t be able to cover every aspect of all timer modules as they are vast and need lot of explanations, something which is beyond the scope of a single post. This is why in this issue we shall explore the very basics of timer modules enough to get STM32 timers to work.
This ATtiny25-based automatic timer project is built to control a water sprinkler. The timeout delay is adjusted using a potentiometer, while the on/off operation of the timer is controlled through a tact switch.
Automatic timer for water control
On the software side, upon power up, the timer flashes the status light to count out the delay in minutes. 10 flashes correlates to 10 minutes. The ADC reads the potentiometer just during the power up and calculates the delay for further use. So to change the delay, you first unplug the timer, set the delay, then plug it back in. This way it will hopefully prevent accidental changes and noise from changing the delay. To use the timer, you press the button once – the timer starts, the valve opens and the status light turns on. After the delay has elapsed, the timer will shut off, valve closes and the status light shuts off. If you want to turn it off early, then you just push the button and everything turns off. I also made use of the watchdog timer to prevent software issues from keeping the valve open. In the event that a watchdog reset occurs, the initial startup code will catch it, begin flashing the power LED and prevent further use until being power cycled.
Here’s another seven segment LED based digital clock using a PIC microcontroller. The project uses a 4-digit common anode type seven segment LED display, a PIC16F727 MCU, and BCR562 transistors operating as switches to drive the LED segments and common anodes. A coconut shell enclosure gives an artistic look to the clock.
Seven segment LED display clock
This TV-Go-Sleep timer turns off any TV after a preset delay time. This project is built around an Arduino microcontroller that uses an open source TV-B-Gone library. The hardware part consists of a pushbutton switch to set the delay time, which is shown on a 7-segment display. When the timer expires, the Arduino transmits “Turn OFF” codes for all known TVs through IR LED, and the TV shuts down.
Universal TV sleep timer
A music synthesizer is Frank’s entry to the 555 contest. He used a 555 timer to make a really cool synthesizer that is played with a stylus and has filtering and volume enveloping features. Various note frequencies are generated with precisely calculated resistances.