Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lecture 1: Embedded Systems Overview, AVR Hardware/Software Introduction.

Similar presentations


Presentation on theme: "1 Lecture 1: Embedded Systems Overview, AVR Hardware/Software Introduction."— Presentation transcript:

1 1 Lecture 1: Embedded Systems Overview, AVR Hardware/Software Introduction

2 2 Embedded Systems Overview Computing systems are everywhere Most of us think of “desktop” computers –PC’s –Laptops –Mainframes –Servers But there’s another type of computing system –Far more common...

3 3 Embedded Systems Overview Embedded computing systems –Computing systems embedded within electronic devices –Hard to define. Nearly any computing system other than a desktop computer –Billions of units produced yearly, versus millions of desktop units –Perhaps 50 per household and per automobile Computers are in here... and here... and even here... Lots more of these, though they cost a lot less each.

4 4 A “short list” of embedded systems And the list goes on and on Anti-lock brakes Auto-focus cameras Automatic teller machines Automatic toll systems Automatic transmission Avionic systems Battery chargers Camcorders Cell phones Cell-phone base stations Cordless phones Cruise control Curbside check-in systems Digital cameras Disk drives Electronic card readers Electronic instruments Electronic toys/games Factory control Fax machines Fingerprint identifiers Home security systems Life-support systems Medical testing systems Modems MPEG decoders Network cards Network switches/routers On-board navigation Pagers Photocopiers Point-of-sale systems Portable video games Printers Satellite phones Scanners Smart ovens/dishwashers Speech recognizers Stereo systems Teleconferencing systems Televisions Temperature controllers Theft tracking systems TV set-top boxes VCR’s, DVD players Video game consoles Video phones Washers and dryers

5 5 What is an embedded system? What makes a microcontroller: – Self Contained CPU Memory I/O – Application or Task Specific Not a general-purpose computer Appropriately scaled for the job

6 6 What is an embedded system? Embedded PCs? “Soft” Processors on PLDs? Systems On A Chip?

7 7 Designing Embedded Systems Microcontrollers – Don’t have keyboard and monitor jacks – Must use ports to perform I/O Inputs – to sense things Outputs – to control things Related Component Topics – Common Interfaces – Part Packages

8 8 What you will do: Labs –Lab 1: Introduction to AVR STK500 Hardware/Software, a couple of simple c programs –Lab 2: A/D converter –Lab 3: Optical Sensors –Lab 4: 2 bits D/A converter –Lab 5: Controls and Feedback –Lab 6: Motor Control - open loop –Lab 7: Motor Control - simple feedback control –Lab 8: Motor Control - proportional feedback control

9 9 What you will do: Presentation – your proposed project Final Project –Hardware –Software –Presentation –Report

10 10 Introduction to AVR CodeVision AVR C Compiler Professional version –Installed in 20 PCs in room EN229 –Compile programs with more than a thousand instructions. –Provides many useful assembly programs used by your C programs. You write your programs in C completely. AVR C compiler will integrate all required programs together –More about AVR C compiler when presenting Lab 1

11 11 Introduction to AVR

12 12 Used in Lab

13 13 AVR Architecture What are the features of RISC? – 1 instruction per clock cycle (pipelined) – Lots of registers: 32 GP registers – Register-to-register operation Variations in the parts: – TINY to MEGA – ATtiny10 Processor has only 8 pins – ATmega128 (128K bytes flash) Processor has 64 pins

14 14 AVR Architecture

15 15 AVR RISC Architecture Single Cycle Instructions: 8mhz = 8mips. Large register file (32). Every register an accumulator. 3 index register pairs Register & IO are mapped in SRAM space.

16 16 On Chip Debug Serial Peripheral Interface Two Wire Interface

17 17

18 18 Typical Hardware Support Internal or External Oscillator/Clock Brown Out Detector One or more timers Two or more PWM One or more USART 10 bit ADC Analog Comparator External interrupts

19 19

20 20

21 21 AREF is analog ref. pin for A/D converter AVCC is connected to Vcc or through a low pass filter to Vcc

22 22

23 23 AVCC and AREF properly connected

24 24 AVR Memory Space Program Flash – Vectors, Code, and (Unchangeable) Constant Data Working Registers – Includes X, Y, and Z registers. I/O Register Space – Includes “named” registers SRAM – Data Space – Runtime Variables and Data – Stack space EEPROM space – For non-volatile but alterable data

25 25 AVR Addressing Modes Register Direct, with 1 and 2 registers I/O Direct Data Direct Data Indirect – with pre-decrement – with post-increment Code Memory Addressing

26 26 Register Direct: 1 Register

27 27 Register Direct: 2 Registers

28 28 I/O Direct

29 29 Data Direct STSstore direct to data space

30 30 Data Indirect

31 31 Data Indirect w/ Displacement Operand address is the result of the Y- or Z-register contents added to the address contained in 6 bits of the instruction word. Rd/Rr specify the destination or source register.

32 32 Data Indirect: Pre-Decrement The X,- Y-, or the Z-register is decremented before the operation.

33 33 Data Indirect: Post-Increment The X-, Y-, or the Z-register is incremented after the operation.

34 34 Status Register: SREG Status Register (SREG) SREG: Status Register C: Carry Flag Z: Zero Flag N: Negative Flag V: Two’s complement overflow indicator S: N  V, For signed tests H: Half Carry Flag T: Transfer bit used by BLD and BST instructions I: Global Interrupt Enable/Disable Flag

35 35 Interesting Instruction Examples: NOP – Do nothing for 1 cycle SLEEP – Sleep until reset or interrupted WDR – Watch Dog Reset AVR Instruction set manual available in the course website This instruction resets the Watchdog Timer. This instruction must be executed within a limited time given by the WD prescaler. When WDT (Watch Dog Timer) times out and resets the processor

36 36 include static unsigned int waiter; /*variable to time blinks*/ void main (void) { DDRC = 0x1; /*set PORTC.0 for output*/ /*wait for button to be pressed*/ while (PINA.0 == 1) { ; /*wait for PB to be pressed*/ } WDTCR = 0x0b; /*enable WDT with 130 ms timeout*/ /*stay in this loop while button is held*/ while(PINA.0 == 0) { #asm("wdr"); /*reset WT continuously*/ ++waiter; /*increment waiter variable*/ if (waiter == 50000) { PORTC.0 = PORTC.0 ^ 1; /*complement port bit*/ waiter = 0; /*reset waiter for next delay time*/ } while(1); /*lock up to allow WDT to time out*/ } /* Demonstration the use of of the watchdog timer */

37 37

38 38 Timers: Why we need them Provide accurately timed delays or actions independent of code execution time How are Timers used? – Accurate delay Read the timer, store value as K. Loop until timer reaches K+100. – Schedule important events Setup an Output Compare to trigger an interrupt at a precise time – Measure time between events When event#1 happens, store timer value as K When event#2 happens, read timer value and subtract K The difference is the time elapsed between the two events

39 39 AVR Timer/Counter 0 8 Bit Wrap-Around Up Counter Interrupt on Overflow

40 40 AVR Timer/Counter 0 8 Bit Up Counter – counts from 0 to 255 (0xFF), then loops to 0 – Internal or External Clock source Prescaler Interrupt on Overflow – Transition from 255 to 0 can trigger interrupt if desired

41 41 Example: 6MHz, Prescaler = 8, 6/8=0.75MHz, 1 clock cycle = 1.33 us for the Timer

42 42 static unsigned int time_count; /*.5 second counter*/ // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isr(void) { TCNT0 = 31; /*set initial value for counter 0 to 31, count up to 256, for 300 us timeout*/ /* 256 – 31 = 225 counts at 1.33 us/clock cycle; 225x1.33 = 300 us */ ++time_count; /*increment.5 second counter*/ if (time_count == 1666) /* 300us x 1666 =.5 sec */ { PORTC.0 = (PORTC.0 ^ 1); /*complement port bit to blink LED*/ time_count = 0; /*reset time counter for next.5 second*/ } void main (void) { DDRC = 0x01; /*set PORTC.0 for output*/ /*set timer 0 prescaler to clk/8*/ TCCR0=0x02; TCNT0=0x00; OCR0=0x00; /* unmask Timer 0 overflow interrupt*/ TIMSK=0x01; /* enable interrupts */ #asm("sei") while(1) { ; /*do nothing in here */ } /*TCCR: timer counter control register*/ /* TCNT0: timer counter 0*/

43 43

44 44 AVR Timer/Counter 1 – 16 Bit – Dual Comparators A,B (output captures) – Up Counter – Interrupt on: Overflow Compare A/B Input Capture of external event on ICP pin. – Can also act as an 8, 9 or 10 bit PWM Up- Down Counter.

45 45 Timer 1 and Output Compare The AVR has two output compares (OCR1A/B) – OCR1A/B are 16-bit registers – When the value of OCR1x matches that of Timer1: A user-defined action can take place on the OC1x pin (set/clear/inv) An interrupt can be triggered Timer1 can be cleared to zero – Once set up, output compares operate continuously without software intervention – Great for: Precise recurring timing Frequency/Tone generation (maybe sound effects) All kinds of digital signal generation – Infrared communications – Software-driven serial ports

46 46 Timer 1 and PWM Pulse-Width Modulation – Useful for using digital circuits to achieve analog- like control of motors, LEDs, etc – Timer 1 has two channels of PWM output on OCR1A and OCR1B

47 47 Timer Control: I/O space Timer 0: – Control Register (TCCR0) – Timer/Counter0 (TCNT0) Timer 1: – Control Register A & B (TCCR1A/B) – Input Capture Register (ICR1) – Timer/Counter1 Output Compare Register A and B (OCR1A/B) – Timer/Counter1 (TCNT1) Timer Interrupt Registers (Mask and Flag Registers) are Common to Both Timers

48 48 AVR Timer/Counter Sources Shut Off CPU frequency divided by 1,8,64,256,1024 At 8MHz that’s: 1/8us, 1us, 8us, 32us, 128us External Input (rising or falling).

49 49 Interrupts Interrupts halt normal code execution in order to go do something more important or time sensitive Interrupt “Handlers” – Using the Interrupt Vectors Interrupts are used for: – RESET – Timers and Time-Critical Code – Hardware signaling “I’m done” “Something’s happened that you want to know about” “I have something for you”

50 50

51 51 Reading Assignment: Chapter 1 of Embedded C Programming and the Atmel AVR Next class time we may have a quiz about Chapter 1 Exercises.


Download ppt "1 Lecture 1: Embedded Systems Overview, AVR Hardware/Software Introduction."

Similar presentations


Ads by Google