1 / 38

Introduction to Embedded Systems

Introduction to Embedded Systems. Instructed by: Iksan Bukhori. Outline. Course Information Course Overview & Objectives Course Materials Course Requirement/Evaluation/Grading (REG). I. Course Information. Instructor + Name : Iksan Bukhori

cherylp
Download Presentation

Introduction to Embedded Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Embedded Systems Instructed by: Iksan Bukhori

  2. Outline • Course Information • Course Overview & Objectives • Course Materials • Course Requirement/Evaluation/Grading (REG)

  3. I. Course Information • Instructor + Name : Iksan Bukhori + Address : Jl. Ki Hadjar Dewantara, President University, Cikarang, Bekasi + Email Address : bukhoriiksan@gmail.com + Office Hours : • Course‘s Meeting Time & Location + Meeting Time : Thursday-> 10.30 – 13.00 (Lec) : Friday -> 10.30 – 13.00 (Lab) + Location : Room B, President University, Cikarang Baru, Bekasi

  4. Course Objectives The objectives of this course are students should be able to : • Demonstrate the understanding of several microprocessor architectures & organizations, bus systems, input/output units, and memory systems • Exhibit the ability in designing and building an interface for AVR ATmega328p microcontroller of an Arduino UNO Board • Develop interface programming using Assembly, or C languages • Assemble the interfacing of AVR ATmega 328p microcontroller to other external peripherals, sensor(s) , actuator(s), computer(s)

  5. III. Course Materials

  6. Final Exam : All Chapters/Activities

  7. IV. Course Requirement/Evaluation/Grading • Requirements : - Microcomputer Interfacing - Engineering Programming • Evaluation for the final grade will be based on : - Mid-Term Exam : 30 % - Quizzes : 15 % - Lab Experiments or Assignments : 25 % - Course Project : 30%

  8. Mid-Term Exam consists of Lectures given in between the Week 1 and the Week 6. • Final Exam covers whole subjects or materials given duringthe classes. • Grading Policy Final grades may be adjusted; however, you are guaranteed the following: If your final score is 85 - 100, your grade will be A. If your final score is 70 - 84, your grade will be B. If your final score is 60 - 69, your grade will be C. If your final score is 55 - 59, your grade will beD. If your final score is < 55, your grade will be E.

  9. REFERENCES • LOTS

  10. Rules & Regulations

  11. Chapter 8 Interrupts

  12. 9.1 What is an Interrupt? • A transfer of program control that is not directed by the programmer • Like a phone call in the middle of a conversation • Stop what you’re doing, deal with the interruption, then continue where you left off • Very handy for handling events that need immediate attention • Or that need to occur at regular intervals • Or that need to run automatically without programmer keeping track

  13. 9.2. What Happens? • An interrupt is signaled somehow • A phone rings • The AVR stops running user code and checks to see what caused the interrupt • Stop your conversation and check which phone is ringing • The AVR runs an Interrupt Service Routine (ISR) related to that interrupt • Answer the phone and handle the call • The AVR restores the system state and picks up the user code where it left off • Hang up and resume your previous conversation

  14. 9.3. Type of Interrupts • On Arduino/AVR, there are three types • External: A signal outside the chip (connected to pin) • Timer: Internal to the chip, like an alarm clock • Device: One of the AVR devices (USART, SPI, ADC, EEPROM) signals it needs attention

  15. 9.4. External Interrupts • AN external event (signal on an input pin) causes an interrupt • A button, a sensor, external chip, etc. • There are two external interrupt pins on Arduino • Interrupt 0 (Pin 2) and Interrupt 1 (Pin 3) • Supported by Arduino software • attachInterrupt(interrupt#, func-name, mode); • Interrupt# is 0 or 1 • Func-name is the name of ISR function • Mode is LOW, CHANGE, RISING, FALLING

  16. 9.4. External Interrupts

  17. 9.4.1 From Arduino Reference

  18. 9.4.2 External Interrupt Example

  19. 9.4.3 A note on ISR • Any delay function used the same timer as interrupt (Timer0), thus one should not use delay function inside ISR • ISR should be kept short because otherwise it will make the whole program runs slower as processor needs to spread processing time to main program and all ISRs

  20. 9.4.4 Volatile Qualifier

  21. 9.4.4 External Interrupt Summary • AVR ATMega328p has 2 external interrupts • 0 (on Arduino pin 2) and 1 (on Arduino pin 3) • Use attachInterrupt (int#, ISR-name, mode); to attach ISR to external interrupt • Make sure to provide function definition for ISR-name • Choose mode as LOW, CHANGE, RISING, FALLING • If the main code looks at a variable set in ISR make sure that variable is volatile • detachnterrupt(int#); is also available • Interrupts(); and noInterrupts(); turn them on and off

  22. 9.5 Timer Interrupt: Motivation • Arduino 101 – blinking LED • Problem – Arduino is just wasting time during the delay. The processor can’t be used for anything else

  23. 9.5 Timer Interrupt: Motivation • Instead, we could use interrupts • Interrupt the processor every 1 sec (for example) • Change the state of LED • Then continue with program execution • Keeps the LED blinking at a fixed rate • Doesn’t require any attention in the main program • This is a general technique, not just for LED-blinking!!

  24. 9.5.1 Timer • First look at timers • What are they? • How to read/write timer values? • How to configure them? • Then look at how timer can cause an interrupt • Like an alarm clock • When a timer alarm goes off, an ISR may be called

  25. 9.5.2 AVR Timers • Timers are like on-chip alarm clocks • They count (tick) once for each system clock tick • 16 MHz for Arduino • Your program can check, and reset the count values • You can also “prescale” the timer’s clock so that it’s counting slower than 16 MHz Arduino clock • You can also have the timer set an alarm when the count gets to some particular value • The alarm is an interrupt • You can define the ISR for that timer alarm

  26. 9.5.2 AVR Timers • Arduino’ AVR has three internal timers • Timer0: an 8-bit timer(counts 0 to 255) • Used for system timing, millis(), micros(), etc. • And PWM on pins 5 and 6 • Timer1: a 16-bit timer (counts 0 to 65,535) • Used for PWM on pins 9 and 10 • Timer2: an 8-bit timer (counts 0 to 255) • Used for PWM on pins 3 and 11 • Try to avoid using Timer0 – it might mess things up… • If you use Timer1 or Timer2, you will lose PWM on some pins…

  27. 9.5.3 Timer Normal Mode • Start counting on system reset • Count until you get to your TOP, then start again at 0 • 8-bit timer TOP is 255 • 16-bit TOP is 65,535 • Access timer’s current value using special register • TCNT0, TCNT1, TCNT2 • A=TCNT2; //Read value of timer 2 • TCNT1=0; //Reset value of timer 1 to 0

  28. Registers (ATMega 328) • TCNTx Most important is the Timer/Counter Register (TCNTx) itself. This is what all timer modes base on. It counts System Clock ticks, prescaled system clock or from the external pin. • TCCRx The Timer/Counter Control register is used to set the timer mode, prescaler and other options.

  29. Registers (ATMega 328) • OCR1 The Output Compare register can be used to generate an Interrupt after the number of clock ticks written to it. It is permanently compared to TCNT1. When both match, the compare match interrupt is triggered. If the time between interrupts is supposed to be equal every time, the WGM12 bit has to be set (TCCR1B). It is a 16-bit register.

  30. Registers (ATMega 328) • TIMSK It is a common register for all the three timers. In our case, TIMSK will be used to enable timer overflow interrupt. TOIE1: Timer Overflow Interrupt Enable (Timer 1); If this bit is set and if global interrupts are enabled, the micro will jump to the Timer Overflow 1 interrupt vector upon Timer 1 Overflow. TOIE0: Timer Overflow Interrupt Enable (Timer 0); Same as TOIE1, but for the 8-bit Timer 0.

  31. Using Interrupts: Overflow Interrupt Problem Statement: Using normal mode on Timer1, turn on and off an LED every time Timer1 Overflows. • First, we initialize the timer

  32. Using Interrupts: Overflow Interrupt Problem Statement: Using normal mode on Timer1, turn on and off an LED every time Timer1 Overflows. • Next, define ISR How fast will the LED actually blink? • Assume Timer1 works on 16 MHz • Maximum of TCNT1: • Period (Time for one clock cycle): • Which means the counter will overflow every:

  33. Time Prescaling and CTC • Suppose that we want to blink LED every 1 second. We can configure timer using the CSxy bits in TCCRxB register. • For example, we can set CS10 and CS12 which gives us timer resolution seconds • Now, the timer will overflow every seconds • Too long!

  34. CTC Mode • Instead of counting until an overflow occurs, the timer compares its count to a value that was previously stored in a register(OCR1) • First, Find out how many counts we need to get one second interval • (target time) = (timer resolution) * (# timer counts + 1) • (# timer counts + 1) = (target time) / (timer resolution) • (# timer counts + 1) = (1 s) / (6.4e-5 s) • (# timer counts + 1) = 15625 • (# timer counts) = 15625 - 1 = 15624 We add +1 to timer counts because after the TCNT matches OCR, the timer will reset to zero and this process takes one clock cycle to perform.

  35. Interrupt using CTC and Prescaler

  36. Timer Summary

  37. Thank You

More Related