MPMC Project K&N

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

TIME PERIOD

MEASUREMENT
PROJECT BY KULDEEP SINGH(B220974EE)
AND NAVNEET (B220430EE)
ACKNOWLEDGEMENT

We are heartly thankful and we would like to express our sincere


gratitude towards Dr . Nikhil Sasidharan for his guidance and support
for completion of our project.
INTRODUCTION
• A project designed to measure the time period of a signal using a PIC
microcontroller, the working mechanism focuses on capturing signal
transitions and calculating the time between them.
• In this project, we will measure the time period between two events,
such as two rising edges of a digital signal. The goal is to output the
calculated time period through a simple interface, like an LCD display
or a serial connection.
• A PIC18F452 microcontroller has been used in the model along with
LCD display and a pulse generator circuit.
APPARATUS REQUIRED
• PIC 18F452
• IC555
• Crystal Oscillator(8MHz)
• LCD Display 16*2
• 10k Potentiometer
• Resisters
• Capacitors
• IC Regulator
• 5V DC Supply
CIRCUIT DIAGRAM
CONSTRUCTION
• Attach the PIC on a breadboard . Connect the LCD Display to the PIC
according to the connections shown in the circuit diagram.
• Develop a pulse generator circuit and connect it properly to the PIC
for required input. Similarly, connect potentiometer, resistors,
capacitors and crystal oscillator accordingly.
• Now, since a 5V DC Supply is required, we use a IC regulator along
with the 9V battery to get the desired supply.
• The circuit is ready, so its time to load the PIC with the code. Remove
the PIC and place it in a burner and load the following code in it.
CODE
// lcd module connections
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D4 at RC2_bit;
sbit LCD_D5 at RC3_bit;
sbit LCD_D6 at RC4_bit;
sbit LCD_D7 at RC5_bit;

sbit LCD_RS_Direction at TRISC0_bit;


sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D4_Direction at TRISC2_bit;
sbit LCD_D5_Direction at TRISC3_bit;
sbit LCD_D6_Direction at TRISC4_bit;
sbit LCD_D7_Direction at TRISC5_bit;
// end lcd module connections
CODE CONTI…
int pulse = 0;
float period = 0;
char text[15];
void interrupt(){
if(INTCON.RBIF ==1){
INTCON.RBIE = 0; // Disable the port change interrupt
if(PORTB.F4==1){
T1CON.TMR1ON = 1;
}

if(PORTB.F4==0){
T1CON.TMR1ON = 0; // Stop timer1
pulse = ((TMR1H<<8)|(TMR1L));
TMR1H = 0;
TMR1L = 0;
}
CODE CONTI…
}
INTCON.RBIE = 1; // Enable the port change interrupt
INTCON.RBIF = 0;
}
void main() {
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,3,"Time Period");
Lcd_Out(2,3,"Measurement");
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,3,"Developed by");
Lcd_Out(2,1,"KULDEEP NAVNEET");
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
INTCON.RBIE = 1;
TRISB = 0X10;
PORTB = 0X00;
INTCON.GIE = 1; // Enable global interrupt
CODE CONTI…
INTCON.RBIF = 0; // Clear the port change interrupt flag
INTCON.RBIE = 1; // Enable port change interrupt
TMR1CS_bit = 0;
T1SYNC_bit = 1;
T1CKPS0_bit = 1;
T1CKPS1_bit = 1;
TMR1ON_bit = 1;
TMR1H = 0;
TMR1L = 0;

while(1){
period = pulse / 125.0;
if(period<0){
//Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Out of Range");
Lcd_Out(2,1,"Min T.Pri 250ms");
}
CODE CONTI…
else if(period>0){
//Lcd_Cmd(_LCD_CLEAR);
floatToStr(period,text);
text[5] = 0 ;
Lcd_Out(1,1,"Time Period:");
Lcd_Out(2,6,"ms ");
Lcd_Out(2,1,text);
}
delay_ms(500);
}

}

CALCULATION
Oscilator Frequency = 8MHz
Internal clock Frequency = 8MHz / 4 = 2MHz
Prescaler value = 1:8
Timer1 value = (TMR1H : TMR1L) = (TMR1H<<8) | (TMR1L)

1second ,Timer1 count pulses = ((8MHz / 4) / 8) /


= 250000

1ms , Timer1 count pulses = 125000/1000


= 250
CONTINUE…
assume,
Pulse Generator Frequency = 1KHz
T = 1ms
T = Ton + Toff, Ton = Toff
Ton = (1 / 2)ms
= 0.5ms

Ther Timer1 count internal pulse at Ton time of Pulse Generator.


Ton = T / 2

0.5ms, Timer1 count pulses = 250 / 2


= 125

thence,
Timer Period of Pulse Generator signal = pulses / 125 ms
THE PROJECT
WORKING
• After loading the PIC with the code, connect it in the breadboard in
the exact position as it was connected before.
• Properly connect terminals of the battery to the IC regulator to get
the required voltage input to the circuit.
• Now vary the pulse using 10k potentiometer connected to the IC555
to get different time periods for different pulses.
• Observe the time periods on the LCD display.
PRECAUTOINS
• Verify the circuit connections with the diagram again.
• Check in another circuit if the LCD is working.
• If the LCD doesn’t glow on connecting the battery, try checking the
circuit again for loose connections.
• After loading the PIC, verify to check if code has been read.
• If it still doesn’t work, try using another PIC or another circuit for
pulse generator.
CONCLUSION
The program initializes an LCD display, measures the time
period of a signal using Timer1 and interrupts, and displays
the result on the LCD. It includes error handling for out-of-
range periods. This project showcases the use of interrupts,
timers, and LCD interfacing in a PIC microcontroller
application.
BIBLIOGRAPHY
• PIC Microcontroller by M. Ali Mazidi
• https://www.electronicsforu.com/technology-trends/learn-
electronics/16x2-lcd-pinout-diagram
• https://www.microchip.com/en-us/product/pic18f452

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