Download presentation
Presentation is loading. Please wait.
1
2/26/2015 Richard Kuo Assistant Professor
Timer/WatchDog /RTC 2/26/2015 Richard Kuo Assistant Professor
2
Outline 6.0 NuMicro_Timer.ppt Timer/WatchDog/RTC Introduction
Exercise Timers Lab. Periodic mode (smpl_Timer_LED) Lab. One timer Multiple counter (smpl_Timer_Counter) Lab. One timer Multiple modes (smpl_Timer_LCD) Exercise Timer Capture pin Lab. Ultrasonic Sensor module (smpl_Timer_SR04) Exercise Watch-Dog Timer Lab. Watch-Dog Timer (smpl_WDT) Exercise Real-Time Clock Lab. Real Time Clock (smpl_RTC) Homework : Car Parking Sensor
3
Timer Features Four 24-bit up-counting timer
A prescaler (divider) for each Timer Selectable 5 clock source Four modes : one shot, periodic, toggle, continuous Timeout Period calculation Time out period = (Period of timer clock input) * (8-bit Prescale + 1) * (24-bit TCMP)
4
Nano100 Timer Clock Source
5
Nano100 Timer Block Diagram
6
NUC100 Timer Clock Source HIRC HCLK LIRC HXT
7
NUC100 Timer Block Diagram
8
Timer operation modes Example: TCMPR = 100 One-Shot mode Periodic mode
Continuous Counting mode Interrupt 100 One shot Reset counter Periodic 100 Overflow 100 101 224-1 Continuous
9
smpl_Timer_LED volatile uint8_t ledState =0;
void TMR1_IRQHandler(void) { ledState = ~ ledState; // changing ON/OFF state if(ledState) PC12=0; else PC12=1; TIMER_ClearIntFlag(TIMER1); // Clear Timer1 time-out interrupt flag }
10
smpl_Timer_LCD
11
smpl_Timer_SR04 Ultrasonic Sensor HC-SR04 VCC5 to VCC GND to GND
GPB2 to Echo GPB4 to Trig
12
Ultrasonic Ranging Module SR04
Item Specification Working Voltage DC 5V Working Current 15mA Working Frequency 40Hz Max. Range 4 m Min. Range 2 cm Measuring Angle 15 degree Trigger Input 10 us TTL pulse Echo Output TTL level
13
Ultrasonic Sensor Waveform
14
Ultrasonic Ranging Module SR04
supply a short 10uS pulse to the trigger input to start the ranging, then the module will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo The Echo is a distance object that is pulse width and the range in proportion Equation : Distance = (Echo_Pulse [us] * 340/2 [Meter] ) / 1000 …… (Unit: mm) Example : Echo Pulse: us, Velocity of Sound: 340m/s Distance = (11245 * 340/2) / 1000 = 1911 (Unit: mm) over 60ms measurement cycle is suggested, in order to prevent trigger signal to the echo signal. Ultrasound Speed : V = * T
15
Ultrasound Sensor Ranger Principle
。 Ultrasound Sensor Ranger Principle Ultrasound Sensor Ranging the distance by measuring the time from transmitting 40KHz wave to received 40KHz wave, Ultrasound Speed : V = * T T : temperature C0 : speed at absolute zero degree Distance t: travel time from sound wave transmitted to the reflection received
16
WatchDog Timer 18-bit up counter 8 selections of time out period
Support function: WDT interrupt WDT reset WDT wakeup
17
NUC100 WDT Clock
18
Watchdog controller Block Diagram
19
Watchdog Timer Interrupt & Reset signals
20
Windowed Watchdog controller Block Diagram
21
Nano100 WDT Time out Interval selection
22
Nano100 WWDT pre-scaler selection
23
NUC100 WDT Time out selection
WTIS Interrupt Timeout Watchdog Reset Timeout WTR Timeout Interval for Reset (WDT_CLK=12MHz) WTR Timeout Interval for Reset (WDT_CLK=32KHz) 000 24 WDT_CLK (16 WDT_CLK) ( ) WDT_CLK (1040 WDT_CLK) 86.67us 32.5 ms 001 26 WDT_CLK ( ) WDT_CLK 90.67 us 34 ms 010 28 WDT_CLK ( ) us 40 ms 011 210 WDT_CLK ( ) WDT_CLK us 64 ms 100 212 WDT_CLK ( ) WDT_CLK us 160 ms 101 214 WDT_CLK ( ) WDT_CLK 1.45 ms 544 ms 110 216 WDT_CLK ( ) WDT_CLK 5.55 ms 2080 ms 111 218 WDT_CLK ( ) WDT_CLK 21.93 ms 8224 ms `
24
smpl_WDT
25
RTC Features TLR=0x00093043 CLR=0x00120229 RTC counter A set of Alarm
Time counter Calendar counter Day of week Leap year BCD format TLR=0x CLR=0x A set of Alarm Alarm and time tick interrupt Wakeup function 32KHz compensation
26
RTC Block Diagram INIR (0xA5EB1357) AER (0xA965) 512 RTC clock ≒15msec
27
RTC Example RTC sample code with driver RTC sample code
Enable RTC and set date and time Date: Time: Enable alarm interrupt and set alarm date and time Alarm date: Alarm Time: RTC sample code The same flow
28
Smpl_RTC
29
smpl_Timer_WDT_RTC
30
Car Parking Sensor
31
Important Notice ! This educational material are neither intended nor warranted for usage in systems or equipment, any malfunction or failure of which may cause loss of human life, bodily injury or severe property damage. Such applications are deemed, “Insecure Usage”. Insecure usage includes, but is not limited to: equipment for surgical implementation, atomic energy control instruments, airplane or spaceship instruments, the control or operation of dynamic, brake or safety systems designed for vehicular use, traffic signal instruments, all types of safety devices, and other applications intended to support or sustain life. All Insecure Usage shall be made at user’s own risk, and in the event that third parties lay claims to the author as a result of customer’s Insecure Usage, the user shall indemnify the damages and liabilities thus incurred by using this material. Please note that all lecture and sample codes are subject to change without notice. All the trademarks of products and companies mentioned in this material belong to their respective owners.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.