# Analog to Digital Converter

The real world is analog. It produces continuous electrical signals. To control the real world parameters using digital devices , we must convert the analog signals to digital ones. ADC does the same.There are various ways to convert an analog signal to the digital one. The most effective is Successive Approximation Register Technique.

## The SAR technique

A digital register is updated iteratively. Every time the register content value is compared with expected binary equivalent of the input analog signal. When the most suitable value is seen, that is the output of the ADC.

## The Time Saving Algorithm

Refer to the above figure. Analog input is of  unknown value. The ADC will convert it to its binary equivalent. We assume here that the ADC is 10 bit wide (like it is in Arduino/Tinah). So the output binary number is expected to be in the range 0 to 1023.

To convert the analog signal (in the range 0 to 5 volts) to an equivalent binary number, the ADC follows this procedure:

1. The logic block will load number 512 (mid value of 0 to 1023) to the SAR register. ADC output is disabled.
2. Its equivalent value appears at the DAC output. It is an analog voltage.
3. This voltage is compared with the input analog voltage by an analog comparator.
4. New value in SAR is decided by using following logic:
1. If the comparator output is high, (i.e. analog input is greater than DAC output)  mid value of the upper range (512 to 1023) is loaded to the SAR, say 766.
2. If the comparator output is low, (i.e. analog input is less than DAC output) mid value of the lower range (i.e. 0 to 512) is loaded in the SAR, say 255.
5. The above process continues for TEN iterations. After the TEN iterations, the DAC output is expected to be very very near to the input analog signal.
6. We are considering a 10 bit ADC so TEN iterations are necessary to come to the result. (\$ latex 2^10 = 1023\$)
7. When the tenth iteration is over, the SAR output is declared as the output of ADC.

To understand the above algorithm well, I wrote a number guessing game. In this game you will play the role of the logic block. The computer plays the role of analog comparator. In this game, I assume that the ADC is 7 bit wide (for the sake of simplicity). You need to have python installed on your machine to play this game. You can download the game here.