0% found this document useful (0 votes)
16 views6 pages

Lab#6 Timers

Uploaded by

vruchat05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

Lab#6 Timers

Uploaded by

vruchat05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1|Page

Lab#6 Timers Part1_Timers Polling & Interrupts


In-Person, Due is Next Week
Objectives:
 To be familiar with PIC24F Timers.
 Be familiar with the process of downloading and debugging programs on PIC24 microcontroller
using ICD 3.

Equipment and Tools:


 Personal Computer
 Explorer 16 Development Board
 In-Circuit Debugger (ICD 3)
 USB A/B cable
 9V DC adapter
 Oscilloscop.
 MPLAB X Integrated Development Environment v6.0

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;

PR1=31250; // 500ms/16us = 31250 clock


// 1000ms/16us = 62500 near maximum
T1CON =0x8030; // 32MHz32/2/256 = 16 uSec for 1 Clock Cycle

while(1);
}

void _ISR _T1Interrupt(void)


{
_LATA0 =~_LATA0; // or _LATA0 ^=1;
_T1IF =0;

Update the delay to be as follow and test the code.


 250 ms >> PR1 =
 1 ms >> PR1 =
 10 ms >> PR1 =
 50 ms >> PR1 =

Time for on is: -


 250 ms >> Lab Tip>>> PR1 = 250*1000u/16u = 15625 >>> PR1
 1 ms >>
 10 ms >>
 50 ms >> Lab Tip>> PR1 = 50 000u/16u = 3125

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

//Add the following to your code


#define s3 PORTDbits.RD6
#define s6 PORTDbits.RD7
#define s5 PORTAbits.RA7 //Port A
#define s4 PORTDbits.RD13

#define s3_Control _TRISD6


#define s6_Control _TRISD7
#define s5_Control _TRISA7 //Port A
#define s4_Control _TRISD13

Lab5_ES_W23_Muhammed Abdulrahman
5|Page

ilar solution for Lab6

Lab5_ES_W23_Muhammed Abdulrahman
6|Page

Lab Tips:

Write a program using Timer1 to generate.


 PWM with 4KHz, and 30% Duty cycle, or 40% if S3 (active low) is pressed.

(Timer Polling) with PS 1:1 or 0.0625Usec


1/4KHz = 250Usec = Period, TFLY = 250u/0.0625u < 4000

Ton = 4000 * 0.3 =1200 Counts, TFLY< 1200


Toff = 4000 * 0.7= 2800, (Ton + Toff), TFLY< (1200 + 2800) or < 4000

Ton = 4000 * 0.4 = 1600 Counts


Toff = 4000-1600 = 2400, (Ton + Toff), TFLY< (2400 + 1600) or < 4000

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.

(Timer Polling) with PS 1:1


1/8KHz = 125Usec = Period, TFLY < 2000

Ton = 2000 * 0.1 =200 Counts, TFLY< 200


Toff = 2000 * 0.9= 1800, (Ton + Toff), TFLY< (200 + 1800) or < 2000

Ton = 2000 * 0.5 = 1000 Counts


Toff = 2000-1000 = 1000, (Ton + Toff), TFLY< (200 + 1800) or < 2000

IF (!S3) TFLY= 1000 for On, and 2000 for Off , ELSE TFLY= 200 for On, and
2000 for Off.

Lab5_ES_W23_Muhammed Abdulrahman

You might also like