Lab#6 Timers
Lab#6 Timers
Lab#6 Timers
Theory
According to the family manual, a PIC24F device has 5_16 bit timers. Each timer x
has the following registers:
• TMRx: 16-Bit Timer Count register.
• PRx: 16-Bit Timer Period register associated with the timer.
• TxCON: 16-Bit Timer Control register associated with the timer.
Each of those timers also contain interrupt control bits:
• Interrupt Enable Control bit (TxIE)
• Interrupt Flag Status bit (TxIF)
• Interrupt Priority Control bits (TxIP)
In addition to the previous, it is possible to cluster 2 16-bits counters to form a 32-bit counter.
In the output control subsystem, we could compare the values of compare registers.
Which gives us the ability to generate a single output pulse, a train of output pluses, or
compare match/mismatch events. This could be used to accurately generate pulse width
modulated signals by specifying the period register and the timer.
Lab work:
1. [20] Write a C language program to use 1:256 pre scaler, [ use Delay function in Config.h]
Flash PortA every 0.5 Sec,
Turn it on for 100 mSec, and off for 400 mSec, check them both on Oscilloscope.
2. [40] Write a C language program to, here use 1:1 pre scaler, [Remove Delay Function from
Config.h].
Draw a PWM with 16KHz, and 25% Duty cycle or 50% if S3 is pressed.
Draw a PWM with 32KHz, and 25% Duty cycle 50% if S3 is pressed.
Draw a PWM with 10KHz, and 30% Duty cycle 40% if S3 is pressed.
Draw a PWM with 5KHz, and 10% Duty cycle 35% if S3 is pressed.
Lab5_ES_W23_Muhammed Abdulrahman
2|Page
3. [30] Do the following waveforms using Timer1 Interrupts, accurately determine the PR1 value
here, check on the oscilloscope.
#include "Config.h"
void main(void)
{
_TRISA0=0;
_T1IF=0;
_T1IP=1; // 0 disable
_T1IE=1;
while(1);
}
Lab Report
To be considered complete, the Lab report should contain the following information:
1. Cover sheet.
2. Brief discussion about LCD.
3. Questions and Source Codes of all items in the lab work.
4. Keep your codes well documented.
5. Conclusion.
Lab5_ES_W23_Muhammed Abdulrahman
3|Page
Lab5_ES_W23_Muhammed Abdulrahman
4|Page
Lab5_ES_W23_Muhammed Abdulrahman
5|Page
Lab5_ES_W23_Muhammed Abdulrahman
6|Page
Lab Tips:
IF (!S3) TFLY= 1600 for On, and 4000 for Off , ELSE TFLY= 1200 for On, and
4000 for Off .
PWM with 8KHz, and 10% Duty cycle, or 50% if S3 (active low) is pressed.
IF (!S3) TFLY= 1000 for On, and 2000 for Off , ELSE TFLY= 200 for On, and
2000 for Off.
Lab5_ES_W23_Muhammed Abdulrahman