Analog to Digital Converter
Analog to Digital converters (ADC) converts ‘real’ world signals into a digital signal that can be read and used by electronic devices. Common applications include audio recording, video recording and sensor measurements like pressure or temperature. There are many applications for ADC’s and most electronic devices rely on them to function effectively because there is always a need to convert a signal in the physical world into the digital domain. Think about it, how is it possible for you to talk on the phone and someone 3 000KM away from you with no contact hears your sound? You push a button on your phone and you can hear your favourite song exactly the same way the musician recorded it, how is it possible? The only way this is possible is if the physical signal i.e the recorded sound is recorded and converted into a digital signal that can be used by electronic devices such as a radio.
ADC samples an analog signal into equal intervals that have integer values that can be read a microcontroller or a computer of a sort using the principle of sampling and quantization from the Nyquist Theory. The signal is only converted to integer values because a microcontroller can easily read integer values in digital form as shown in the image below.
There are two important specifications to look at before selecting an ADC; the voltage input and the resolution. The voltage input is the maximum voltage the ADC can read, although it can accept a voltage lower. The resolution is specified in bits and it is how the ADC will map the analog signal values into the digital domain if an ADC has 16-bit resolution it means it will map the signal into 2^N (2^(16)=65536) integer values where N represents the number of bits. The get the accuracy of the ADC simply divide the voltage range with the integer value from the resolution (5V/65536=0.000076293V). The higher the accuracy the better it can represent the signal.
How to select an ADC
A typical ADC will record the physical signal with a voltage between 0 to 5V, and it will have a resolution of 10 bits, what this means is that it can read voltages between 0 to 5V with an accuracy of 0.004V and convert that into 1024 digital integer values. In other words, we represent 0 to 5V with 1024 integer values where 0 digital value represents 0V and 1023 represents 5V. Remember, an analog signal is infinite it’s not 1023 values, between 0 to 5V there is an infinite amount values such 0.000001V or 2.10000004V and 4.99999999999993V, we can not fully capture all the values in digital form we have to resort to an acceptable resolution (or accuracy) for our application. This effectively means if our accuracy is 0.004V, and our analog signal changes by a value smaller than that, for example, 0.00002V or 0.001V then will we will be making an error, however, if our signal is changing by 0.1V or 0.01V then we can fully capture it or better represent it.
In reality, changes in the analog signal are very small and depend on the application, for example, a DC motor will change its speed based on the voltage it receives, if it needs 12V to match a speed of 60rpm and 0V it comes to a stop, it means that for every 1V change the motor speed will change by 5rpm which might be noticeable. However, if the motor is running full speed at 12V (and 60rpm) and you change the speed by 0.005V theoretically the speed should reduce by 0.025rpm to 59.975pm but practically you won’t even notice the difference it will still be 60rpm. This example clearly demonstrates that we do not need to capture the full range of the analog signal, but only the accuracy that will have real change for instance, in this case, the accuracy of 0.5V will be enough.
Digital to Analog Converters
Digital to Analog Converters (DAC) as the name suggests converts a digital signal to an analog signal in a similar fashion as the ADC but vice versa. It is often necessary to translate digital signals to the real world or physical domain using transducers like a speaker transmitting sound waves from a phone. A DAC will convert the binary value in digital form to a continuous analog signal with a voltage output of the DAC for example if the DAC has a resolution of 10 bit and voltage output of 0 to 5V, a digital value of 1023 will send an output voltage of 5V from the DAC.
Pulse width modulation (PWM)
Pulse width modulation is a technique used to create a square wave in which you create variable voltage by changing the duty cycle. PWM is another convenient method of converting a digital signal to an analog signal if you do not have a DAC. Digital pins can only output high/low, if you want to change the voltage of that pin without measure power losses you will struggle, however, if you switch on/off the pin fast enough you will create a square wave and in return, the square wave will output a voltage that is continuous based on the duty cycle specified. For example, you want to change the voltage supplied to a DC motor without using a DAC, you can do that by using a digital pin with PWM. The PWM will only work if the frequency used is higher than the source, for example, using an Arduino PWM with the frequency of 940 Hz is more than enough to control the voltage supply of a motor or change the brightness of an LED.
There are a few definitions we need to discuss before using PWM which can be seen in the chart below.
Amplitude: Vmax-Vmin (maximum voltage minus minimum voltage). The minimum voltage is usually 0.
Period: It the time it takes for one cycle to be complete, from one position on the wave to the next same position on the wave.
Frequency: This is the number of cycles per second and is calculated as 1/Period
T_on: Time during the cycle that the signal is on or high (Vmax).
T_off: Time during the cycle that the signal is off or low (Vmin).
Duty cycle: It is a measure of how long the signal is on during a cycle and is measured in percentage.