The AVR microcontroller and embedded systems using assembly and c AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

More fun with Timer/Counters
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
Timers in Hardware ECE152. Overview Why are timers important – Watchdog – Task switching – Accurate time of day Can use polling or interrupts.
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
ATtiny2313 Timers/Counters CS-423 Dick Steflik. What Do You Use Timers For? Timing of events (internal or external)‏ Scheduling Events Measuring the width.
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Pulse Width Modulation modes
1.  8051 Timers “count up,” incrementing the Timer’s respective “count register” each time there is a triggering clock pulse. 2  When the “count register”
Timers and Interrupts Shivendu Bhushan Sonu Agarwal.
The Use of Microcontrollers
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
Today’s Lecture List the Timers of PIC18 and their associated registers Describe the various modes of the PIC18 timers Program the PIC18 timers in Assembly.
AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All.
CHAPTER TIMER PROGRAMMING Timers The 8051 has two timers/counters, they can be used as ◦ Timers to generate a time delay ◦ Event counters.
8051 timer/counter.
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
Dec Hex Bin 13 D ORG ; THIRTEEN 8253/54 Timer.
Slides created by: Professor Ian G. Harris Interrupts  Embedded systems often perform some tasks which are infrequent and possibly unpredictable Hang.
Timer/counter Chapter 12
ARM Timers.
System Clocks.
A Few Words From Dilbert
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Advanced uC Session Speaker : Chiraag Juvekar Jan 13, 2011 Speaker : Chiraag Juvekar Jan 13, 2011.
Timers /Counters Programming  The 8051 has 2 timers/counters: ○ timer/counter 0 ○ timer/counter 1 They can be used as 1. The timer is used as a time.
Introduction to AVR Chapter 1
ELE22MIC Lecture 18 The AVR Sleep Modes The ATMEGA128’s Timer System
Counter/Timer/PWM. incoming Lab. Counter counter is a device which stores the number of times a particular event or process has occurred synchronous/asynchronous.
AVR Programming: Timers October 8, What is a timer? A register that keeps track of a current value This value is updated at a certain frequency.
FIGURE 11-1 Bit assignments for the Timer Control, Mask, and Flag Register Peter Spasov Microcontroller Technology: The 68HC11, Fourth Edition Copyright.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
CS-280 Dr. Mark L. Hornick 1 Atmel Timer/Counter System Most microcontrollers include some type of timer system Facilitates real-time monitoring and control.
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
Timers and Scheduled Interrupts
Jump, Loop, and Call Instructions
Interrupt On a very basic level, an interrupt is a signal that interrupts the current processor activity. It may be triggered by an external event (change.
TIMERS AND INTERRUPTS AVI SINGH KEVIN JOSE PIYUSH AWASTHI.
The Silicon Laboratories C8051F020
Arithmetic and Logic Chapter 5
Microprocessors A practical approach Lesson 2 Hardware description and Delays.
1 68HC11 Timer. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare.
The AVR microcontroller
Timer Programming in Assembly and C Prepared By:
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
16-Bit Timer/Counter 1 and 3
Timers and Scheduled Interrupts
Outline Introduction to Arduino UNO Programming environment setup GPIO
V.V.P. ENGINEERING COLLEGE,RAJKOT
BITS EDU. CAMPUS , VARNAMA
AVR Addressing Modes Subject: Microcontoller & Interfacing
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
Timer/Counter Modified from Dr. Lam Phung’s Slides.
16-bit Timer/Counter1 Features
8-bit Timer/Counter0 with PWM
DC motor and PWM.
Programmable Interval timer 8253 / 8254
8-bit Timer/Counter2 with PWM and Asynchronous Operation
Programmable Interval timer 8253 / 8254
Timers/Counters.
Wave Generation and Input Capturing
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
Presentation transcript:

The AVR microcontroller and embedded systems using assembly and c AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Timers/Counters

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Counter Register

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. A Simple Design (Counting 4 People) First Design (Counter Register has initial value of zero) Sensor Karşılaştırıcısız çözüm olur mu?

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. A Simple Design (Counting 4 People) Second Design (Counter Register has initial value of 0xFC) Sensor Karşılaştırıcısız çözüm

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. A Simple Design (Making 4 Clock Cycles Delay) Bu sayıcı bir sensör yerine periyodik bir saat sinyali ile tetiklendiği için bir zamanlayıcıya dönüşmüştür.

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. A Generic Timer/Counter Delay generating Counting Wave-form generating

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Timers/Counters in AVR ATMega328PU 3 Timers/Counters Two 8-bit Timers/Counters (0-255) Timer 0 Timer 2 One 16-bit Timer/Counter ( ) Timer 1

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Timer Registers and Flags TCNTn TCCRn TOVn OCRn = OCFn TCNTn (Timer/CouNTer Register) TOVn (Timer OVerflow Flag) TCCRn (Timer/Counter Control Register) OCRn (Output Compare Register) OCFn (Output Compare Match Flag) TIFRn (Timer Interrupt Flag Register) n 0, 1 veya 2 değerini alır.

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Normal Mode (Timer 0) 0xFF TCNT0 0 TOV time 0 TOV0: 1 FE FF TOV0 =

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Example 1: Write a Program that Waits 14 Machine Cycles in Normal Mode. $100 -$0E $F2 14 = $0E $F2 Question: How to calculate the delay generated by the timer? Answer: 1) Calculate how much a machine clock lasts. T= 1/f 2) Calculate how many machine clocks it waits. 3) Delay = T * number of machine cycles Question: How to calculate the delay generated by the timer? Answer: 1) Calculate how much a machine clock lasts. T= 1/f 2) Calculate how many machine clocks it waits. 3) Delay = T * number of machine cycles

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Finding Values to be Loaded into the Timer 0 1. Calculate the period of clock source. Period = 1 / Frequency E.g. For XTAL = 8 MHz  T = 1/8MHz 2. Divide the desired time delay by period of clock. 3. Perform n, where n is the decimal value we got in Step Set TCNT0 = n

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. CTC (Clear Timer on Compare Match) Mode (Timer 0) TCNT0 0 OCF0 time 0 TOV0: xx TOV0 = no change OCF0 = 1 OCR0 0 OCF0: 1 0xFF

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Prescaler

The AVR microcontroller and embedded systems using assembly and c AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Timer 1 (A 16-bit Timer)

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Timer 1 TCNT1 (TCNT1H + TCNT1L)TCCR1B TOV1 OCR1A (OCR1AH + OCR1AL) = OCF1A = OCF1B OCR1B (OCR1BH + OCR1BL) TCCR1A

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Timer 1 Registers

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Timer Clock Selector (CS1x) 6 7

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Timer Mode Selector (WGM1x)

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Wrap Times (Fcpu=16 MHz) TIMER 0 is 8-bit (0−255) when prescaler = 1, reaches full count in 16  s when prescaler = 1024, full count in ms TIMER 1 is 16-bit (0−65536) when prescaler = 1, reaches full count in ms when prescaler = 1024, full count in seconds TIMER 2 is 8-bit (0−255) when prescaler = 1, reaches full count in 16  s when prescaler = 1024, full count in ms These wrap times set limits on timed interrupts makes TIMER 1 attractive, for its 16 bits

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. A Complete Timer 1 AVR C Example (V1) (Normal Mode) Yoklama (Polling). Kesmeden Farkı? Bayrağı Silmek İçin Set Etmek Gerekli??

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. A Complete Timer 1 AVR C Example (V2) (Normal Mode)

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. A Complete Timer 1 AVR C Example (CTC Mode)

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. AVR C Definitions for ATMega328P The bit values WGM12, CS10, etc. are defined in iom328p.h Its location is hardware/tools/avr/avr/include/avr/ For example: #define CS10 0 #define CS11 1 #define CS12 2 #define WGM12 3 #define WGM13 4 #define ICES1 6 #define ICNC1 7 #define OCR1A _SFR_MEM16(0x88) #define OCR1AL _SFR_MEM8(0x88) #define OCR1AH _SFR_MEM8(0x89) #define TIMER1_COMPA_vect _VECTOR(11) // Timer1 Compare Match A

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Generating Large Delays Using loop Prescaler Bigger counters

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. The Difference Between Timer 0 and Timer 2 Timer 0 Timer 2 CS02 CS01 CS00 Comment Timer/Counter stopped clk (No Prescaling) 0 1 0clk / clk / clk / clk / External clock (falling edge) External clock (rising edge) CS22 CS21 CS20 Comment Timer/Counter stopped clk (No Prescaling) 0 1 0clk / clk / clk / clk / clk / clk / 1024

AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi © 2011 Pearson Higher Education, Upper Saddle River, NJ All Rights Reserved. Atmel AVR ATMega328P Mikrodenetleyicisinin Pinout Diyagramı T0T1