EE313 Lab 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

EE313: Microprocessor Applications

LAB 3: Timer Counter Applications with


PIC micro-controller

NAMES: ALVISH NAIDU, AVISHAY NARAYAN

STUDENT ID: S11158221, S11158219


DATE: 12/03/2020

Aim
To comprehend the timer initialization in PIC 18F8722
Introduction
Frequency is characterized as number of cycles every second. It can likewise be characterized as
reciprocal of absolute time 'T'.
Frequency counters are test instruments used to give exact estimations of the recurrence of a
sign. Frequency counters are test instruments utilized in numerous applications related with radio
frequency engineering to quantify the recurrence of signs precisely.
A prescaler is an electronic checking circuit used to decrease a high recurrence electrical sign to
a lower recurrence by whole number division. The reason for the prescaler is to permit the clock
to be timed at the rate a client wants.
In this lab students are required to find the best prescaler to create a trigger at every fifteen
seconds. Also, students are required to display both the lab partners name on the lcd display. And
finally students are required to generate the frequency in the lcd that they have set in the
frequency generator.
Results
Task 1 (15 sec delay)
Prescaler=256
8bit Timer0 mode

#include <18F8722.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
int16 i=0;
int lowt=0;
#INT_TIMER0
void interrupt_tim0(){ // program automatically jump on ISR when overflow occurred
i++;
if(i==1145){ // check for about 15sec
if(lowt==1)lowt=0;
else lowt=1;
i=0;
}
if(lowt==0)output_high(PIN_B4); // LED OFF
else output_low(PIN_B4); // LED ON
}
main() {
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);//Timer 0 setup
enable_interrupts(INT_RTCC);//enable timer0
enable_interrupts(GLOBAL);//enable global interrupts
output_low(PIN_B4); // LED ON
while(1); // Wait for the interrupt
}
Prescaler =128
8bit Timer0 mode

#include <18F8722.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
int16 i=0;
int lowt=0;
#INT_TIMER0
void interrupt_tim0(){ // program automatically jump on ISR when overflow occurred
i++;
if(i==2289){ // check for about 15sec
if(lowt==1)lowt=0;
else lowt=1;
i=0;
}
if(lowt==0)output_high(PIN_B4); // LED OFF
else output_low(PIN_B4); // LED ON
}
main() {
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128|RTCC_8_BIT);//Timer 0 setup
enable_interrupts(INT_RTCC);//enable timer0
enable_interrupts(GLOBAL);// enable global interrupts
output_low(PIN_B4); // LED ON
while(1); // Wait for the interrupt
}
Prescaler=64
8bit Timer0 mode

#include <18F8722.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
int16 i=0;
int lowt=0;
#INT_TIMER0
void interrupt_tim0(){ // program automatically jump on ISR when overflow occurred
i++;
if(i==4578){ // check for about 15sec
if(lowt==1)lowt=0;
else lowt=1;
i=0;
}
if(lowt==0)output_high(PIN_B4); // LED OFF
else output_low(PIN_B4); // LED ON
}
main() {
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64|RTCC_8_BIT);//Timer 0 setup
enable_interrupts(INT_RTCC);//enable timer0
enable_interrupts(GLOBAL);// enable global interrupts
output_low(PIN_B4); // LED ON
while(1); // Wait for the interrupt
}
16bit Timer0 mode
Prescaler=256

#include <18F8722.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
int i=0;
int lowt=0;
#INT_TIMER0
void interrupt_tim0(){ // program automatically jump on ISR when overflow occurred
i++;
if(i==5){ // check for about 15sec
if(lowt==1)lowt=0;
else lowt=1;
i=0;
}
if(lowt==0)output_high(PIN_B4); // LED OFF
else output_low(PIN_B4); // LED ON
}
main() {
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);//Timer 0 setup
enable_interrupts(INT_RTCC);//enable timer0
enable_interrupts(GLOBAL); enable global interrupts
output_low(PIN_B4); // LED ON
while(1); // Wait for the interrupt
}

16bit Timer0 mode


Prescaler=128

#include <18F8722.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
int i=0;
int lowt=0;
#INT_TIMER0
void interrupt_tim0(){ // program automatically jump on ISR when overflow occurred
i++;
if(i==9){ // check for about 15sec
if(lowt==1)lowt=0;
else lowt=1;
i=0;
}
if(lowt==0)output_high(PIN_B4); // LED OFF
else output_low(PIN_B4); // LED ON
}
main() {
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);//Timer 0 setup
enable_interrupts(INT_RTCC);//enable timer0
enable_interrupts(GLOBAL); enable global interrupts
output_low(PIN_B4); // LED ON
while(1); // Wait for the interrupt
}

16bit Timer0 mode


Prescaler=64

#include <18F8722.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
int i=0;
int lowt=0;
#INT_TIMER0
void interrupt_tim0(){ // program automatically jump on ISR when overflow occurred
i++;
if(i==18){ // check for about 15sec
if(lowt==1)lowt=0;
else lowt=1;
i=0;
}
if(lowt==0)output_high(PIN_B4); // LED OFF
else output_low(PIN_B4); // LED ON
}
main() {
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);//Timer 0 setup
enable_interrupts(INT_RTCC);//enable timer0
enable_interrupts(GLOBAL);// enable global interrupts
output_low(PIN_B4); // LED ON
while(1); // Wait for the interrupt
}

Task 2
Name Display Code

#include <18F8722.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
#include "lcd.c" // inbuilt LCD library
main() {
lcd_init(); // Initialise the LCD
lcd_putc('\f'); // clear the screen
lcd_putc("EE313 LAB 3\n AVISHAY NARAYAN");
}//end program

Fig [1]: Name of first lab partner

#include <18F8722.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
#include "lcd.c" // inbuilt LCD library
main() {
lcd_init(); // Initialise the LCD
lcd_putc('\f'); // clear the screen
lcd_putc("EE313 LAB 3\n ALVISH NAIDU");
}//end program
Fig [2]: Name of second lab partner
Frequency Counter Code

#include <18F8722.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
#include "lcd.c" // inbuilt LCD library
unsigned int16 value;
main() {
lcd_init(); // Initialise the LCD
lcd_putc('\f'); // clear the screen
lcd_putc("FREQUENCY:");
while(1)
{
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);//take external clock input T1CKI
delay_ms(1000); // wait for some time to settle timer
setup_timer_1(T1_DISABLED); // disable timer 1 to read present count

lcd_gotoxy(1,16);
printf(lcd_putc,"%LU",value); //LCD display of Frequency count
}
}// end of program

Fig [3]: Signal Gen 15KHz Square Wave


Fig [4]: LCD Frequency Count Display

Fig [5]: Signal Gen 50KHz Square Wave

Fig [6]: LCD Frequency Count Display


Fig [7]: Signal Gen 30KHz Square Wave

Fig [8]: LCD Frequency Count Display


Discussion
The code for task one provided in the results is for timer0 using 256,128 and 64 as the prescaler
and using both 8bit and 16bit mode. The quickest time was measured to be for prescaler 8 of
timer 0 using stopwatch on phone.
For task two, the first activity involved display of name on LCD. Fig [1] ad Fig [2] shows the
name of the two lab partners. The second activity involved programming the PIC microcontroller
to count the frequency of the square wave signal generated by the signal generator and display on
LCD. Three trials were conducted at different frequencies as shown in Fig [3], Fig [4], Fig [5],
Fig [6], Fig [7] and Fig [8].

Conclusion
After completing this lab, students have learnt how to use the different prescalers to generate
square waves (triggers) as the output and have also learnt the different codes in PCW compiler
for PIC C to generate square waves (triggers) as the output and also to show the frequency that is
generated by a signal generator.
Reference
Fig [1]: Name of first lab partner
Fig [2]: Name of second lab partner
Fig [3]: Signal Gen 15KHz Square Wave
Fig [4]: LCD Frequency Count Display
Fig [5]: Signal Gen 50KHz Square Wave
Fig [6]: LCD Frequency Count Display
Fig [7]: Signal Gen 30KHz Square Wave
Fig [8]: LCD Frequency Count Display
[1]"Prescaler - an overview | ScienceDirect Topics", Sciencedirect.com, 2020. [Online]. Available:
https://www.sciencedirect.com/topics/engineering/prescaler. [Accessed: 22- Mar- 2020].

[2]"What is a Frequency Counter & Counter Timer » Electronics Notes", Electronics-notes.com, 2020.
[Online]. Available: https://www.electronics-notes.com/articles/test-methods/frequency-counter-
timer/what-is-a-frequency-counter-timer.php. [Accessed: 22- Mar- 2020].

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy