ESTE: Analog-to-Digital Converter (ADC) and Sensor Reading

De MediaWiki do Campus São José
Revisão de 18h39min de 15 de setembro de 2015 por Katharine.sf (discussão | contribs)
Ir para navegação Ir para pesquisar

This experiment is part of this project.

Here we are going to learn about the ADC and how to use and read sensors. The ADC or conversor A/D is a analog-digital conversor. It is an electronic device capable of generating a digital representation from an analog quantity (usually a signal represented by a voltage level or intensity of electrical current). ADCs are useful and normally necessary at the interface between digital devices (microprocessors and microcontrollers) and analog devices and are used in applications such as reading sensors, audio and video scan. For example, an ADC of 10 bits and prepared for an analog input signal with voltage that varies from 0V to 5V can take binary values from 0 (0000000000) to 1023 (1111111111) respectively. It is also capable of capturing 1024 (10 bits) levels of a given signal. if we presume a ADC input signal of 2.5V, for example, the binary value generated will be 512. (0v = 0, 5v = 1023, 2.5v = 1023/2). So if we want to use, manipulate or visualize a value generated by a sensor we must use an ADC to convert these signals to digital values and then manipulate them. Those signal generated by sensors may be unstable and vary a lot each measure caught by the ADC, therefore we need to perform an average(RMS) of the obtained measures, get from this average a reliable value and then convert it.

Pseudo code

Let's begin with a solution. The pseudo code (actual coding is up to you) is below:

int main(void) {
    int x;
    while(1) {
        Accumulate(x);    //accumulate x mesures. Recomended x=30;
        RMS();            //performs the average of the measures
    }
    return 0;
}     

void Accumulate(int repeat){
    while(repeat){
        digital_value = read(analog_value);   //convert the analog-value (voltage) to digital one (0-1024)
        accumulated = sum_digital_value;      //accumulate all the digital-values “repeat” times
    }
}

void RMS(){
    average = accumulated / repeat;      //here we have a general example of an average. RMS instead, is given by the "Equation of RMS".
    equivalent_voltage =(Vcc*average)/1024;  

/*the row above should convert the digital manipulated value to a voltage/ analogic signal again acording to the following rule:
5v - 1024        1024 x voltage = average x 5
voltage - average    voltage(Vo) = averagex 5/1024
*/
}

This pseudo-code has a comparison statement to see if the push button is pressed (1) or not (0). If yes, the led will turn on and if not (else), the led will stay turned off.

Equation of RMS

References