Download presentation
Presentation is loading. Please wait.
Published byGabriel Ferguson Modified over 9 years ago
1
Real Time Interrupts Section 4.15
2
Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts are often counted to determine time and date (XP, LINUX) OS use RTI interrupts for process scheduling IBM PC is interrupted 18.2 times per second by RTI
3
Real-Time Interrupt Two Bits of Interest –RTIE – Real-Time Interrupt Enable “0” – Disables Interrupts “1” – Enables Interrupts –RTIF – Real-Time Interrupt Flag Set every T Seconds when RTIE=“1” Generates Maskable Interrupt when “1” Write “1” to RTIF to Clear Flag
4
Real Time Interrupt 68HC12DP256 Set Up and Controlled using 3 Registers: –RTICTL –CRGINT –CRGFLG
5
Clock Generator Lab Processor Boards uses a 4 MHz Crystal Oscillator Frequency of Bus Clock (ECLK) – 2 MHZ RTI uses the 4 MHZ Crystal Clock
7
4 MHZ SETS RTI FLAG Prescaler: Divides by 1, 2, 4, 8, 16, 32, or 64 Divides by 1, 2, 3, 4, 5, 6,, 16
8
Divide 4 MHZ Clock by: 1024 AND BY 1 or 2 or 4 or 8 or 16 or 32 or 64 (Selected by RTR[6:4]) AND BY 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 or 11 or 12 or 13 or 14 or 15 or 16 (Selected by RTR[3:0]) to generate rate of RTI Timeout Output.
9
Real Time Interrupt Enable
10
Real Time Interrupt Flag Power-On Reset Flag Self-check Mode Interrupt Flag
11
Real Time Control Register
13
/* rtc1 = RTR[6:4], rtc = RTR[3:3] frti = Frequency of RTI */ int rtc1, rtc2; float frti; rtc1 = (RTR>>4)&0x07; rtc2 = RTR&0x0F; if(rtc1==0) frti=0; else frti = 4000000/(1024*(1<<(rtc1-1))*(rtc2+1)) Frequency of RTI
14
1234567 13906.251953.13976.56488.28244.14122.0761.04 21953.13976.56488.28244.14122.0761.0430.52 31302.08651.04325.52162.7681.3840.6920.35 4976.56488.28244.14122.0761.0430.5215.26 5781.25390.63195.3197.6648.8324.4112.21 6651.04325.52162.7681.3840.6920.3510.17 7558.04279.02139.5169.7534.8817.448.72 8488.28244.14122.0761.0430.5215.267.63 9434.03217.01108.5154.2527.1313.566.78 10390.63195.3197.6648.8324.4112.216.10 11355.11177.5688.7844.3922.1911.105.55 12325.52162.7681.3840.6920.3510.175.09 13300.48150.2475.1237.5618.789.394.70 14279.02139.5169.7534.8817.448.724.36 15260.42130.2165.1032.5516.288.144.07 16 244.14 122.07 61.04 30.52 15.26 7.63 3.81
15
Init prescale factor in RTICTL Enable RTIE in CRGINT Reset RTIF in CRGFLG Enable maskable interrupts ENABLE(); CRGFLG
16
Text RTI Example RTI Interrupt every 8.192 msec. E Clock is 4 MHZ RTICTL is defined differently Divide E Clock by 2 raised to power 15 –RTR[6:4] = 6 –RTR[3:0] = 0 –RTICTL = 0x60 RTI Interrupt Vector Address = 0xFFF0
17
TEXT RTI Examples Replace #include with #include Replace interrupt #pragma code with –void RTI_isr() __attribute__ ((interrupt)); Replace init vector #pragma code but place inside of main program Initialize Interrupt Vectors with –SETVECT(0xFFF0,RTI_isr);
18
Text RTI Example Replace RITCTL=0x84 with Set Interrupt Frequency, enable RTI, clear RTI –RTICTL = 0x60; –CRGFLG=0x80; –CRGINT = CRGINT | 0x80; Replace RTIFLG=0x80 with Clear RTI Flag –CRGFLG = 0x80; Replace CLI() Enable Interrupts with –ENABLE();
19
/* Real Time Interrupt Example Program Page 206-208 of Text Modified to Execute on Lab Microcontroller This program keeps track of clock time using the Real Time Interrupts. The RTI generates an interrupt 8.192 ms. The RTI_isr keeps track of elapsed time. */ /* include files */ #include /* function prototypes */ void RTI_isr(void) __attributes__ ((interrupt)); /* global variables */ unsigned int ms_ctr, sec_ctr, mins_ctr, hrs_ctr, days_ctr;
20
void main(void){ ms_ctr = 0; // initialize timer variables sec_ctr = 0; mins_ctr = 0; hrs_ctr = 0; days_ctr = 0; /* initialize RTI - - replaces pragma abs_address, etc. */ SETVECT(0xFFF0,RTI_isr); // interrupt vector // Replace RTICTL = 0x84; RTICTL = 0x60; // set interrupt frequency CRGFLG=0x80; // clear RTI interrupt flag CRGINT = CRGINT | 0x80; // enable RTI /* Enable Interrupts – replace CLI() */ ENABLE(); while(1); // wait for interrupts }
21
/* RTI_isr: RTI Interrupt Service Routine */ void RTI_isr(void) { // replaces RTIFLG CRGFLG = CRGFLG | 0x80; /* update milliseconds */ ms_ctr = ms_ctr+1; /* update seconds */ if(ms_ctr == 122) /* counter equates 1000 ms at 122 */ { ma_ctr = 0; // reset millisecond counter sec_ctr = sec_ctr +1; // increment seconds counter
22
/* update minutes */ if(sec_ctr == 60) { sec_ctr = 0; // reset seconds counter mins_ctr = mins_ctr+1; // increments minutes counter } /* update hours */ if(mins_ctr == 60) { mins_ctr = 0; // reset minutes counter hrs_ctr = hrs_ctr + 1 // increments hours counter } /* update days */ if(hrs_ctr == 24) { hrs_ctr = 0; // reset hours counter days_ctr = days_ctr + 1; // increment days counter }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.