Mudanças entre as edições de "ESTE: Analog-to-Digital Converter (ADC) and Sensor Reading"

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar
Linha 25: Linha 25:
  
 
void RMS(){
 
void RMS(){
     average = accumulated / repeat;          //here we have a general example of an average. RMS instead, is given by the "Equation of 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;   
 
     equivalent_voltage =(Vcc*average)/1024;   
  
Linha 34: Linha 34:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
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.
+
This pseudo-code show some functions to perform: the accumulation necessary to the average; the calculation of a precise average (RMS); the conversion from analogic signal to digital values and back. These are the elements necessary to start reading any tipe of sensor amog other applications.
  
[[Arquivo:Equation_RMS.png|600px|thumb|center|Equation of RMS]]
+
[[Arquivo:Equation_RMS.png|600px|thumb|center|¹Equation of RMS]]
  
 
==References==
 
==References==
 
*[https://pt.wikipedia.org/wiki/Conversor_anal%C3%B3gico-digital ADC]
 
*[https://pt.wikipedia.org/wiki/Conversor_anal%C3%B3gico-digital ADC]
 
*[https://pt.wikipedia.org/wiki/Valor_eficaz RMS Average]
 
*[https://pt.wikipedia.org/wiki/Valor_eficaz RMS Average]

Edição das 14h11min de 23 de setembro de 2015

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. For example, if we presume an ADC input signal of 2.5V, 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, 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 show some functions to perform: the accumulation necessary to the average; the calculation of a precise average (RMS); the conversion from analogic signal to digital values and back. These are the elements necessary to start reading any tipe of sensor amog other applications.

¹Equation of RMS

References