System Clocks.

Slides:



Advertisements
Similar presentations
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Advertisements

4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
Microcontroller Programming II MP6-1
Programmable Interval Timer
EET 2261 Unit 10 Enhanced Capture Timer  Read Almy, Chapter 20.  Homework #10 and Lab #10 due next week.  Quiz next week.
Introduction of Holtek HT-46 series MCU
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.
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.
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”
NS Training Hardware. System Controller Module.
Timers and Interrupts Shivendu Bhushan Sonu Agarwal.
3-1 System peripherals & Bus Structure Memory map of the LPC2300 device is one contiguous 32-bit address range. However, the device itself is made up of.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Module Introduction Purpose  This training module provides an overview of the different.
Renesas Electronics Europe GmbH A © 2010 Renesas Electronics Corporation. All rights reserved. RL78 Clock Generator.
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)
8253 TIMER. Engr 4862 Microprocessors 8253 / 8254 Timer A.k.a. PIT (programmable Interval Timer), used to bring down the frequency to the desired level.
PIT: Programmable Interval Timer
ECE 425 Timer 1 Timer Functions Two main modes: – Input capture Used for timing external events – Match (Output compare) Allows use as a simple function.
ARM Timers.
LPC2148 Programming Using BLUEBOARD
8254 SOFTWARE PROGRAMMABLE TIMER/COUNTER
16F877A. Timer 0 The Timer0 module timer/counter has the following features: –8-bit timer/counter –Readable and writable –8-bit software programmable.
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Chapter 4 TIMER OPERATION
Timers The timers of the PIC16C7X microcontroller can be briefly described in only one sentence. There are three completely independent timers/counters.
Clock Options and Sleep Modes. Clock Sources Flash Fuse bits can be programmed to choose one of the following Clock sources: 1. External RC Osc. f = 1/(3RC).
The 8253 Programmable Interval Timer
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This course provides an overview of the CPU architecture.
Lecture 11 Low Power Modes & Watchdog Timers
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose This course provides an introduction to the peripheral functions.
8279 KEYBOARD AND DISPLAY INTERFACING
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
CCP MODULES  The CCP module (Capture/Compare/PWM) is a peripheral which allows the user to time and control different events.  Capture Mode provides.
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.
Conclusion Speech. Content Organization Pronunciation Handwriting.
8254 Timer.
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Real Time Interrupts Section Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose This course provides an introduction to the peripheral functions.
8279 KEYBOARD AND DISPLAY INTERFACING
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
C Examples 6. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
Timer Programming in Assembly and C Prepared By:
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
Timer modules in PIC 16F877.  The PIC 16F877 basically has three independent timer modules,  denoted by the symbols, TIMER-0, TIMER1,andTIMER2. . These.
EET 2261 Unit 13 Enhanced Capture Timer
16F877A.
Why are Timer Functions Important?
Timers and Event Counters
Timer and Interrupts.
UNIT – Microcontroller.
AVR Addressing Modes Subject: Microcontoller & Interfacing
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
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.
EMT 348: Microcontroller Timer/counter
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
嵌入式微控制器编程 Embedded Microcontroller Programming
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Wireless Embedded Systems
Presentation transcript:

System Clocks

System Clocks The LPC23xx has two main internal clocks. The first is Cclk, the CPU clock, which is used to clock the ARM7 CPU and the AHB peripherals which include the USB controller, Ethernet controller and the general purpose DMA. The second internal clock is Pclk, the peripheral clock, which is used to clock all the peripherals on the APB bus. Both of these clocks may be derived from one of three oscillator sources, an internal RC oscillator, an external main oscillator and an external watch crystal.

System Clocks 32kHz - 50MHz For the MCB2300 board, OSC = 12MHz (Xtal oscillator) SYSclock = 2 x M x OSCin / N SYSclock= 2 x 12 x 12 / 1 = 288MHz

CPU, USB and Peripheral Clocks The output from the PLL enters a series of dividers that are used to determine the USB, CPU and peripheral clocks. USBclk = SysClock/USBclksel CClk = SYSclock/Cclksel Each peripheral on the APB bus derives its clock from Cclk and has a programmable divider which divides Cclk by 1, 2 or 4. For the MCB2300 this is configured in the startup file (LPC2300.s) to give CClk and USBClk of 48MHz and the PClk for all peripherals of 12MHz.

Timing Timing - using a known clock frequency Clock source derived from the system clock, but may be divided down In our case for TIMER0 CClk/4 (this can be selected in the startup.s file)

Timers Applications Timing - using a known clock frequency Counting external events (using an external input) Pulse width measurement generating pulse outputs Timers are really n-bit binary counters with additional features.

Timing Essentially a 32 bit binary counter which increments at the Pclk frequency (or a sub multiple of) 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 . 1 2 2^32 For example if the Pclk is at 12MHz then the timer will increment 12 000 000 times per second which equates to once every 83.333nS (The smallest resolution for a 12MHz Pclk) Maximum time duration 2^32×83.333nS = 358s To increase this value a pre-scaler may be used

Timing The current value of the timer counter is compared against the match register. When the values match an event is triggered. This event can perform an action to the timer (reset, stop or generate interrupt) and also influence an external pin (set, clear, toggle).

Generating a time period Each timer has a match register This value of this is set by the programmer When the timer value = match register value a flag will be set. For example to generate a time period of 0.5s Clock counts = Timer Frequency × time period Clock counts = 12 000 000 × 0.5 = 6 000 000

Counters - software based Counting the number of times Port2 Bit 10 is pressed (lab example 4) // wait until pushbutton is pressed while((FIO2PIN & 0x00000400) != 0) { ; } val++;

Counters Often required to count external events or measure frequency. -Input from a switch -Input from frequency dependant sensor (QCM) -Input from industrial machinery (counting number of ?? Each time an external event occurs detecting edge(s) of an input the value in the counter is incremented. Source of the counter input is an external pin not the clock!

Counting external events Frequency counting After a defined time period (nominally 1s) what is the value of the counter. Event counting After a set number of (events) edges have been detected perform some action

Pulse width measurement (timer mode) Start timer Stop timer t On rising edge from an external input start timer Stop on the falling edge How many timer increments have occurred ? Remember resolution is set by the value of Pclk & prescaler used

Pulse width generation On timer match toggle output pin t Pulse width t set by value in the match register

LPC2368 Timer/Counters There are four 32-bit timer/counters (T0 - T3) Each timer has a programmable 32 bit Prescaler. Counter or Timer operation Four 32 bit match registers that allow: Continuous operation with optional interrupt generation on match. Stop timer on match with optional interrupt generation. Reset timer on match with optional interrupt generation.

LPC2368 Timer/Counters (contd.) Up to four external outputs corresponding to match registers, with the following capabilities: Set low on match. Set high on match. Toggle on match. Do nothing on match. Up to four 32 bit capture channels per timer, that can take a snapshot of the timer value when an input signal transitions. A capture event may also optionally generate an interrupt.

Timer diagram One timer showing the register structure PCLK is the peripheral clock which is derived from the main processor clock. ( Pclk = CPUclk / x where x is 1,2 or 4)

For each Timer there are registers:- TCR - Timer Control Register The TCR is used to control the Timer Counter functions. The Timer Counter can be disabled or reset through the TCR. TC - Timer Counter The 32 bit TC is incremented every PR+1 cycles of PCLK. The TC is controlled through the TCR. PR - Prescale Register When the Prescale Counter (below) is equal to this value, the next clock increments the TC and clears the PC. PC - Prescale Counter The 32 bit PC is a counter which is incremented to the value stored in PR. When the value in PR is reached, the TC is incremented and the PC is cleared..

contd. IR - Interrupt register EMR - External Match Register The IR can be written to clear interrupts. The IR can be read to identify which of eight possible interrupt sources are pending. EMR - External Match Register The EMR controls the external match pins MATn.0-3 (MAT0.0-3 and MAT1.0-3 respectively). CTCR - Count Control Register The CTCR selects between Timer and Counter mode, and in Counter mode selects the signal and edge(s) for counting. Register naming Precede the register name with T0, T1, T2 or T3

contd. MCR - Match Control Register The MCR is used to control if an interrupt is generated and if the TC is reset when a Match occurs. MR0, MR1, MR2, MR3 - Match Registers The match registers can be enabled through the MCR to reset the TC, stop both the TC and PC, and/or generate an interrupt every time MR0 matches the TC. CCR - Capture Control Register The CCR controls which edges of the capture inputs are used to load the Capture Registers and whether or not an interrupt is generated when a capture takes place. CR0, CR1, CR2, CR3 - Capture Registers The capture registers is loaded with the value of TC when there is an event on the CAPn.0(CAP0.0 or CAP1.0 respectively) input.

Timer Control Register Timer 0 Control register is T0TCR

Interrupt Registers Timer 0 Interrupt register is T0IR

Count Control Register

Count Control Register (contd.) T0 Count Control register is T0CTCR

Example to measure a fixed period of time Calculate count value to place in a Match Register Configure Match Control Register to reset Timer Counter and to set IR when match occurs. The counter will reset and carry on incrementing. Poll the relevant bit in the IR - when the bit is set the time period has elapsed. Now clear the bit ready for the next match to occur.

C code to initialise Timer 0 Timer 0 peripheral clock = 12Mhz Period to measure = 125ms (1/8 of a second) Clock counts = Timer Frequency * time period = 12000000 * 125 x10-3 = 1500000 /* Initialise Timer 0, match register and start timer */ T0MR0 = 1499999; /* 125 msec = 1500000-1 at 12.0 MHz */ T0MCR = 3; /* ResetT0TC & set interrupt on MR0 */ T0TCR = 1; /* Timer0 Enable */

Program structure for periodic execution Initialise variables & peripherals initialise and start the timer while(1) { } Code for the periodic task goes here Wait for the timer period to elapse. Reset the timer interrupt bit.

I need feeding every 5 Hours WatchDog Timer (WDT) The purpose of the WatchDog is to reset the microcontroller within a reasonable amount of time if it enters an erroneous state (crashed program). When enabled, the WatchDog will generate a system reset if the user program fails to "feed" (or reload) the Watchdog within a predetermined amount of time. The minimum watchdog period at 60MHz is 17.066us and the maximum is just under 5 minutes. I need feeding every 5 Hours

Real Time Clock (RTC) The LPC23xx Real Time Clock (RTC) is a clock calendar accurate up to the year 2099. The RTC has the option to run from and external 32KHz watch crystal or from the internal PCLK. The RTC also has an associated 2K of Low power SRAM called the battery RAM. The RTC and battery SRAM have a separate power domain so by supplying 3.3V to the Vbat pin, the RTC can be kept running and the contents of the battery ram may be preserved when the LPC23xx is powered down.

RTC

References LPC23xx user manual (UM10211) http://www.keil.com/dd/docs/datashts/philips/lpc23xx_um.pdf NXP links page -http://ics.nxp.com/products/lpc2000/lpc23xx/ Insiders guide to the LPC23xx http://www.hitex.com/index.php?id=download-insiders-guides