Mudanças entre as edições de "STE29008-2019-1"
Ir para navegação
Ir para pesquisar
(74 revisões intermediárias por 2 usuários não estão sendo mostradas) | |||
Linha 6: | Linha 6: | ||
*[[STE-EngTel_(Plano_de_Ensino)| Plano de Ensino]]. | *[[STE-EngTel_(Plano_de_Ensino)| Plano de Ensino]]. | ||
+ | *[http://docente.ifsc.edu.br/roberto.matos/ste_public/adm/STE2019-1_notas.pdf Notas] | ||
= 13/02/2019 – Apresentação= | = 13/02/2019 – Apresentação= | ||
Linha 37: | Linha 38: | ||
− | = 27/02/ | + | = 27/02/2019 – ADC = |
− | * | + | * Finalizar o UART mestre escravo |
+ | |||
+ | *Consulta: | ||
+ | **[http://www.lisha.ufsc.br/teaching/esl/ad.pdf ADC] | ||
+ | *Experimentos: | ||
+ | **[[ESTE:_Analog-to-Digital_Converter_(ADC)_and_Sensor_Reading | Lab 04: UART - ADC e Sensor Reading]] | ||
**[[ESTE:_Analog_Temperature_Sensor_2_(NTC_-_Negative_Temperature_Coeficient) | Lab 05: Temperature Sensor]] | **[[ESTE:_Analog_Temperature_Sensor_2_(NTC_-_Negative_Temperature_Coeficient) | Lab 05: Temperature Sensor]] | ||
+ | |||
+ | = 01/03/2019 – Interrupções = | ||
+ | |||
+ | *Desafio: | ||
+ | **Usando Round Robin sem interrupções implementar um sistema com um LED e um botão. O sistema deve piscar o LED a cada 2 segundos e ao botão ser pressionado envia uma mensagem pela serial. | ||
+ | |||
+ | *Notas de Aula: | ||
+ | **[http://www.lisha.ufsc.br/teaching/esl/esd.pdf Embedded Systems Development: Design Principles] | ||
+ | |||
+ | *Experimentos: | ||
+ | **[[ESTE:_GPIO_and_External_Interrupts_-_part_1 | Lab 06: GPIO and External Interrupts - part 1]] | ||
+ | **[[ESTE:_GPIO_and_External_Interrupts_-_part_2 | Lab 07: GPIO and External Interrupts - part 2]] | ||
+ | |||
+ | *Referências: | ||
+ | ** [https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/ attachInterrupt()] | ||
+ | ** [https://www.arduino.cc/reference/en/language/functions/time/millis/ millis()] | ||
+ | |||
+ | |||
+ | = 08/03/2019 – Usando C++= | ||
+ | |||
+ | ==Mudança de nível de abstração== | ||
+ | *Arduino Mega --> ATmega2560 (Ex.: I/O Ports) | ||
+ | *[http://docente.ifsc.edu.br/roberto.matos/ste_public/doc/sch_mega2560-original.pdf Esquemático Arduino Mega] | ||
+ | *[http://docente.ifsc.edu.br/roberto.matos/ste_public/doc/sch_mega2560-clone_CH340G.pdf Esquemático Arduino Mega - CLONE] | ||
+ | |||
+ | <!-- | ||
+ | *[https://www.arduino.cc/en/uploads/Main/arduino-mega2560-schematic.pdf Esquemático Arduino Mega] | ||
+ | *[https://robotdyn.com/pub/media/0G-00005641==MEGA-PRO-CH340GATmega2560/DOCS/Schematic==0G-00005641==MEGA-PRO-CH340GATmega2560.pdf Esquemático Arduino Mega - CLONE] | ||
+ | --> | ||
+ | |||
+ | [[Arquivo: portas_arduino_MEGA.png|800px]] | ||
+ | |||
+ | |||
+ | Fonte: https://www.arduino.cc/en/Hacking/PinMapping2560 | ||
+ | |||
+ | <!-- [[Arquivo: portas_arduino_uno.png|300px]] | ||
+ | [[Arquivo:ATmega328p_pinout.png|600px]] --> | ||
+ | |||
+ | == ATmega2560: I/O Ports== | ||
+ | *[http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf Datasheet ATmega2560] | ||
+ | *[http://docente.ifsc.edu.br/roberto.matos/ste_public/doc/datasheet_ATmega2560.pdf Datasheet ATmega2560 (local)] | ||
+ | |||
+ | *[http://www.avr-tutorials.com/digital/about-avr-8-bit-microcontrollers-digital-io-ports Resumo Portas] | ||
+ | |||
+ | |||
+ | *Tabela verdade de configuração das portas: | ||
+ | [[Arquivo:Port_Pin_Configurations.png|600px]] | ||
+ | |||
+ | |||
+ | *Endereços registradores de I/O: | ||
+ | [[Arquivo:io_registers_address_2560.png|800px]] | ||
+ | |||
+ | ==GCC, avr-libc== | ||
+ | |||
+ | ===Fluxo Ferramentas:=== | ||
+ | |||
+ | [[Arquivo:Avr-gcc.png|800px]] | ||
+ | |||
+ | |||
+ | ===AVR-LIBC:=== | ||
+ | *[https://www.nongnu.org/avr-libc/ avr-libc] | ||
+ | *[https://www.nongnu.org/avr-libc/user-manual/group__demo__project.html A simple Project] | ||
+ | |||
+ | |||
+ | ===Desenvolvimento:=== | ||
+ | * É obrigatório a instalação das ferramentas (Toolchain e o AVR-Libc). | ||
+ | * O aluno pode escolher usar o Eclipse ou montar seu próprio Makefile. | ||
+ | |||
+ | |||
+ | *Ferramentas Necessárias: | ||
+ | **[http://avr-eclipse.sourceforge.net/wiki/index.php/The_AVR_GCC_Toolchain Instalação do Toolchain e AVR-Libc] | ||
+ | |||
+ | |||
+ | * Instalação do Eclipse: | ||
+ | **[http://tele.sj.ifsc.edu.br/~arliones.hoeller/eclipse-neon2-x86_64.tar.bz2 Eclipse IDE Neon.2 para Linux 64-bits] (última atualização em 24/02/2017) - Mantido pelo [[Arliones_Hoeller | Prof. Arliones]]. | ||
+ | ** OU | ||
+ | ** [https://www.eclipse.org/cdt/ Instalação do Eclipse para C/C++] e [http://avr-eclipse.sourceforge.net/wiki/index.php/Plugin_Download Plugin dentro do Eclipse] | ||
+ | ** E | ||
+ | **[[Eclipse_AVR-LIBC | Iniciando um projeto no Eclipse usando o AVR Plugin]] | ||
+ | |||
+ | |||
+ | *Makefile: | ||
+ | **[http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/ Guia] | ||
+ | **[http://docente.ifsc.edu.br/roberto.matos/ste_public/src/Makefile Exemplo Simples] | ||
+ | **[https://gist.github.com/rynr/72734da4b8c7b962aa65 Exemplo Complexo] | ||
+ | |||
+ | ==Prática== | ||
+ | *Implemente um programa usando GCC e avr-libc para ligar um led quando um botão for pressionado ([[ESTE:_General_Purpose_Input_and_Output_(GPIO)|exemplo]]) | ||
+ | *[https://www.geeksforgeeks.org/bitwise-hacks-for-competitive-programming/ Operação de Bits em C/C++] | ||
+ | *[http://www.cplusplus.com/doc/boolean/ Operações Booleanas em C/C++] | ||
+ | *[https://www.avrfreaks.net/forum/tut-c-bit-manipulation-aka-programming-101?name=PNphpBB2&file=viewtopic&t=37871 Programming 101 - By Eric Weddington] | ||
+ | |||
+ | |||
+ | = 13/03/2019 – Não Houve Aula= | ||
+ | |||
+ | = 15/03/2019 – Usando C++ (cont.)= | ||
+ | |||
+ | ==Atividade - A1== | ||
+ | Re-implementar as seguintes atividades usando C++ e AVR-Libc: | ||
+ | *[[ESTE: General Purpose Input and Output (GPIO) | Lab 01: GPIO - Hello LED]] | ||
+ | *[[ESTE:_Universal_Assynchronous_Receiver_and_Transmitter_(UART) | Lab 02: UART - Serial Communication]] | ||
+ | *[[ESTE:_Analog-to-Digital_Converter_(ADC)_and_Sensor_Reading | Lab 04: UART - ADC e Sensor Reading]] | ||
+ | *[[ESTE:_GPIO_and_External_Interrupts_-_part_1 | Lab 06: GPIO and External Interrupts - part 1]] | ||
+ | *[[ESTE:_GPIO_and_External_Interrupts_-_part_2 | Lab 07: GPIO and External Interrupts - part 2]] | ||
+ | |||
+ | Entregar: | ||
+ | * Código fonte | ||
+ | * Relatório apresentando principais registradores utilizados para cada atividade. | ||
+ | * Usar as dicas em: [https://ww1.microchip.com/downloads/en/AppNotes/doc8453.pdf Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers] | ||
+ | |||
+ | Deadline: 31/03/2019 | ||
+ | |||
+ | = 20/03/2019 – Auxílio Atividade (Serial) = | ||
+ | * Análise dos registradores de controle | ||
+ | * Funcionamento bloqueante da Serial | ||
+ | |||
+ | |||
+ | = 22/03/2019 – Auxílio Atividade (ADC) = | ||
+ | * Análise dos registradores de controle | ||
+ | *[https://bennthomsen.wordpress.com/arduino/peripherals/analogue-input/ Resumo] | ||
+ | *[https://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html <stdlib.h>: General utilities] | ||
+ | |||
+ | = 27/03/2019 – Auxílio Atividade (Interrupção) = | ||
+ | * Revisão das funções lógicas em C/C++ | ||
+ | * Definição das funções de interrupção | ||
+ | * [https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html <avr/interrupt.h>: Interrupts] | ||
+ | |||
+ | |||
+ | * Análise comunicação serial 9600bps 8N1: | ||
+ | ** Tempo por bit = 1/9600 = ~104us | ||
+ | ** Tempo por byte (8N1) = 104us x 10 = 1,04ms | ||
+ | ** Período do clock de 16MHz = 1/16M = 62,5ns | ||
+ | ** Considerando uma instrução por ciclo de clock, temos: 16.666 instruções que podem ser executadas durante a recepção de 1 byte pela serial (9600 8N1). | ||
+ | |||
+ | |||
+ | = 03/04/2019 – Classe GPIO = | ||
+ | * Projeto GPIO | ||
+ | *[https://drive.google.com/open?id=1-Duj1Ofn1B4K1mi_MfhXVml8XcJv0AOhAhWjeak-Qf8 Mapeamento de Pinos Arduino Mega] | ||
+ | |||
+ | |||
+ | <syntaxhighlight lang=c> | ||
+ | #include <avr/io.h> | ||
+ | #include <util/delay.h> | ||
+ | #include "GPIO.h" | ||
+ | |||
+ | |||
+ | //LEDS PLACA (acende com '0') | ||
+ | GPIO led0(0, GPIO::OUTPUT); //PE0 | ||
+ | GPIO led1(1, GPIO::OUTPUT); //PE1 | ||
+ | |||
+ | //LEDS PLACA (acende com '1') | ||
+ | GPIO led13(13, GPIO::OUTPUT); //PB7 | ||
+ | |||
+ | //Adicionar LED | ||
+ | GPIO led4(4, GPIO::OUTPUT); //PG5 | ||
+ | GPIO led6(6, GPIO::OUTPUT); //PH0 | ||
+ | |||
+ | int main(void){ | ||
+ | |||
+ | UCSR0B = 0; | ||
+ | |||
+ | led0.set(1); | ||
+ | led1.set(1); | ||
+ | led6.clear(); | ||
+ | led4.clear(); | ||
+ | led13.clear(); | ||
+ | _delay_ms(1000); | ||
+ | led0.clear(); | ||
+ | led1.clear(); | ||
+ | led6.set(1); | ||
+ | led4.set(1); | ||
+ | led13.set(1); | ||
+ | _delay_ms(1000); | ||
+ | |||
+ | while (1){ | ||
+ | led0.toggle(); | ||
+ | led1.toggle(); | ||
+ | led6.toggle(); | ||
+ | led4.toggle(); | ||
+ | led13.toggle(); | ||
+ | _delay_ms(1000); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | [[Arquivo:megapdf.jpg|800px]] | ||
+ | |||
+ | = 05/04/2019 – Classe GPIO (cont.) = | ||
+ | * [http://docente.ifsc.edu.br/roberto.matos/ste_public/src/GPIO_Port.zip GPIO Port ] | ||
+ | * Análise GPIO | ||
+ | :avr-objdump -h -S <PROJECT_NAME>.elf > <PROJECT_NAME>.lst | ||
+ | |||
+ | = 10/04/2019 – Classe GPIO (cont.) = | ||
+ | * Atividade 2: | ||
+ | **Análise prática das versões passadas em sala de aula com tabela contendo o tamanho do seguinte: | ||
+ | *** Construtor | ||
+ | *** Método set(val) | ||
+ | *** Do objeto na memória de dados | ||
+ | *** Total do programa | ||
+ | *** Total dos dados | ||
+ | **Completar a classe GPIO e GPIO_port da GPIO_v2 para todos os pinos da plataforma Arduino, gerando a GPIO_v3, com os seguintes IDs: | ||
+ | ***[https://drive.google.com/open?id=1-Duj1Ofn1B4K1mi_MfhXVml8XcJv0AOhAhWjeak-Qf8 Mapeamento de Pinos Arduino Mega] | ||
+ | ** Fazer uma análise na versão GPIO_v3 com os arrays na memória RAM e forçados para memória flash com: | ||
+ | ***[https://www.nongnu.org/avr-libc/user-manual/pgmspace.html PROGMEM] | ||
+ | ** Entregar Código Fonte e Relatório contendo: | ||
+ | *** Análise prática e conceitual das versões | ||
+ | *** Discussão da implementação | ||
+ | **Essas perguntas não precisam ser respondidas como questionário e não devem limitar suas análises. | ||
+ | ***1- Por que salvar o _bit como (1 << BIT_PORTA)? É melhor do que usar diretamente (1 << BIT_PORTA)? | ||
+ | ***2- Qual tamanho do clear? Por que ele é maior e mais lento que o set? Como resolver? | ||
+ | ***3- Por que utilizar grandes vetores na memória Flash? O que isso impacta no acesso a constante? | ||
+ | ***4- Comente sobre a versão 1.2 e 1.3. Qual é menor e por quê? Quais as vantagens da v1.3? | ||
+ | ***5- Comente sobre a estratégia usada na implementação v2? | ||
+ | ***6- Qual o tamanho total dos recursos ocupados pelo atributo do objeto "GPIO" nas vesões sugeridas? | ||
+ | ***7- Qual a diferença de expandir as versões passads para todos os pinos do hardware do arduino? Como isso impactaria no "construtor" e no "set"? | ||
+ | ** Apresentar o código presencialmente | ||
+ | |||
+ | |||
+ | = (12/04/2019) – Classe UART Bloqueante = | ||
+ | |||
+ | Dúvidas A2 (Classe GPIO) | ||
+ | |||
+ | Proposta e implementação da UART Bloqueante | ||
+ | * Ler o capítulo 22 do datasheet (USART). Atenção especial as seguintes seções: | ||
+ | **"Clock Generation" | ||
+ | **"USART Initialization" | ||
+ | **"Sending Frames with 5 to 8 Data Bit" | ||
+ | **"Receiving Frames with 5 to 8 Data Bits" | ||
+ | **"Register Description" | ||
+ | |||
+ | *Diagrama de Classe: | ||
+ | http://docente.ifsc.edu.br/roberto.matos/ste_public/uml/UART_bloqueante.png | ||
+ | |||
+ | = (17/04/2019) – Classe UART com Interrupção = | ||
+ | |||
+ | Proposta e implementação da UART com interrupção: | ||
+ | * Ler manuais da AVR-LIBC: | ||
+ | ** https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html | ||
+ | ** https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__interrupts.html | ||
+ | |||
+ | * Ler o capítulo 14 do datasheet (Interrupts). | ||
+ | * Ler Seção "7.8 Reset and Interrupt Handling" | ||
+ | * Ler o capítulo 22 do datasheet (USART). Atenção especial as seguintes seções: | ||
+ | **"Transmitter Flags and Interrupts" | ||
+ | **"Receive Compete Flag and Interrupt" | ||
+ | **"Register Description" | ||
+ | *Atenção, a interrupção TXCIEn não deve ser usada - normalmente ela é utilizada apenas para implementar protocolos com reconhecimento/ack; | ||
+ | *Diagrama de Classe: | ||
+ | http://docente.ifsc.edu.br/roberto.matos/ste_public/uml/UART_interrupt.png | ||
+ | |||
+ | = (24/04/2019) – Classe UART com Interrupção (cont.) = | ||
+ | * Terminar classe com interrupção | ||
+ | * Implementar UART com interrupção e FIFO | ||
+ | |||
+ | = (26/04/2019) – Classe Interrupção Externa = | ||
+ | |||
+ | Proposta e implementação da classe de Interrupção Externa: | ||
+ | * A classe deve funcionar para as 8 interrupções externas (INTn). Não confundir com a PCINTn. | ||
+ | |||
+ | * Ler manuais da AVR-LIBC: | ||
+ | ** https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html | ||
+ | ** https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__interrupts.html | ||
+ | |||
+ | * Ler o capítulo 14 do datasheet (Interrupts). | ||
+ | * Ler Seção "7.8 Reset and Interrupt Handling" | ||
+ | * Ler o capítulo 15 do datasheet (External Interrupts). Atenção especial as seguintes seções: | ||
+ | **"Register Description" (EICRA, EICRB, EIMSK e EIFR) | ||
+ | |||
+ | *Diagrama de Classe: | ||
+ | http://docente.ifsc.edu.br/roberto.matos/ste_public/uml/ExtInt.png | ||
+ | |||
+ | |||
+ | |||
+ | <syntaxhighlight lang=c> | ||
+ | #include <avr/interrupt.h> | ||
+ | #include "extint.h" | ||
+ | #include "uart.h" | ||
+ | |||
+ | using namespace EXT_INT; | ||
+ | |||
+ | UART uart(19200, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1); | ||
+ | |||
+ | void int0_handler(void){ | ||
+ | uart.put('0'); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | void int1_handler(void){ | ||
+ | uart.put('1'); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | void int2_handler(void){ | ||
+ | uart.put('2'); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | void int3_handler(void){ | ||
+ | uart.put('3'); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | void int4_handler(void){ | ||
+ | uart.put('4'); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | void int5_handler(void){ | ||
+ | uart.put('5'); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | void int6_handler(void){ | ||
+ | uart.put('6'); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | void int7_handler(void){ | ||
+ | uart.put('7'); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | int main( void ){ | ||
+ | |||
+ | ExtInt int0_obj(ExtInt::INT_0, ExtInt::FALLING, &int0_handler); | ||
+ | ExtInt int1_obj(ExtInt::INT_1, ExtInt::FALLING, &int1_handler); | ||
+ | ExtInt int2_obj(ExtInt::INT_2, ExtInt::FALLING, &int2_handler); | ||
+ | ExtInt int3_obj(ExtInt::INT_3, ExtInt::FALLING, &int3_handler); | ||
+ | ExtInt int4_obj(ExtInt::INT_4, ExtInt::FALLING, &int4_handler); | ||
+ | ExtInt int5_obj(ExtInt::INT_5, ExtInt::FALLING, &int5_handler); | ||
+ | ExtInt int6_obj(ExtInt::INT_6, ExtInt::FALLING, &int6_handler); | ||
+ | ExtInt int7_obj(ExtInt::INT_7, ExtInt::FALLING, &int7_handler); | ||
+ | |||
+ | int0_obj.enable(); | ||
+ | int1_obj.enable(); | ||
+ | int2_obj.enable(); | ||
+ | int3_obj.enable(); | ||
+ | int4_obj.enable(); | ||
+ | int5_obj.enable(); | ||
+ | int6_obj.enable(); | ||
+ | int7_obj.enable(); | ||
+ | |||
+ | sei(); | ||
+ | while(1){ /* forever */ | ||
+ | if (uart.has_data()){ | ||
+ | uart.put(uart.get()); /* echo the received character */ | ||
+ | uart.put((EICRA)); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | = (03/05/2018) – Timer e Timeouts = | ||
+ | |||
+ | * Leitura capítulo 16 ("8-bit Timer/Counter0 with PWM"). | ||
+ | *Adaptar e testar a classe timer fornecida para o Atmega2560: | ||
+ | **[http://docente.ifsc.edu.br/roberto.matos/ste_public/src/Timer.zip Classe Timer] | ||
+ | **[https://pt.wikipedia.org/wiki/Singleton Singleton] | ||
+ | |||
+ | *Implementar a classe Timeout e e inserir os métodos "TimeoutManager" e "addTimeout" na classe Timer: | ||
+ | http://docente.ifsc.edu.br/roberto.matos/ste_public/uml/timeouts.png | ||
+ | |||
+ | = (08/05/2018) – Apoio nas implementações = | ||
+ | |||
+ | |||
+ | == Definição A3 == | ||
+ | * Serial: | ||
+ | ** Adicionar uma implementação de FIFO | ||
+ | ** Adicionar a configuração double speed no construtor | ||
+ | ** Adicionar o puts (envio de strings) | ||
+ | ** A classe serial deve ser genérica e com a possibilidade de mapear para qualquer uma das seriais do ATmega2560. | ||
+ | |||
+ | * Interrupção externa: | ||
+ | ** Criar uma classe para tratar eventos não "prioritários" usando a PCINT | ||
+ | ** Gerenciador de interrupções para adicionar no programa principal | ||
+ | |||
+ | * Timeout: | ||
+ | ** Re-fatorar a classe implementada de forma que o usuário final crie o objeto "timeout" e registre no objeto "Timer". Usar a associação "friend". | ||
+ | ** Fazer uma análise entre a classe original e a re-fatorada no uso de dois timeouts. | ||
+ | |||
+ | * Entrega: | ||
+ | ** Implementar programas que testem as classes amplamente baseados nos requisitos | ||
+ | ** Modelar a classe em UML | ||
+ | ** Entregar todas as versões trabalhadas em sala de aula com programas testes | ||
+ | ** Discutir a abordagem da extensão das classes | ||
+ | ** Apresentar e defender individualmente as implementações | ||
+ | |||
+ | * Data da Entrega: 26/05/2019 | ||
+ | * Adiado para: 02/06/2019 | ||
+ | |||
+ | = Aula 15/05/2019: Não houve aula – Paralisação Nacional = | ||
+ | |||
+ | = Aula 17/05/2019: Apoio A3 (cont.) = | ||
+ | |||
+ | |||
+ | = Aula 22/05/2019: Projeto Final e A3 = | ||
+ | |||
+ | * Simular uma FXO para testar projetos de centrais telefônicas (FXS) | ||
+ | ** Ter uma sequência predefinida para teste sem programação, por exemplo, “tira do gancho”, 0, 1, 2, 3, 4, ..., *, #, “volta gancho” | ||
+ | ** Permitir cadastrar até duas sequências programáveis de tons DTMF via o teclado. Essas sequências devem ser persistentes (gravadas em EEPROM). | ||
+ | ** Permitir o modo "online" de envio | ||
+ | ** Implementar uma interface de saída (LCD e LEDs) para informar sobre os modos de operação e sobre o andamento do teste. | ||
+ | ** Mensagens durante o teste devem ser enviadas via serial para Debug. | ||
+ | ** O sistema tem que se conectar de fato a uma FXS e funcionar | ||
+ | |||
+ | *Três abordagens possíveis: | ||
+ | ** Implementar a geração do DTMF no AVR (Precisa fazer o circuito de conexão, [http://electronics-diy.com/electronic_schematic.php?id=597 por exemplo]) | ||
+ | ** Usar um CI [https://www.microsemi.com/document-portal/doc_view/127042-mt8880c-datasheet-sep2005 MT8880C] para gerar o DTMF (Precisa fazer o circuito de conexão, [http://electronics-diy.com/electronic_schematic.php?id=597 por exemplo]) | ||
+ | ** Hackear um telefone. Por exemplo, Telefone Premium da Intelbras: [http://docente.ifsc.edu.br/roberto.matos/ste_public/apostila_telefonia1_premium.pdf Apostila Telefonia - Capítulo 4] e [https://wiki.sj.ifsc.edu.br/images/1/19/HM91710.pdf CI HM91710] | ||
+ | |||
+ | *Cronograma: | ||
+ | **14/06/2019: Apresentação dos diagramas preliminares | ||
+ | **03/07/2019: Última aula de dúvidas | ||
+ | **04/07/2019: Prazo final para entrega dos códigos/diagramas finais (pelo SIGAA) | ||
+ | **05/07/2019: Apresentação/teste do projeto presencial em sala de aula. | ||
+ | |||
+ | * Mais informações sobre DTMF: | ||
+ | ** Esquemático Telefone Premium: | ||
+ | [[Arquivo:Premium744.jpg|800px]] | ||
+ | |||
+ | :* Esquemático teste (Prof. Fábio): | ||
+ | [[Arquivo:Dialer.jpg|500px]] | ||
+ | |||
+ | = Aula 24/05/2019: Implementação A3 e PF = | ||
+ | |||
+ | = Aula 29/05/2019: Implementação A3 e PF = | ||
+ | |||
+ | * Sugestão código para testar a serial: | ||
+ | <syntaxhighlight lang=c> | ||
+ | #include <avr/io.h> | ||
+ | #include <avr/interrupt.h> | ||
+ | #include <util/delay.h> | ||
+ | #include <stdlib.h> | ||
+ | #include "UART.h" | ||
+ | |||
+ | //using namespace UART; | ||
+ | |||
+ | char you_send[] = "You send through UART : \n"; | ||
+ | char echo[] = "Echo: \n"; | ||
+ | |||
+ | int main(void) { | ||
+ | |||
+ | UART uart0(9600, UART::UART0, UART::DOUBLE_FALSE, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1); | ||
+ | UART uart1(9600, UART::UART1, UART::DOUBLE_FALSE, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1); | ||
+ | UART uart2(9600, UART::UART2, UART::DOUBLE_FALSE, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1); | ||
+ | UART uart3(9600, UART::UART3, UART::DOUBLE_FALSE, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1); | ||
+ | |||
+ | |||
+ | sei(); | ||
+ | |||
+ | uint8_t input; | ||
+ | for (;;) { | ||
+ | if (uart0.has_data()) { | ||
+ | input = uart0.get(); | ||
+ | |||
+ | echo[6] = input; | ||
+ | uart0.puts(echo); | ||
+ | |||
+ | you_send[21] = '0'; | ||
+ | you_send[24] = input; | ||
+ | |||
+ | uart1.puts(you_send); | ||
+ | uart2.puts(you_send); | ||
+ | uart3.puts(you_send); | ||
+ | } | ||
+ | |||
+ | if (uart1.has_data()) { | ||
+ | input = uart1.get(); | ||
+ | |||
+ | echo[6] = input; | ||
+ | uart1.puts(echo); | ||
+ | |||
+ | you_send[21] = '1'; | ||
+ | you_send[24] = input; | ||
+ | |||
+ | uart0.puts(you_send); | ||
+ | uart2.puts(you_send); | ||
+ | uart3.puts(you_send); | ||
+ | } | ||
+ | |||
+ | if (uart2.has_data()) { | ||
+ | input = uart2.get(); | ||
+ | |||
+ | echo[6] = input; | ||
+ | uart2.puts(echo); | ||
+ | |||
+ | you_send[21] = '2'; | ||
+ | you_send[24] = input; | ||
+ | |||
+ | uart0.puts(you_send); | ||
+ | uart1.puts(you_send); | ||
+ | uart3.puts(you_send); | ||
+ | } | ||
+ | |||
+ | if (uart3.has_data()) { | ||
+ | input = uart3.get(); | ||
+ | |||
+ | echo[6] = input; | ||
+ | uart3.puts(echo); | ||
+ | |||
+ | you_send[21] = '3'; | ||
+ | you_send[24] = input; | ||
+ | |||
+ | uart0.puts(you_send); | ||
+ | uart1.puts(you_send); | ||
+ | uart2.puts(you_send); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> |
Edição atual tal como às 21h46min de 8 de setembro de 2019
Sistemas Embarcados
- Professor: Roberto de Matos
- Encontros: quartas às 13:30h e sextas às 15:40h no Laboratório CAD 1.
13/02/2019 – Apresentação
- Apresentação do professor.
- Apresentação da disciplina.
- 2017 Embedded Markets Study
15/02/2019 – Introdução
- Notas de Aula:
20/02/2019 – Experimento GPIO
- Experimentos:
22/02/2019 – Experimento UART
27/02/2019 – ADC
- Finalizar o UART mestre escravo
- Consulta:
- Experimentos:
01/03/2019 – Interrupções
- Desafio:
- Usando Round Robin sem interrupções implementar um sistema com um LED e um botão. O sistema deve piscar o LED a cada 2 segundos e ao botão ser pressionado envia uma mensagem pela serial.
- Notas de Aula:
- Experimentos:
- Referências:
08/03/2019 – Usando C++
Mudança de nível de abstração
- Arduino Mega --> ATmega2560 (Ex.: I/O Ports)
- Esquemático Arduino Mega
- Esquemático Arduino Mega - CLONE
Fonte: https://www.arduino.cc/en/Hacking/PinMapping2560
ATmega2560: I/O Ports
- Tabela verdade de configuração das portas:
- Endereços registradores de I/O:
GCC, avr-libc
Fluxo Ferramentas:
AVR-LIBC:
Desenvolvimento:
- É obrigatório a instalação das ferramentas (Toolchain e o AVR-Libc).
- O aluno pode escolher usar o Eclipse ou montar seu próprio Makefile.
- Ferramentas Necessárias:
- Instalação do Eclipse:
- Eclipse IDE Neon.2 para Linux 64-bits (última atualização em 24/02/2017) - Mantido pelo Prof. Arliones.
- OU
- Instalação do Eclipse para C/C++ e Plugin dentro do Eclipse
- E
- Iniciando um projeto no Eclipse usando o AVR Plugin
- Makefile:
Prática
- Implemente um programa usando GCC e avr-libc para ligar um led quando um botão for pressionado (exemplo)
- Operação de Bits em C/C++
- Operações Booleanas em C/C++
- Programming 101 - By Eric Weddington
13/03/2019 – Não Houve Aula
15/03/2019 – Usando C++ (cont.)
Atividade - A1
Re-implementar as seguintes atividades usando C++ e AVR-Libc:
- Lab 01: GPIO - Hello LED
- Lab 02: UART - Serial Communication
- Lab 04: UART - ADC e Sensor Reading
- Lab 06: GPIO and External Interrupts - part 1
- Lab 07: GPIO and External Interrupts - part 2
Entregar:
- Código fonte
- Relatório apresentando principais registradores utilizados para cada atividade.
- Usar as dicas em: Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers
Deadline: 31/03/2019
20/03/2019 – Auxílio Atividade (Serial)
- Análise dos registradores de controle
- Funcionamento bloqueante da Serial
22/03/2019 – Auxílio Atividade (ADC)
- Análise dos registradores de controle
- Resumo
- <stdlib.h>: General utilities
27/03/2019 – Auxílio Atividade (Interrupção)
- Revisão das funções lógicas em C/C++
- Definição das funções de interrupção
- <avr/interrupt.h>: Interrupts
- Análise comunicação serial 9600bps 8N1:
- Tempo por bit = 1/9600 = ~104us
- Tempo por byte (8N1) = 104us x 10 = 1,04ms
- Período do clock de 16MHz = 1/16M = 62,5ns
- Considerando uma instrução por ciclo de clock, temos: 16.666 instruções que podem ser executadas durante a recepção de 1 byte pela serial (9600 8N1).
03/04/2019 – Classe GPIO
- Projeto GPIO
- Mapeamento de Pinos Arduino Mega
#include <avr/io.h>
#include <util/delay.h>
#include "GPIO.h"
//LEDS PLACA (acende com '0')
GPIO led0(0, GPIO::OUTPUT); //PE0
GPIO led1(1, GPIO::OUTPUT); //PE1
//LEDS PLACA (acende com '1')
GPIO led13(13, GPIO::OUTPUT); //PB7
//Adicionar LED
GPIO led4(4, GPIO::OUTPUT); //PG5
GPIO led6(6, GPIO::OUTPUT); //PH0
int main(void){
UCSR0B = 0;
led0.set(1);
led1.set(1);
led6.clear();
led4.clear();
led13.clear();
_delay_ms(1000);
led0.clear();
led1.clear();
led6.set(1);
led4.set(1);
led13.set(1);
_delay_ms(1000);
while (1){
led0.toggle();
led1.toggle();
led6.toggle();
led4.toggle();
led13.toggle();
_delay_ms(1000);
}
}
05/04/2019 – Classe GPIO (cont.)
- GPIO Port
- Análise GPIO
- avr-objdump -h -S <PROJECT_NAME>.elf > <PROJECT_NAME>.lst
10/04/2019 – Classe GPIO (cont.)
- Atividade 2:
- Análise prática das versões passadas em sala de aula com tabela contendo o tamanho do seguinte:
- Construtor
- Método set(val)
- Do objeto na memória de dados
- Total do programa
- Total dos dados
- Completar a classe GPIO e GPIO_port da GPIO_v2 para todos os pinos da plataforma Arduino, gerando a GPIO_v3, com os seguintes IDs:
- Fazer uma análise na versão GPIO_v3 com os arrays na memória RAM e forçados para memória flash com:
- Entregar Código Fonte e Relatório contendo:
- Análise prática e conceitual das versões
- Discussão da implementação
- Essas perguntas não precisam ser respondidas como questionário e não devem limitar suas análises.
- 1- Por que salvar o _bit como (1 << BIT_PORTA)? É melhor do que usar diretamente (1 << BIT_PORTA)?
- 2- Qual tamanho do clear? Por que ele é maior e mais lento que o set? Como resolver?
- 3- Por que utilizar grandes vetores na memória Flash? O que isso impacta no acesso a constante?
- 4- Comente sobre a versão 1.2 e 1.3. Qual é menor e por quê? Quais as vantagens da v1.3?
- 5- Comente sobre a estratégia usada na implementação v2?
- 6- Qual o tamanho total dos recursos ocupados pelo atributo do objeto "GPIO" nas vesões sugeridas?
- 7- Qual a diferença de expandir as versões passads para todos os pinos do hardware do arduino? Como isso impactaria no "construtor" e no "set"?
- Apresentar o código presencialmente
- Análise prática das versões passadas em sala de aula com tabela contendo o tamanho do seguinte:
(12/04/2019) – Classe UART Bloqueante
Dúvidas A2 (Classe GPIO)
Proposta e implementação da UART Bloqueante
- Ler o capítulo 22 do datasheet (USART). Atenção especial as seguintes seções:
- "Clock Generation"
- "USART Initialization"
- "Sending Frames with 5 to 8 Data Bit"
- "Receiving Frames with 5 to 8 Data Bits"
- "Register Description"
- Diagrama de Classe:
(17/04/2019) – Classe UART com Interrupção
Proposta e implementação da UART com interrupção:
- Ler manuais da AVR-LIBC:
- Ler o capítulo 14 do datasheet (Interrupts).
- Ler Seção "7.8 Reset and Interrupt Handling"
- Ler o capítulo 22 do datasheet (USART). Atenção especial as seguintes seções:
- "Transmitter Flags and Interrupts"
- "Receive Compete Flag and Interrupt"
- "Register Description"
- Atenção, a interrupção TXCIEn não deve ser usada - normalmente ela é utilizada apenas para implementar protocolos com reconhecimento/ack;
- Diagrama de Classe:
(24/04/2019) – Classe UART com Interrupção (cont.)
- Terminar classe com interrupção
- Implementar UART com interrupção e FIFO
(26/04/2019) – Classe Interrupção Externa
Proposta e implementação da classe de Interrupção Externa:
- A classe deve funcionar para as 8 interrupções externas (INTn). Não confundir com a PCINTn.
- Ler manuais da AVR-LIBC:
- Ler o capítulo 14 do datasheet (Interrupts).
- Ler Seção "7.8 Reset and Interrupt Handling"
- Ler o capítulo 15 do datasheet (External Interrupts). Atenção especial as seguintes seções:
- "Register Description" (EICRA, EICRB, EIMSK e EIFR)
- Diagrama de Classe:
#include <avr/interrupt.h>
#include "extint.h"
#include "uart.h"
using namespace EXT_INT;
UART uart(19200, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1);
void int0_handler(void){
uart.put('0');
return;
}
void int1_handler(void){
uart.put('1');
return;
}
void int2_handler(void){
uart.put('2');
return;
}
void int3_handler(void){
uart.put('3');
return;
}
void int4_handler(void){
uart.put('4');
return;
}
void int5_handler(void){
uart.put('5');
return;
}
void int6_handler(void){
uart.put('6');
return;
}
void int7_handler(void){
uart.put('7');
return;
}
int main( void ){
ExtInt int0_obj(ExtInt::INT_0, ExtInt::FALLING, &int0_handler);
ExtInt int1_obj(ExtInt::INT_1, ExtInt::FALLING, &int1_handler);
ExtInt int2_obj(ExtInt::INT_2, ExtInt::FALLING, &int2_handler);
ExtInt int3_obj(ExtInt::INT_3, ExtInt::FALLING, &int3_handler);
ExtInt int4_obj(ExtInt::INT_4, ExtInt::FALLING, &int4_handler);
ExtInt int5_obj(ExtInt::INT_5, ExtInt::FALLING, &int5_handler);
ExtInt int6_obj(ExtInt::INT_6, ExtInt::FALLING, &int6_handler);
ExtInt int7_obj(ExtInt::INT_7, ExtInt::FALLING, &int7_handler);
int0_obj.enable();
int1_obj.enable();
int2_obj.enable();
int3_obj.enable();
int4_obj.enable();
int5_obj.enable();
int6_obj.enable();
int7_obj.enable();
sei();
while(1){ /* forever */
if (uart.has_data()){
uart.put(uart.get()); /* echo the received character */
uart.put((EICRA));
}
}
return 0;
}
(03/05/2018) – Timer e Timeouts
- Leitura capítulo 16 ("8-bit Timer/Counter0 with PWM").
- Adaptar e testar a classe timer fornecida para o Atmega2560:
- Implementar a classe Timeout e e inserir os métodos "TimeoutManager" e "addTimeout" na classe Timer:
(08/05/2018) – Apoio nas implementações
Definição A3
- Serial:
- Adicionar uma implementação de FIFO
- Adicionar a configuração double speed no construtor
- Adicionar o puts (envio de strings)
- A classe serial deve ser genérica e com a possibilidade de mapear para qualquer uma das seriais do ATmega2560.
- Interrupção externa:
- Criar uma classe para tratar eventos não "prioritários" usando a PCINT
- Gerenciador de interrupções para adicionar no programa principal
- Timeout:
- Re-fatorar a classe implementada de forma que o usuário final crie o objeto "timeout" e registre no objeto "Timer". Usar a associação "friend".
- Fazer uma análise entre a classe original e a re-fatorada no uso de dois timeouts.
- Entrega:
- Implementar programas que testem as classes amplamente baseados nos requisitos
- Modelar a classe em UML
- Entregar todas as versões trabalhadas em sala de aula com programas testes
- Discutir a abordagem da extensão das classes
- Apresentar e defender individualmente as implementações
- Data da Entrega: 26/05/2019
- Adiado para: 02/06/2019
Aula 15/05/2019: Não houve aula – Paralisação Nacional
Aula 17/05/2019: Apoio A3 (cont.)
Aula 22/05/2019: Projeto Final e A3
- Simular uma FXO para testar projetos de centrais telefônicas (FXS)
- Ter uma sequência predefinida para teste sem programação, por exemplo, “tira do gancho”, 0, 1, 2, 3, 4, ..., *, #, “volta gancho”
- Permitir cadastrar até duas sequências programáveis de tons DTMF via o teclado. Essas sequências devem ser persistentes (gravadas em EEPROM).
- Permitir o modo "online" de envio
- Implementar uma interface de saída (LCD e LEDs) para informar sobre os modos de operação e sobre o andamento do teste.
- Mensagens durante o teste devem ser enviadas via serial para Debug.
- O sistema tem que se conectar de fato a uma FXS e funcionar
- Três abordagens possíveis:
- Implementar a geração do DTMF no AVR (Precisa fazer o circuito de conexão, por exemplo)
- Usar um CI MT8880C para gerar o DTMF (Precisa fazer o circuito de conexão, por exemplo)
- Hackear um telefone. Por exemplo, Telefone Premium da Intelbras: Apostila Telefonia - Capítulo 4 e CI HM91710
- Cronograma:
- 14/06/2019: Apresentação dos diagramas preliminares
- 03/07/2019: Última aula de dúvidas
- 04/07/2019: Prazo final para entrega dos códigos/diagramas finais (pelo SIGAA)
- 05/07/2019: Apresentação/teste do projeto presencial em sala de aula.
- Mais informações sobre DTMF:
- Esquemático Telefone Premium:
- Esquemático teste (Prof. Fábio):
Aula 24/05/2019: Implementação A3 e PF
Aula 29/05/2019: Implementação A3 e PF
- Sugestão código para testar a serial:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdlib.h>
#include "UART.h"
//using namespace UART;
char you_send[] = "You send through UART : \n";
char echo[] = "Echo: \n";
int main(void) {
UART uart0(9600, UART::UART0, UART::DOUBLE_FALSE, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1);
UART uart1(9600, UART::UART1, UART::DOUBLE_FALSE, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1);
UART uart2(9600, UART::UART2, UART::DOUBLE_FALSE, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1);
UART uart3(9600, UART::UART3, UART::DOUBLE_FALSE, UART::DATABITS_8, UART::NONE, UART::STOPBIT_1);
sei();
uint8_t input;
for (;;) {
if (uart0.has_data()) {
input = uart0.get();
echo[6] = input;
uart0.puts(echo);
you_send[21] = '0';
you_send[24] = input;
uart1.puts(you_send);
uart2.puts(you_send);
uart3.puts(you_send);
}
if (uart1.has_data()) {
input = uart1.get();
echo[6] = input;
uart1.puts(echo);
you_send[21] = '1';
you_send[24] = input;
uart0.puts(you_send);
uart2.puts(you_send);
uart3.puts(you_send);
}
if (uart2.has_data()) {
input = uart2.get();
echo[6] = input;
uart2.puts(echo);
you_send[21] = '2';
you_send[24] = input;
uart0.puts(you_send);
uart1.puts(you_send);
uart3.puts(you_send);
}
if (uart3.has_data()) {
input = uart3.get();
echo[6] = input;
uart3.puts(echo);
you_send[21] = '3';
you_send[24] = input;
uart0.puts(you_send);
uart1.puts(you_send);
uart2.puts(you_send);
}
}
}