Lab 9 - Introduction of Timers & their configuration to generate time-based interrupts
Lab 9 - Introduction of Timers & their configuration to generate time-based interrupts
Experiment # 9
Introduction of Timers & their configuration to
generate time-based interrupts
Objective
• To get familiar with Timers and their applications
• To generate time-based interrupts of specific time intervals (Simulation Based)
Timers in microcontrollers are hardware peripherals designed to measure time intervals, generate timing
events, and control the timing of various operations within the microcontroller. They are incredibly versatile
and find applications in a wide range of tasks, from generating precise time delays to controlling the
execution time of specific operations.
Applications:
1. Time Measurement: Timers can measure elapsed time accurately by counting clock cycles or
external events. This feature is useful for tasks such as measuring the duration of an event or
generating time stamps.
2. Timing Events: Timers can be configured to generate interrupts or trigger events at specific
intervals. This capability is essential for tasks that require periodic execution, such as sampling
sensors or updating display screens.
3. Pulse Width Modulation (PWM) (Fixed Frequency & Variable Duty Cycle): Many timers in
microcontrollers support PWM functionality. PWM is used to control the power supplied to devices
like motors, LEDs, and heaters by varying the duty cycle of a square wave signal.
4. Frequency Generation (Variable Frequency & Fixed Duty Cycle): Timers can generate precise
clock signals with adjustable frequencies. This feature is handy in applications like communication
systems, where accurate timing is crucial for data transmission.
5. Input Capture (Time Measurement): Some timers have input capture functionality, allowing them
to record the timestamp when an external event occurs. This feature is useful for tasks such as
measuring the frequency of an incoming signal or capturing the time of external events.
Time delay = (Max Value – Pre-Programmed Value) * 4 * One Clock Cycle Time
While
One Clock Cycle Time = 1 / Clock Frequency
So,
Time delay = (Max Value – Pre-Programmed Value) * 4 / Clock Frequency
• To enhance the maximum limit of time delay (i.e, to enhance the number of bits of
Timer Register), a Pre-Scalar register option is available in almost all the MCUs. So,
formula can be rewritten as:
• Connect an LED to RB1 in Proteus and Load the .hex file of above program and observe the output.
Explain it in your report.
Note: 20 MHz Clock Frequency is used in the above simulation.
Task 2:
• Implement time-based interrupt for 300 m seconds time delay
• Use 4 MHz clock frequency in your simulation
• Show your detailed calculation and c programming in report
Task 3:
• Compose a concise report for submission in the forthcoming lab session, presenting it in hard copy
format.
• Include images of simulations, circuit diagram, along with your comments for all tasks within the
report.
• On the title page of your report, include only the following details: Experiment number and name,
Your name, Registration number, Section, and a thumbnail (optional).
• Adhere strictly to a professional format for the entire report.
• Ensure that the report is printed on both sides of the paper.
----------------------------------------------