Mudanças entre as edições de "ESTE: GPIO and External Interrupts"

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar
(Limpou toda a página)
 
Linha 1: Linha 1:
This experiment is part of [[Embedded_Systems_Experiments_for_the_Telecommunication_Engineering_Course|this project]].
 
  
Here we are going to build a experiment with an led and a push button, using the GPIO to consolidate concepts of interrupts. A interruption is an action performed by the microcontroller that allows itself to stop doing what is being performed at the time and immediately answer the device requesting the interruption. There are two types of Interrupts requests: called from the hardware (external signal) and from the software (programming code). At this moment we are going to work with the external interrupt. Before we begin it is essential to know that external interrupts are called by hardware components, whose signal generated (HIGH and LOW) varies very fast. In order to perform a interrupt call that is regular and accurate, it’s signal must undergo a treatment that is basically the determination of a time limit to regularize the signal call. This treatment is called deboucing.
 
The exercise here proposed is to turn on and off a led each time we press the push button. To complete this experiment it is recommended to see at first the [http://wiki.sj.ifsc.edu.br/index.php/ESTE:_General_Purpose_Input_and_Output_%28GPIO%29 GPIO] script.
 
 
 
==Pseudo code==
 
 
Let's begin with a solution. The pseudo code (actual coding is up to you) is below:
 
 
<syntaxhighlight lang=c>
 
int main(void) {
 
    type_interrupt = 0;        //you can select two types of interrupt: 0 (pin 2) and 1 (pin 3);
 
    led_state = 0;                //state = 0, led is off; state =1, led is on
 
    limit_time = 200;          //limit time in ms to stabilize the calls of interruption
 
    moment = HIGH; 
 
/*here we specify when or wich moment of the signal calls the interruption. We can have the values: HIGH, LOW, CHANGE, RISING, FALLING*/
 
   
 
      while(1) {
 
        if (moment)
 
            led_change();
 
          else
 
            set_led(led, led_state); 
 
    }
 
return 0;
 
}   
 
void led_change(){
 
    if (debounce())   
 
        //invert led_state
 
}
 
int debounce(){
 
//debounce is the function responsable for stabilizing the call to interruption
 
 
    debounce_time = time_passed();    //It performs a delay
 
    if(debounce_time > limit_time)
 
        stabilazed =  1;
 
    else
 
        stabilazed = 0;
 
    return stabilazed;
 
}
 
</syntaxhighlight>
 
 
This pseudo-code always send a led_state to the led so that it atualizes his brightness acording to the states on and off. When the microcontroller detects a special “moment”, it will call the function specified to a certain type_interrupt (each type of interruption can call only one function or perform one determinated action). To truly perform the led_change() it is necessary to check if the debounce() was done correctly, because the debounce will treat all the calling signals to the interruption - commonly more then thousands calls for each second in a push button -  so that they stay regular. After the treatment of the interrupt signals, the led_state will be changed, varying between on and off.
 
 
==Schematic==
 
[[Arquivo:Led_push_button_interrupts_Esquemático.png|450px|thumb|center|Schematic of the circuit]]
 
 
==Part List==
 
*1 LED
 
*1 push button
 
*2 220 ohm resistors
 
*1 Protoboard
 
*5 copper wires (tinned) or jumpers
 
<br/>
 
 
==Assembly==
 
[[Arquivo:Led_push_button_interrupts_bb.png|450px|thumb|center|Assembly of the circuit]]
 
 
==Solutions==
 
*[C - AVR]
 
*[https://drive.google.com/open?id=0B_chZ-d1CkpCRGlGMndSYmVBdms Arduino UNO - interrupts1]
 
*[https://drive.google.com/open?id=0B_chZ-d1CkpCQW5PblZwNHNtbFk Arduino UNO - interrupts2]
 
 
==Tools==
 
*AVR GCC and tools
 
*Arduino IDE
 
 
==References==
 
*https://www.youtube.com/watch?v=bmPKQzpnCeU
 
*https://www.arduino.cc/en/Reference/AttachInterrupt
 
*http://robotics.stackexchange.com/questions/2063/unable-to-read-pushbutton-press-properly-in-arduino
 
*http://davidorlo.com/articles/arduino/arduino-%E2%80%93-interrupt-tutorial-with-led-switch
 
*http://www.instructables.com/id/Arduino-Software-debouncing-in-interrupt-function/
 
*https://www.sparkfun.com/tutorials/326
 
*http://www.engblaze.com/we-interrupt-this-program-to-bring-you-a-tutorial-on-arduino-interrupts/
 
*http://gonium.net/md/2006/12/20/handling-external-interrupts-with-arduino/
 
*http://www.embedds.com/implementing-avr-interrupts/
 
*http://www.embedds.com/basic-understanding-of-microcontroller-interrupts/
 

Edição atual tal como às 14h46min de 21 de setembro de 2015