Top Banner
INTERRUPTIONS LE MICROCONTROLEUR
42

LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Jun 27, 2018

Download

Documents

truongdieu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

INTERRUPTIONS

LE MICROCONTROLEUR

Page 2: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, pourquoi?

Comment faire plusieurs

choses à la fois?

Page 3: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, types

● Timer○ “Je veux faire quelque chose dans 100*x

ms pour N fois”○ setTimer(fonction, x, N)

● External○ “Je veux faire quelque chose quand une

valeur mesurée change”○ attachInterrupt(interrupt, fonction, quand)

Page 4: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, the Arduino way:attachInterrupt (Prismino ~= Leonardo)

#define LED_PIN 13;volatile int state = LOW;

void setup(){ pinMode(LED_PIN, OUTPUT); attachInterrupt(0, blink, CHANGE); // LOW, RISING, FALLING, CHANGE}

void loop(){ digitalWrite(LED_PIN, state);}

void blink(){ state = !state;}

Page 5: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, demo● Jouer de la musique

● Suivre une ligne

Page 6: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, demo● Jouer de la musique

○ Interruption àchaque change-ment de la valeurde sortie

● Suivre une ligne○ Interruption chaque

fois que le senseurne voit plus la ligne

Page 7: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, demovoid setup(){ //Update motor speeds when line is lost/found attachInterrupt(IR_PIN, follow_line, CHANGE);}

void loop(){ play_music();}

Page 8: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, demovoid setup(){ //Call the play_note function every 2*100ms setTimer(play_note, 2, 0);}

void loop(){ follow_line(); delay(10);}

void play_note(){

// play_note code}

TIMER: 10ms

Page 9: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, demovoid setup(){ //Call the play_note function every 2*100ms setTimer(play_note, 2, 0);}

void loop(){ follow_line(); delay(10);}

void play_note(){

// play_note code}

TIMER: 20ms

Page 10: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, demovoid setup(){ //Call the play_note function every 2*100ms setTimer(play_note, 2, 0);}

void loop(){ follow_line(); delay(10);}

void play_note(){

// play_note code}

TIMER: 30ms

Page 11: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, demovoid setup(){ //Call the play_note function every 2*100ms setTimer(play_note, 2, 0);}

void loop(){ follow_line(); delay(10);}

void play_note(){

// play_note code}

TIMER: 200ms

Page 12: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, demovoid setup(){ //Call the play_note function every 2*100ms setTimer(play_note, 2, 0);}

void loop(){ follow_line(); delay(10);}

void play_note(){

// play_note code}

TIMER: 210ms

Page 13: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

INTERRUPTIONS

LE MICROCONTROLEUR

Page 14: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Il y a quoi dedans?

Ou, les datasheets

Atmel AtMega32U4 datasheet http://www.atmel.com/Images/doc7766.pdf

Hard disk RAM

Page 15: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Mon PC

● N’est pas un Personal Computer

● Plutôt, un Program Counter

● Marque/compte quelle ligne de code/instruction est à executer

● Au reset, PC = $0x0000

● $ → Adresse, 0x → hexadecimal

Page 16: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x00000

0x011ee

0x01422

Data Address

Contient l’adresse du debut du programme

Page 17: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x002a3

0x011ee

0x01422

Data Address

Page 18: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x002a4

0x011ee

0x01422

Data Address

Page 19: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x002a5

0x011ee

0x01422

Data Address

Page 20: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x00...

0x011ee

0x01422

Data Address

...

Page 21: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x0042c

0x011ee

0x01422

Data Address

Appel fonction!!

Page 22: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x011ee

0x011ee

0x01422

Data Address

Page 23: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x0....

0x011ee

0x01422

Data Address

...

Page 24: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x01422

0x011ee

0x01422

Data Address

Page 25: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x0042d

0x011ee

0x01422

Data Address

Page 26: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, the hard way!

Atmel AtMega32U4 datasheet http://www.atmel.com/Images/doc7766.pdf on page 61 and 87

Example pour interruption externe numero 3

Page 27: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions, the hard way!

ISR(INT3_vect){ // Your interrupt code}

Atmel AtMega32U4 datasheet http://www.atmel.com/Images/doc7766.pdf on page 61 and 87

int main(void){ // Your init

asm(“cli”); // disable global interruptEIMSK |= (1 << INT3);// EIMSK |= 0b00001000; equivalentasm(“sei”); // enable global interrupt

}

Page 28: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme - Interruption!

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x00000

0x011ee

0x01422

Data Address

Contient l’adresse du debut du programme

INTERRUPT TABLE

Interruption (N3)

0x015e3

0x0160f

Page 29: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme - Interruption!

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x002a3

0x011ee

0x01422

Data Address

INTERRUPT TABLE

Interruption (N3)

0x015e3

0x0160f

Page 30: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme - Interruption!

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x002a4

0x011ee

0x01422

Data Address

INTERRUPT TABLE

Interruption (N3)

0x015e3

0x0160f

Page 31: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme - Interruption!

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x002a5

0x011ee

0x01422

Data Address

INTERRUPT TABLE

Interruption (N3)

0x015e3

0x0160f

Page 32: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme - Interruption!

PC = 0x002a- PIN CHANGE! External World

Dans ce cas, onadmet c’estl’interruptionnumero 3

Page 33: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme - Interruption!

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x00008

0x011ee

0x01422

Data Address

INTERRUPT TABLE

Interruption (N3)

0x015e3

0x0160f

Page 34: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme - Interruption!

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x015e3

0x011ee

0x01422

Data Address

INTERRUPT TABLE

Interruption (N3)

0x015e3

0x0160f

Page 35: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme - Interruption!

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x0160f

0x011ee

0x01422

Data Address

INTERRUPT TABLE

Interruption (N3)

0x015e3

0x0160f

Page 36: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Memoire programme - Interruption!

RESET

Main program

0x002a3

0x005f1

Some function

PC = 0x002a6

0x011ee

0x01422

Data Address

INTERRUPT TABLE

Interruption (N3)

0x015e3

0x0160f

Page 37: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Interruptions

● En C: Ne pas oublier de les activer!● Ligne en C: asm(“sei”);● Activer les interruptions APRES les avoir

attachés/declarés

● Pour desactiver? ● Ligne en C: asm(“cli”);

● Arduino: attachInterrupt & detachInterrupt

Page 38: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Remarque moteurs

NE marche PAS Fonctionne

Page 39: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

Prochains évenements

Lundi 25 novembreInvité: Steven, avec des QUADCOPTERS!

Page 40: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

???

Page 41: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

PROFIT!

Lundi 25 novembreInvité: Steven, avec des QUADCOPTERS!

Lundi 2 decembrePresentation reglès grand concours

Dimanche 6 avril 2014 Grand concours! Pendant l’inauguration du convention center

Page 42: LE MICROCONTROLEUR INTERRUPTIONS - Robopoly | … · Interruptions, types Timer ... Hard disk RAM. Mon PC N’est pas un Personal Computer ... Dimanche 6 avril 2014 Grand concours!

FINQuestions?