Control systems that manage electrical or mechanical systems must often be able to generate, or respond to, sequential events in the system. This ability to use time as part of the driver equation is in fact one of the important abilities of a microcontroller that makes it such a good control for electrical and mechanical systems. However, implementing multiple sequences can become long and involved if a linear coding style is used.
A simple construct, called a state machine, simplifies the task of generating a sequence by breaking the sequence into a series of steps and then executing them sequentially. While this sounds like an arbitrary definition of a linear piece of code, the difference is that the individual sections, or steps in the sequence, are encoded within a SWITCH/CASE statement.
Pulse Width Modulation (PWM) Tutorial
Pulse Width Modulation – Using digital pulses to create some analog value other than just ‘high’ and ‘low’ signal levels. Many digital systems are powered by a 5-Volt power supply, so if you filter a signal that has a 50% duty cycle you get an average voltage of 2.5 Volts. Other duty cycles produce any voltage in the range of 0 to 100% of the ‘high’ voltage, depending upon the PWM resolution.
A state machine is recommended for most solutions where there is non time-critical tasks to perform. However, the time sliced multi-tasking is useful when:
1. There is multiple tasks.
2. Some of the tasks are low-priority, and can execute in the background, being interrupted by higher priority tasks. For example, low-frequency PWM with 300ms of mathematical calculations happening every 1 second.
The 555 Timer is a very cheap, popular and useful precision timing device that can act as either a simple timer to generate single pulses or long time delays, or as a relaxation oscillator producing stabilized waveforms of varying duty cycles from 50 to 100%. The 555 timer chip is extremely robust and stable 8-pin device that can be operated either as a very accurate Monostable, Bistable or Astable Multivibrator to produce a variety of applications such as one-shot or delay timers, pulse generation, LED and lamp flashers, alarms and tone generation, logic clocks, frequency division, power supplies and converters etc, in fact any circuit that requires some form of time control as the list is endless.