embedded sys2
-
Upload
shubham-kaushik -
Category
Documents
-
view
216 -
download
0
description
Transcript of embedded sys2
![Page 1: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/1.jpg)
Exam
zone
![Page 2: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/2.jpg)
Intro to AVR ATtiny2313
CS423 Dick Steflik
![Page 3: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/3.jpg)
AVR ATtiny2313
![Page 4: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/4.jpg)
2313 Features
RISC, 120 instructions, most executable in one clock cycle, 32x8 general purpose registers, up to 20 MIPS at 20 Mhz
Memory - 2Kbytes Flash, 128 Bytes EEPROM, 128 bytes SRAM
Peripherals Features – 1-8bit timer, 1- 16 bit timer, 4- PWM channels, On-chip analog comparitor, watchdog timer, Universal Serial Interface, Full Duplex USART
18 programmable I/O lines
Operating Voltage – 2.7 – 5.5VDC
In System Programmable via SPI (Serial Peripheral Interface)
![Page 5: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/5.jpg)
Basic Pin Descriptions
VCC – Digital Supply Voltage
Gnd – ground
Port A (PA2..PA0) – 3 bit, bi-directional I/O with selectable internal pullups
Port B (PB7..PB0) – 8 bit, bi-directional I/O with selectable internal pullups
Port D (PD6-PD0) - 7 bit, bi-directional I/O with selectable internal pullups
Reset – system reset – active low
XTAL1 – external crystal input (alt. PA0)
XTAL2 – external crystal output (alt. PA1)
![Page 6: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/6.jpg)
Serial Peripheral Interface Bus
SPI is used by all Atmel microcontrollers for loading the flash program memory (many other OEMs also)
Easily implemented in hardware
Faster than other methods (I2C, SMBUS)
Master-slave methodology
Half or Full Duplex operation
![Page 7: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/7.jpg)
SPI with 2 slaves
SPI Master SPI Slave 1
SCLK
MISO
MOSI
SS1
SCLK
MOSI
MISO
SS
SPI Slave 2
SCLK
MOSI
MISO
SS
SS2
![Page 8: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/8.jpg)
AVR Programming
AVR Programmer ATtiny2313
SCLK
MISO
MOSI
SCLK (19)
MOSI (17)
MISO (18)
PC
PPT RS232 USB
AVRDUDE
RESET (1)
GND
GND (10) GND
VCC (20) VCC
![Page 9: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/9.jpg)
API Applications
Flash, EEPROM, MMC and SD cards
Sensors
Temperature
Pressure (touch screens)
LCD Panels
Communications (802.15 (ZigBee), CAN, Ethernet....)
Control – D/A, A/D, Digital Pots, position encoders
![Page 10: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/10.jpg)
![Page 11: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/11.jpg)
/* Blinker Demo */ /* Include useful pre-defined functions */ #include <avr/interrupt.h> // Defines pins, ports, etc to make programs easier to read #define F_CPU 100000UL // Sets up the default speed for delay.h #include <util/delay.h> int main(){ DDRD = _BV(PD4); /* enable output on port D, pin 4 */ while(1){ PORTD = _BV(PD4); _delay_ms(1000); PORTD &= ~_BV(PD4); _delay_ms(1000); } return(0); }
![Page 12: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/12.jpg)
Interrupts 1 0x0000 Reset External Pin, POR, BOR,Watchdog Reset 2 0x0001 INT0 External Interrupt Request 0 3 0x0002 INT1 External Interrupt Request 1 4 0x0003 TIMER1 CAPT Timer/Counter1 Capture Event 5 0x0004 TIMER1 COMPA Timer/Counter1 Compare Match A 6 0x0005 TIMER1 OVF Timer/Counter1 Overflow 7 0x0006 TIMER0 OVF Timer/Counter0 Overflow 8 0x0007 USART0,RX USART0 Receive complete 9 0x0008 USART0 UDRE USART0 Data Register Empty 10 0x0009 USART0 RX USART0 Transmit Complete 11 0x000A ANALOG COMP Analog Comparitor 12 0x000B PCINT Pin Change Interrupt 13 0x000C TIMER1 COMPB Timer/Counter1 Compare Match B 14 0x000D TIMER0 COMPA Timer/Counter0 Compare Match A 15 0x000E TIMER0 COMPB Timer/Counter0 Compare Match B 16 0x000F USI START USI Start Condition 17 0x0010 USI OVERFLOW USI Overflow 18 0x0011 EE READY EEPROM Ready 19 0x0012 WDT OVERFLOW Watchdog Timer Overflow
![Page 13: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/13.jpg)
ISR Macro #include <avr/interrupt.h>
Defines the beginning of your Interrupt Servicing Routine
Places the starting address of the ISR code into the interrupt vector
ISR(SIG_INT0) { cli(); //disable interrupts . . . sei(); // enable interrupts } places address of the body if the ISR into 0x0001
![Page 14: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/14.jpg)
Programmable Interrupts
INT0 - Pin 6
INT1 – Pin 7
PCINT – Pins 12-19
PCMSK – Pin Change Mask Register
Which pins contribute to the pin change interrupt
4 different pin changes can be detected
Pin goes low
Any logical change
Falling edge
Rising edge
![Page 15: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/15.jpg)
Interrupt Sense Control
Interrupt 1 Sense Control ISC11 ISC10 Description 0 0 Low level on INT1 0 1 Any logical change on INT1 1 0 Falling edge on INT1 1 1 Rising Edge on INT1
Interrupt 0 Sense Control ISC01 ISC00 Description 0 0 Low level on INT0 0 1 Any logical change on INT0 1 0 Falling edge on INT0 1 1 Rising Edge on INT0
![Page 16: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/16.jpg)
MCU Control Register
Defines which of the four states will activate the interrupt
ex. MCUCR = (1<<ISC01) | (1<<ISC00) Interrupt on pin INT0 falling edge
![Page 17: embedded sys2](https://reader036.fdocuments.in/reader036/viewer/2022081811/568bd5941a28ab203498f6b0/html5/thumbnails/17.jpg)
Example
#include <avr/interrupt.h> int main(void) { // set Pin 6 (PD02) as the interrupt pin PCMSK |= (1<<PIND2); // interrupt on INT0 falling edge MCUCR = (1<<ISC01) | (1 << ISC00); // turn on interrupts GIMSK |= (1<<INT0); // wait for interrupt while (1) { ... };