SlideShare una empresa de Scribd logo
1 de 25
CHAPTER 1
INTRODUCTION
1.1 Introduction
As already mentioned in the abstract, power systems are mainly characterized by
their voltage and frequency. In general we can broadly classify the power systems
across the world into four major groups
1. 100-127V, 50Hz.
2. 100-127V, 60Hz.
3. 220-240V, 50Hz.
4. 220-240V, 60Hz.
(The voltages mentioned above are the R.M.S values and the peak values can
be obtained by multiplying the corresponding voltages with 1.414)
Presently, the frequencies employed mainly are 50Hz (20ms time period) and
60Hz (16.66ms time period). In India the normal system frequency is 50Hz. As
electricity cannot be stored, the instantaneous generation must match the demand
being taken from the system. If the instantaneous demand is higher than the
generation, the system frequency will fall. Conversely, if the instantaneous
generation is higher than the demand, the frequency will rise. System frequency
will therefore vary around the 50 Hz target and Grid has statutory obligations to
maintain the frequency within +/- 0.5Hz around this level.
So there is a requirement of continuous monitoring of mains frequency in
keeping a check on power fluctuations which is highly important as there are
many frequency sensitive instruments like the pulse dependent clocks which will
run slower or faster dependent on mains frequency. Also some losses acquired in
AC machines are dependent on the supply frequency.
1
1.2 Objective:
The main objective of the project is to build an inexpensive frequency measuring
device, especially here to measure the supply mains frequency using a PIC
microcontroller. The range of measurement of frequency is from 10Hz to 125KH
(the pre scaler value set to 4).
1.3 Outline of the project:
1. The AC mains supply is first stepped down using a step down transformer ( ), and
is fed to a near zero detector circuit.
2. This output is given to a microcontroller which measures the frequency based on
an algorithm and displays it on an LCD screen.
2
CHAPTER 2
MODEL DESCRIPTION:
2.1 Block diagram
Fig,1.
2.2 Components Used
1. PIC18F4520 Microcontroller.
2. 16X2 LCD
3. 20MHz Crystal Oscillator
4. Voltage Regulator IC7805
5. BC107 BJT.
6. IN4148 Diode
7. Resistors
8. Capacitors
3
2.3 Near Zero Detection Circuit
Fig.2.
Fig.3
4
Firstly the mains supply is stepped down from 230V to 9V by means of a step
down transformer and then it is rectified using a bridge rectifier. The full wave
rectified signal is applied to at the base of transistor whose output is normally
low. As the input signal to the transistor drops to a value below 0.7V the transistor
turns off and the collector voltage rises to +5V supply voltage as shown in the
fig.3. Three pulses of this output constitute one full period of mains frequency.
These pulses are then fed to the PIC microcontroller.
2.4 PIC18F4520 Microcontroller
The output of the near zero detector is fed to the 2nd
pin of PORTC of the PIC.
The input to this pin is continuously monitored for a high pulse (by the command
BTFSS)
The PIC microcontroller starts an accurate timer when the first pulse arrives and
the timer stops when the third pulse arrives. Thus the timer count is proportional
to the period and hence the frequency of the waveform. The timer count which is
in hex is converted into ASCII and then to the real frequency by an appropriate
formula and is displayed on an LCD display.
2.6 Cost and Management
S.No Components Quantity Cost(rupees)
1. Transformer (220V/9V) 1 100.00
2. Diodes (IN4008) 4 2.00
3. Resistors (10K Ohms) 3 1.00
4. PIC 18f4520(sampled) 1 70.00
5. Crystal Oscillator 1 0.50
6. LCD Screen(16X2) 1 150.00
7. Voltage regulator IC (LM7805) 1 5.00
8. PCB, Capacitors and Miscellaneous 50.00
Total cost = 278
NOTE:UART to USB converter(required for data loging in computer) 500rs
5
CHAPTER-3
OPERATION
3.1 Operation in detail
The output pulses of the near zero detector circuit are counted using 16-bit timer
or counter of the microcontroller (Here timer1 is used). A 20 MHz crystal
oscillator with a counting period is 0.2micro sec and maximum count is 65536. In
perfect 50Hz signal with 20ms period the maximum count will be 25000. The
frequency of the waveform is given by the formula. (Pre-scaler 4)
F= (1.25x106
)
Count
By considering that a difference of one count can be measured, the accuracy
measurement is then given by approximately 0.001Hz. For counting 3 pulses we
have roughly eight instructions and the minimum time required by the PIC to
execute these completely is around 8micro s.
6
3.2 Algorithm
Initiate global program variables
Configure LCD
clear timer/ counter TMR1
Wait until the first low to high transition occurs
start timer/ counter TMR1
wait until second low to high
transition of the pulse
wait until third low to high pulse
transition of the pulse
get timer/ counter value
calculate the frequency
display the frequency on LCD
wait for 5 seconds
END
7
3.3 Description of the Algorithm
Basically the program runs in an endless loop. In the main loop the following steps
are performed:
1. Initially Timer1 which is a 16-bit register is cleared ( actually two 8 bit registers
TMR1H, TMR1L are cleared).
2. The prescaler value is set so that the frequency is divided by 4 i.e., 20/(4x4) =
1.25.
3. Now the PORTA 2 is configured as i/p port and is continuously monitored and the
timer is started at the starting of the first pulse and stopped at the ending of the
third pulse.
4. Now the value from the TMRIH and TMRIL are brought to two registers NUMH
NUML, i.e the value of the count present in hex format. Then it is converted into
the ASCII format.
5. PORTD and PORTC are configured as o/p ports and PORTD for LCD data (i.e
they are connected to db0 to db7) and PORTC(4,5,6) is for the LCD control.
Then the count value is sent to the LCD (detailed program is appended in
appendix A)
8
CHAPTER 4
RESULTS AND DISCUSSION
4.1 RESULT
1. Near-Zero detector was set up and soldered on PCB and it was tested for the
required output.
2. The Program written for this project was simulated for results (on PROTEUS
V7.2) and then is flashed on the PIC microcontroller.
3. LCD is interfaced with the microcontroller and the timer 1 count is displayed on
the LCD Screen.
9
CHAPTER 5
CONCLUSION
5.1 CONCLUSION
An inexpensive frequency measuring device using PIC18f4520 was developed and
constructed on a PCB and tested for results.
5.2 FUTURE SCOPE OF THE PROJECT:
If can be looked into, the project can be extended to data logging i.e., the readings
acquired in these measurements will be logged into a computer by the following
procedure:
1. After the measurement the output of the PIC microcontroller will be given to a
MAX 232 IC Module which converts the PIC TTL to RS232 protocol. The RS-
232 serial communication protocol is a standard protocol used in
asynchronous serial communication. It is the primary protocol used over modem
lines. It is the protocol used by the MICRO STAMP11 when it communicates
with a host PC.
2. Through this serial communication protocol the measurement data is logged into
the computer and this data can be used for various purposes like plotting graphs of
frequency versus time.
Similarly measuring various power system parameters like voltage, current and
power factor at the same time i.e., developing a multi-purpose Meter and logger,
10
employing a microcontroller or microprocessor modules like RASPBERRY PI,
ARDUINO etc.
References
PIC 18f4520 Datasheet: ww1.microchip.com/downloads/en/devicedoc/39631e.pdf
Rs232 standards: http://www.omega.com/techref/pdf/RS-232.pdf
11
APPENDIX A
i. CODE
LIST P=PIC18F4520
#INCLUDE P18F4520.INC
CONFIG OSC=HS, IESO=OFF
CONFIG WDT=OFF
CONFIG BORV=3, PWRT=ON, BOREN=ON
_ui_TenK EQU 0x20
_ui_Thou EQU 0x21
_ui_Hund EQU 0x22
_ui_Tens EQU 0x23
_ui_Ones EQU 0x24
_ui_NumH EQU 0x25
_ui_NumL EQU 0x26
LCD_DATA EQU PORTD
LCD_CTRL EQU PORTC
RS EQU RC5
RW EQU RC6
EN EQU RC7
ORG 0H
Z4 MOVLW 0X0F
MOVWF ADCON1
12
B7 MOVLW 0X20
MOVWF T1CON
CLRF TRISD
CLRF TRISC
BSF TRISA,2
MOVLW 0H
MOVWF TMR1H
MOVWF TMR1L
CALL LDELAY
B1 BTFSS PORTA,2
BRA B1
B2 BTFSC PORTA,2
BRA B2 ; we left first pulse to make sure we dont start counting in the middle of
the wave
BSF T1CON,0
B3 BTFSS PORTA,2
BRA B3
B4 BTFSC PORTA,2
BRA B4
B5 BTFSS PORTA,2
BRA B5
B6 BTFSC PORTA,2
BRA B6 ;here we get time for three pulses
BCF T1CON,0
MOVFF TMR1H,_ui_NumH ; we start converting 16bit hex value we got in
above timer to ascii values to be displayed on lcd
MOVFF TMR1L, _ui_NumL
13
MOVLW 0x00
SWAPF _ui_NumH,w
ANDLW 0x0F
ADDLW 0xF0
MOVWF _ui_Thou
ADDWF _ui_Thou,f
ADDLW 0xE2
MOVWF _ui_Hund
ADDLW 0x32
MOVWF _ui_Ones
MOVF _ui_NumH,w
ANDLW 0x0F
ADDWF _ui_Hund,f
ADDWF _ui_Hund,f
ADDWF _ui_Ones,f
ADDLW 0xE9
MOVWF _ui_Tens
ADDWF _ui_Tens,f
ADDWF _ui_Tens,f
SWAPF _ui_NumL,w
ANDLW 0x0F
ADDWF _ui_Tens,f
ADDWF _ui_Ones,f
RLCF _ui_Tens,f
RLCF _ui_Ones,f
COMF _ui_Ones,f
RLCF _ui_Ones,f
14
MOVF _ui_NumL,w
ANDLW 0x0F
ADDWF _ui_Ones,f
RLCF _ui_Thou,f
MOVLW 0x07
MOVWF _ui_TenK
MOVLW 0x0A
Lb1:
;addwf _ui_Ones,f
DECF _ui_Tens,f
ADDWF _ui_Ones,f
BTFSS STATUS,C ;
GOTO Lb1
Lb2:
;addwf _ui_Tens,f
DECF _ui_Hund,f
ADDWF _ui_Tens,f
BTFSS STATUS,C
GOTO Lb2
Lb3:
;addwf _ui_Hund,f
DECF _ui_Thou,f
ADDWF _ui_Hund,f
BTFSS STATUS,C
GOTO Lb3
Lb4:
;addwf _ui_Thou,f
15
DECF _ui_TenK,f
ADDWF _ui_Thou,f
BTFSS STATUS,C
GOTO Lb4
; Convert to ASCII
MOVLW 0x30
ADDWF _ui_Ones,F
ADDWF _ui_Tens,F
ADDWF _ui_Hund,F
ADDWF _ui_Thou,F
ADDWF _ui_TenK,F
CLRF TRISD ; at this point we start sending ascii values to lcd
CLRF TRISC
BCF LCD_CTRL,EN
CALL LDELAY
CALL READY
MOVLW 0X38
CALL COMMAND
CALL LDELAY
CALL READY
MOVLW 0X0E
CALL COMMAND
CALL LDELAY
CALL READY
MOVLW 0X01
CALL COMMAND
CALL LDELAY
CALL READY
MOVLW 0X06
16
CALL COMMAND
CALL LDELAY
CALL READY
MOVLW 0X86
CALL COMMAND
CALL LDELAY
CALL READY
MOVF _ui_TenK,W
CALL DATA_DISPLAY
CALL LDELAY
CALL READY
MOVF _ui_Thou,W
CALL DATA_DISPLAY
CALL LDELAY
CALL READY
MOVF _ui_Hund,W
CALL DATA_DISPLAY
CALL LDELAY
CALL READY
MOVF _ui_Tens,W
CALL DATA_DISPLAY
CALL LDELAY
CALL READY
MOVF _ui_Ones,W
CALL DATA_DISPLAY
CALL LDELAY
CALL READY
HERE BRA HERE
COMMAND MOVWF LCD_DATA ; syntax for commands to lcd
BCF LCD_CTRL,RS
17
BCF LCD_CTRL,RW
BSF LCD_CTRL,EN
CALL SDELAY
BCF LCD_CTRL,EN
RETURN
DATA_DISPLAY MOVWF LCD_DATA ; syntax for data display
BSF LCD_CTRL,RS
BCF LCD_CTRL,RW
BSF LCD_CTRL,EN
CALL SDELAY
BCF LCD_CTRL,EN
RETURN
READY SETF TRISD
BCF LCD_CTRL,RS
BSF LCD_CTRL,RW
BACK BSF LCD_CTRL,EN
CALL SDELAY
BCF LCD_CTRL,EN
BTFSC LCD_DATA,7
BRA BACK
CLRF TRISD
RETURN
SDELAY MOVLW D'255'
B10 DECF WREG
BNZ B10
RETURN
LDELAY MOVLW 0X08 ; code for causing delay of 13.5seconds
MOVWF T0CON
MOVLW 0XCF
MOVWF TMR0H
18
MOVLW 0X2C
MOVWF TMR0L
BSF T0CON,TMR0ON
AGAIN BTFSS INTCON,TMR0IF
BRA AGAIN
BCF T0CON,TMR0ON
BCF INTCON,TMR0IF
RETURN
MOVLW 0X0F
MOVWF T0CON
CLRF TMR0H
CLRF TMR0L
BSF T0CON,TMR0ON
Z2 BTFSS
BRA Z2
BCF INTCON,TMR0IF
GOTO Z4
END
19
20
DETAILED CKT DIAGRAM
21
APPENDIX B
RS232 PROTOCOL
Fig.4
The above figure shows the relationship between the various components in a
serial ink. These components are the UART, the serial channel, and the interface
logic. An interface chip known as the universal asynchronous receiver/transmitter
or UART is used to implement serial data transmission. The UART sits between
the host computer and the serial channel. The serial channel is the collection of
wires over which the bits are transmitted. The output from the UART is a
standard TTL/CMOS logic level of 0 or 5 volts. In order to improve bandwidth,
remove noise, and increase range, this TTL logical level is converted to an RS-
232 logic level before being sent out on the serial channel. This conversion is
done by the interface logic shown in the above figure. Usually in the systems the
interface logic is implemented by the comm stamp.
A frame is a complete and nondivisible packet of bits. A frame includes both
information (e.g., data and characters) and overhead (e.g., start bit, error checking
and stop bits). In asynchronous serial protocols such as RS-232, the frame
consists of one start bit, seven or eight data bits, parity bits, and stop bits. A
timing diagram for an RS-232 frame consisting of one start bit, 7 data bits, one
parity bits and two stop bits. Note that the exact structure of the frame must be
22
agreed upon by both transmitter and receiver before the comm-link must be
opened.
Most of the bits in a frame are self-explanatory. The start bit is used to signal the
beginning of a frame and the stop bit is used to signal the end of a frame. The
only bit that probably needs a bit of explanation is the parity bit. Parity is used to
detect transmission errors. For even parity checking, the number of 1's in the data
plus the parity bit must equal an even number. For odd parity, this sum must be an
odd number. Parity bits are used to detect errors in transmitted data. Before
sending out a frame, the transmitter sets the parity bit so that the frame has either
even or odd parity. The receiver and transmitter have already agreed upon which
type of parity check (even or odd) is being used. When the frame is received, then
the receiver checks the parity of the received frame. If the parity is wrong, then
the receiver knows an error occurred in transmission and the receiver can request
that the transmitter re-send the frame.
23
APPENDIX C
SIMULATION REPORTS
24
25

Más contenido relacionado

La actualidad más candente

Serial communication in LPC2148
Serial communication in LPC2148Serial communication in LPC2148
Serial communication in LPC2148sravannunna24
 
Tutorial 8 frequency counter
Tutorial 8   frequency counterTutorial 8   frequency counter
Tutorial 8 frequency counterBrit4
 
Fun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol WorksFun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol WorksRitesh Kanjee
 
Sereial com. ppt
Sereial com. pptSereial com. ppt
Sereial com. pptgaurav5345
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)cairo university
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)Mashood
 
Sensor de pressão de pneu
Sensor de pressão de pneuSensor de pressão de pneu
Sensor de pressão de pneuCarlos Vergara
 
FPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLERFPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLERVarun Kambrath
 
Imx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOKImx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOKShahrukh Javed
 
PREPARATION OF C&I CABLE SCHEDULES FOR DCS PANELS
PREPARATION OF C&I CABLE SCHEDULES FOR DCS PANELSPREPARATION OF C&I CABLE SCHEDULES FOR DCS PANELS
PREPARATION OF C&I CABLE SCHEDULES FOR DCS PANELSAjit Kumar
 
8051 serial communication1
8051 serial communication1 8051 serial communication1
8051 serial communication1 vijaydeepakg
 
Measuring the cutoff frequency of a low pass filter
Measuring the cutoff frequency of a low pass filterMeasuring the cutoff frequency of a low pass filter
Measuring the cutoff frequency of a low pass filterHasnain Ali
 
ELECTRONIC MEASUREMENT AND INSTRUMENT: WAVE ANALYZER
ELECTRONIC MEASUREMENT AND INSTRUMENT: WAVE ANALYZERELECTRONIC MEASUREMENT AND INSTRUMENT: WAVE ANALYZER
ELECTRONIC MEASUREMENT AND INSTRUMENT: WAVE ANALYZERShivangiSingh241
 

La actualidad más candente (20)

Serial communication in LPC2148
Serial communication in LPC2148Serial communication in LPC2148
Serial communication in LPC2148
 
Timers and pwm
Timers and pwmTimers and pwm
Timers and pwm
 
Tutorial 8 frequency counter
Tutorial 8   frequency counterTutorial 8   frequency counter
Tutorial 8 frequency counter
 
Fun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol WorksFun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol Works
 
Sereial com. ppt
Sereial com. pptSereial com. ppt
Sereial com. ppt
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)
 
8051 serial communication-UART
8051 serial communication-UART8051 serial communication-UART
8051 serial communication-UART
 
Lecture 10 _serial_communication
Lecture 10 _serial_communicationLecture 10 _serial_communication
Lecture 10 _serial_communication
 
UART
UARTUART
UART
 
Sensor de pressão de pneu
Sensor de pressão de pneuSensor de pressão de pneu
Sensor de pressão de pneu
 
FPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLERFPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLER
 
Imx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOKImx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOK
 
PREPARATION OF C&I CABLE SCHEDULES FOR DCS PANELS
PREPARATION OF C&I CABLE SCHEDULES FOR DCS PANELSPREPARATION OF C&I CABLE SCHEDULES FOR DCS PANELS
PREPARATION OF C&I CABLE SCHEDULES FOR DCS PANELS
 
Pdf tp3076 national
Pdf tp3076 nationalPdf tp3076 national
Pdf tp3076 national
 
Uart
UartUart
Uart
 
8051 serial communication1
8051 serial communication1 8051 serial communication1
8051 serial communication1
 
Measuring the cutoff frequency of a low pass filter
Measuring the cutoff frequency of a low pass filterMeasuring the cutoff frequency of a low pass filter
Measuring the cutoff frequency of a low pass filter
 
ELECTRONIC MEASUREMENT AND INSTRUMENT: WAVE ANALYZER
ELECTRONIC MEASUREMENT AND INSTRUMENT: WAVE ANALYZERELECTRONIC MEASUREMENT AND INSTRUMENT: WAVE ANALYZER
ELECTRONIC MEASUREMENT AND INSTRUMENT: WAVE ANALYZER
 
Uart 16550
Uart 16550Uart 16550
Uart 16550
 

Similar a Measuring Mains Frequency Using PIC Microcontroller

EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfSPonmalar1
 
3) Remote Controlled Fan Regulator
3) Remote Controlled Fan Regulator3) Remote Controlled Fan Regulator
3) Remote Controlled Fan Regulatorsajin sr
 
Design of Counter Using SRAM
Design of Counter Using SRAMDesign of Counter Using SRAM
Design of Counter Using SRAMIOSRJECE
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
ANALOG TO DIGITALCONVERTOR FOR BLOOD-GLUCOSE MONITORING
ANALOG TO DIGITALCONVERTOR FOR  BLOOD-GLUCOSE MONITORING  ANALOG TO DIGITALCONVERTOR FOR  BLOOD-GLUCOSE MONITORING
ANALOG TO DIGITALCONVERTOR FOR BLOOD-GLUCOSE MONITORING csijjournal
 
Analog to Digitalconvertor for Blood-Glucose Monitoring
Analog to Digitalconvertor for Blood-Glucose MonitoringAnalog to Digitalconvertor for Blood-Glucose Monitoring
Analog to Digitalconvertor for Blood-Glucose Monitoringcsijjournal
 
Ultrasonic level meter
Ultrasonic level meterUltrasonic level meter
Ultrasonic level meterhandson28
 
ELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITY
ELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITYELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITY
ELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITYEldhose George
 
Pbl report kkkl 2174 electric analogue
Pbl report kkkl 2174 electric analoguePbl report kkkl 2174 electric analogue
Pbl report kkkl 2174 electric analogueHakim Futra
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programmingMohamed Ali
 
Digital Alarm Clock (IC-TMS-8560)
Digital Alarm Clock (IC-TMS-8560)Digital Alarm Clock (IC-TMS-8560)
Digital Alarm Clock (IC-TMS-8560)Chintan Patel
 
Design and Analysis of Temperature Sensor using CMOS Technology
Design and Analysis of Temperature Sensor using CMOS TechnologyDesign and Analysis of Temperature Sensor using CMOS Technology
Design and Analysis of Temperature Sensor using CMOS Technologyijsrd.com
 
Grid synchronisation
Grid synchronisationGrid synchronisation
Grid synchronisationmanogna gwen
 
Wireless greenhouse environment monitoring through sensors
Wireless greenhouse environment monitoring through sensorsWireless greenhouse environment monitoring through sensors
Wireless greenhouse environment monitoring through sensorsSudhanshu Tripathi
 

Similar a Measuring Mains Frequency Using PIC Microcontroller (20)

EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdf
 
3) Remote Controlled Fan Regulator
3) Remote Controlled Fan Regulator3) Remote Controlled Fan Regulator
3) Remote Controlled Fan Regulator
 
Digital stop watch
Digital stop watchDigital stop watch
Digital stop watch
 
Design of Counter Using SRAM
Design of Counter Using SRAMDesign of Counter Using SRAM
Design of Counter Using SRAM
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
ANALOG TO DIGITALCONVERTOR FOR BLOOD-GLUCOSE MONITORING
ANALOG TO DIGITALCONVERTOR FOR  BLOOD-GLUCOSE MONITORING  ANALOG TO DIGITALCONVERTOR FOR  BLOOD-GLUCOSE MONITORING
ANALOG TO DIGITALCONVERTOR FOR BLOOD-GLUCOSE MONITORING
 
Analog to Digitalconvertor for Blood-Glucose Monitoring
Analog to Digitalconvertor for Blood-Glucose MonitoringAnalog to Digitalconvertor for Blood-Glucose Monitoring
Analog to Digitalconvertor for Blood-Glucose Monitoring
 
rancang bangun NIIBP
rancang bangun NIIBPrancang bangun NIIBP
rancang bangun NIIBP
 
Ultrasonic level meter
Ultrasonic level meterUltrasonic level meter
Ultrasonic level meter
 
ELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITY
ELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITYELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITY
ELECTRONICS PROJECT REPORT OF HOME AUTOMATION CUM BUILDING SECUIRITY
 
Pbl report kkkl 2174 electric analogue
Pbl report kkkl 2174 electric analoguePbl report kkkl 2174 electric analogue
Pbl report kkkl 2174 electric analogue
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programming
 
Remote
RemoteRemote
Remote
 
Digital Alarm Clock (IC-TMS-8560)
Digital Alarm Clock (IC-TMS-8560)Digital Alarm Clock (IC-TMS-8560)
Digital Alarm Clock (IC-TMS-8560)
 
Design and Analysis of Temperature Sensor using CMOS Technology
Design and Analysis of Temperature Sensor using CMOS TechnologyDesign and Analysis of Temperature Sensor using CMOS Technology
Design and Analysis of Temperature Sensor using CMOS Technology
 
Chapter5 dek3133
Chapter5 dek3133Chapter5 dek3133
Chapter5 dek3133
 
Grid synchronisation
Grid synchronisationGrid synchronisation
Grid synchronisation
 
Wireless greenhouse environment monitoring through sensors
Wireless greenhouse environment monitoring through sensorsWireless greenhouse environment monitoring through sensors
Wireless greenhouse environment monitoring through sensors
 

Último

Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 

Último (20)

Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 

Measuring Mains Frequency Using PIC Microcontroller

  • 1. CHAPTER 1 INTRODUCTION 1.1 Introduction As already mentioned in the abstract, power systems are mainly characterized by their voltage and frequency. In general we can broadly classify the power systems across the world into four major groups 1. 100-127V, 50Hz. 2. 100-127V, 60Hz. 3. 220-240V, 50Hz. 4. 220-240V, 60Hz. (The voltages mentioned above are the R.M.S values and the peak values can be obtained by multiplying the corresponding voltages with 1.414) Presently, the frequencies employed mainly are 50Hz (20ms time period) and 60Hz (16.66ms time period). In India the normal system frequency is 50Hz. As electricity cannot be stored, the instantaneous generation must match the demand being taken from the system. If the instantaneous demand is higher than the generation, the system frequency will fall. Conversely, if the instantaneous generation is higher than the demand, the frequency will rise. System frequency will therefore vary around the 50 Hz target and Grid has statutory obligations to maintain the frequency within +/- 0.5Hz around this level. So there is a requirement of continuous monitoring of mains frequency in keeping a check on power fluctuations which is highly important as there are many frequency sensitive instruments like the pulse dependent clocks which will run slower or faster dependent on mains frequency. Also some losses acquired in AC machines are dependent on the supply frequency. 1
  • 2. 1.2 Objective: The main objective of the project is to build an inexpensive frequency measuring device, especially here to measure the supply mains frequency using a PIC microcontroller. The range of measurement of frequency is from 10Hz to 125KH (the pre scaler value set to 4). 1.3 Outline of the project: 1. The AC mains supply is first stepped down using a step down transformer ( ), and is fed to a near zero detector circuit. 2. This output is given to a microcontroller which measures the frequency based on an algorithm and displays it on an LCD screen. 2
  • 3. CHAPTER 2 MODEL DESCRIPTION: 2.1 Block diagram Fig,1. 2.2 Components Used 1. PIC18F4520 Microcontroller. 2. 16X2 LCD 3. 20MHz Crystal Oscillator 4. Voltage Regulator IC7805 5. BC107 BJT. 6. IN4148 Diode 7. Resistors 8. Capacitors 3
  • 4. 2.3 Near Zero Detection Circuit Fig.2. Fig.3 4
  • 5. Firstly the mains supply is stepped down from 230V to 9V by means of a step down transformer and then it is rectified using a bridge rectifier. The full wave rectified signal is applied to at the base of transistor whose output is normally low. As the input signal to the transistor drops to a value below 0.7V the transistor turns off and the collector voltage rises to +5V supply voltage as shown in the fig.3. Three pulses of this output constitute one full period of mains frequency. These pulses are then fed to the PIC microcontroller. 2.4 PIC18F4520 Microcontroller The output of the near zero detector is fed to the 2nd pin of PORTC of the PIC. The input to this pin is continuously monitored for a high pulse (by the command BTFSS) The PIC microcontroller starts an accurate timer when the first pulse arrives and the timer stops when the third pulse arrives. Thus the timer count is proportional to the period and hence the frequency of the waveform. The timer count which is in hex is converted into ASCII and then to the real frequency by an appropriate formula and is displayed on an LCD display. 2.6 Cost and Management S.No Components Quantity Cost(rupees) 1. Transformer (220V/9V) 1 100.00 2. Diodes (IN4008) 4 2.00 3. Resistors (10K Ohms) 3 1.00 4. PIC 18f4520(sampled) 1 70.00 5. Crystal Oscillator 1 0.50 6. LCD Screen(16X2) 1 150.00 7. Voltage regulator IC (LM7805) 1 5.00 8. PCB, Capacitors and Miscellaneous 50.00 Total cost = 278 NOTE:UART to USB converter(required for data loging in computer) 500rs 5
  • 6. CHAPTER-3 OPERATION 3.1 Operation in detail The output pulses of the near zero detector circuit are counted using 16-bit timer or counter of the microcontroller (Here timer1 is used). A 20 MHz crystal oscillator with a counting period is 0.2micro sec and maximum count is 65536. In perfect 50Hz signal with 20ms period the maximum count will be 25000. The frequency of the waveform is given by the formula. (Pre-scaler 4) F= (1.25x106 ) Count By considering that a difference of one count can be measured, the accuracy measurement is then given by approximately 0.001Hz. For counting 3 pulses we have roughly eight instructions and the minimum time required by the PIC to execute these completely is around 8micro s. 6
  • 7. 3.2 Algorithm Initiate global program variables Configure LCD clear timer/ counter TMR1 Wait until the first low to high transition occurs start timer/ counter TMR1 wait until second low to high transition of the pulse wait until third low to high pulse transition of the pulse get timer/ counter value calculate the frequency display the frequency on LCD wait for 5 seconds END 7
  • 8. 3.3 Description of the Algorithm Basically the program runs in an endless loop. In the main loop the following steps are performed: 1. Initially Timer1 which is a 16-bit register is cleared ( actually two 8 bit registers TMR1H, TMR1L are cleared). 2. The prescaler value is set so that the frequency is divided by 4 i.e., 20/(4x4) = 1.25. 3. Now the PORTA 2 is configured as i/p port and is continuously monitored and the timer is started at the starting of the first pulse and stopped at the ending of the third pulse. 4. Now the value from the TMRIH and TMRIL are brought to two registers NUMH NUML, i.e the value of the count present in hex format. Then it is converted into the ASCII format. 5. PORTD and PORTC are configured as o/p ports and PORTD for LCD data (i.e they are connected to db0 to db7) and PORTC(4,5,6) is for the LCD control. Then the count value is sent to the LCD (detailed program is appended in appendix A) 8
  • 9. CHAPTER 4 RESULTS AND DISCUSSION 4.1 RESULT 1. Near-Zero detector was set up and soldered on PCB and it was tested for the required output. 2. The Program written for this project was simulated for results (on PROTEUS V7.2) and then is flashed on the PIC microcontroller. 3. LCD is interfaced with the microcontroller and the timer 1 count is displayed on the LCD Screen. 9
  • 10. CHAPTER 5 CONCLUSION 5.1 CONCLUSION An inexpensive frequency measuring device using PIC18f4520 was developed and constructed on a PCB and tested for results. 5.2 FUTURE SCOPE OF THE PROJECT: If can be looked into, the project can be extended to data logging i.e., the readings acquired in these measurements will be logged into a computer by the following procedure: 1. After the measurement the output of the PIC microcontroller will be given to a MAX 232 IC Module which converts the PIC TTL to RS232 protocol. The RS- 232 serial communication protocol is a standard protocol used in asynchronous serial communication. It is the primary protocol used over modem lines. It is the protocol used by the MICRO STAMP11 when it communicates with a host PC. 2. Through this serial communication protocol the measurement data is logged into the computer and this data can be used for various purposes like plotting graphs of frequency versus time. Similarly measuring various power system parameters like voltage, current and power factor at the same time i.e., developing a multi-purpose Meter and logger, 10
  • 11. employing a microcontroller or microprocessor modules like RASPBERRY PI, ARDUINO etc. References PIC 18f4520 Datasheet: ww1.microchip.com/downloads/en/devicedoc/39631e.pdf Rs232 standards: http://www.omega.com/techref/pdf/RS-232.pdf 11
  • 12. APPENDIX A i. CODE LIST P=PIC18F4520 #INCLUDE P18F4520.INC CONFIG OSC=HS, IESO=OFF CONFIG WDT=OFF CONFIG BORV=3, PWRT=ON, BOREN=ON _ui_TenK EQU 0x20 _ui_Thou EQU 0x21 _ui_Hund EQU 0x22 _ui_Tens EQU 0x23 _ui_Ones EQU 0x24 _ui_NumH EQU 0x25 _ui_NumL EQU 0x26 LCD_DATA EQU PORTD LCD_CTRL EQU PORTC RS EQU RC5 RW EQU RC6 EN EQU RC7 ORG 0H Z4 MOVLW 0X0F MOVWF ADCON1 12
  • 13. B7 MOVLW 0X20 MOVWF T1CON CLRF TRISD CLRF TRISC BSF TRISA,2 MOVLW 0H MOVWF TMR1H MOVWF TMR1L CALL LDELAY B1 BTFSS PORTA,2 BRA B1 B2 BTFSC PORTA,2 BRA B2 ; we left first pulse to make sure we dont start counting in the middle of the wave BSF T1CON,0 B3 BTFSS PORTA,2 BRA B3 B4 BTFSC PORTA,2 BRA B4 B5 BTFSS PORTA,2 BRA B5 B6 BTFSC PORTA,2 BRA B6 ;here we get time for three pulses BCF T1CON,0 MOVFF TMR1H,_ui_NumH ; we start converting 16bit hex value we got in above timer to ascii values to be displayed on lcd MOVFF TMR1L, _ui_NumL 13
  • 14. MOVLW 0x00 SWAPF _ui_NumH,w ANDLW 0x0F ADDLW 0xF0 MOVWF _ui_Thou ADDWF _ui_Thou,f ADDLW 0xE2 MOVWF _ui_Hund ADDLW 0x32 MOVWF _ui_Ones MOVF _ui_NumH,w ANDLW 0x0F ADDWF _ui_Hund,f ADDWF _ui_Hund,f ADDWF _ui_Ones,f ADDLW 0xE9 MOVWF _ui_Tens ADDWF _ui_Tens,f ADDWF _ui_Tens,f SWAPF _ui_NumL,w ANDLW 0x0F ADDWF _ui_Tens,f ADDWF _ui_Ones,f RLCF _ui_Tens,f RLCF _ui_Ones,f COMF _ui_Ones,f RLCF _ui_Ones,f 14
  • 15. MOVF _ui_NumL,w ANDLW 0x0F ADDWF _ui_Ones,f RLCF _ui_Thou,f MOVLW 0x07 MOVWF _ui_TenK MOVLW 0x0A Lb1: ;addwf _ui_Ones,f DECF _ui_Tens,f ADDWF _ui_Ones,f BTFSS STATUS,C ; GOTO Lb1 Lb2: ;addwf _ui_Tens,f DECF _ui_Hund,f ADDWF _ui_Tens,f BTFSS STATUS,C GOTO Lb2 Lb3: ;addwf _ui_Hund,f DECF _ui_Thou,f ADDWF _ui_Hund,f BTFSS STATUS,C GOTO Lb3 Lb4: ;addwf _ui_Thou,f 15
  • 16. DECF _ui_TenK,f ADDWF _ui_Thou,f BTFSS STATUS,C GOTO Lb4 ; Convert to ASCII MOVLW 0x30 ADDWF _ui_Ones,F ADDWF _ui_Tens,F ADDWF _ui_Hund,F ADDWF _ui_Thou,F ADDWF _ui_TenK,F CLRF TRISD ; at this point we start sending ascii values to lcd CLRF TRISC BCF LCD_CTRL,EN CALL LDELAY CALL READY MOVLW 0X38 CALL COMMAND CALL LDELAY CALL READY MOVLW 0X0E CALL COMMAND CALL LDELAY CALL READY MOVLW 0X01 CALL COMMAND CALL LDELAY CALL READY MOVLW 0X06 16
  • 17. CALL COMMAND CALL LDELAY CALL READY MOVLW 0X86 CALL COMMAND CALL LDELAY CALL READY MOVF _ui_TenK,W CALL DATA_DISPLAY CALL LDELAY CALL READY MOVF _ui_Thou,W CALL DATA_DISPLAY CALL LDELAY CALL READY MOVF _ui_Hund,W CALL DATA_DISPLAY CALL LDELAY CALL READY MOVF _ui_Tens,W CALL DATA_DISPLAY CALL LDELAY CALL READY MOVF _ui_Ones,W CALL DATA_DISPLAY CALL LDELAY CALL READY HERE BRA HERE COMMAND MOVWF LCD_DATA ; syntax for commands to lcd BCF LCD_CTRL,RS 17
  • 18. BCF LCD_CTRL,RW BSF LCD_CTRL,EN CALL SDELAY BCF LCD_CTRL,EN RETURN DATA_DISPLAY MOVWF LCD_DATA ; syntax for data display BSF LCD_CTRL,RS BCF LCD_CTRL,RW BSF LCD_CTRL,EN CALL SDELAY BCF LCD_CTRL,EN RETURN READY SETF TRISD BCF LCD_CTRL,RS BSF LCD_CTRL,RW BACK BSF LCD_CTRL,EN CALL SDELAY BCF LCD_CTRL,EN BTFSC LCD_DATA,7 BRA BACK CLRF TRISD RETURN SDELAY MOVLW D'255' B10 DECF WREG BNZ B10 RETURN LDELAY MOVLW 0X08 ; code for causing delay of 13.5seconds MOVWF T0CON MOVLW 0XCF MOVWF TMR0H 18
  • 19. MOVLW 0X2C MOVWF TMR0L BSF T0CON,TMR0ON AGAIN BTFSS INTCON,TMR0IF BRA AGAIN BCF T0CON,TMR0ON BCF INTCON,TMR0IF RETURN MOVLW 0X0F MOVWF T0CON CLRF TMR0H CLRF TMR0L BSF T0CON,TMR0ON Z2 BTFSS BRA Z2 BCF INTCON,TMR0IF GOTO Z4 END 19
  • 20. 20
  • 22. APPENDIX B RS232 PROTOCOL Fig.4 The above figure shows the relationship between the various components in a serial ink. These components are the UART, the serial channel, and the interface logic. An interface chip known as the universal asynchronous receiver/transmitter or UART is used to implement serial data transmission. The UART sits between the host computer and the serial channel. The serial channel is the collection of wires over which the bits are transmitted. The output from the UART is a standard TTL/CMOS logic level of 0 or 5 volts. In order to improve bandwidth, remove noise, and increase range, this TTL logical level is converted to an RS- 232 logic level before being sent out on the serial channel. This conversion is done by the interface logic shown in the above figure. Usually in the systems the interface logic is implemented by the comm stamp. A frame is a complete and nondivisible packet of bits. A frame includes both information (e.g., data and characters) and overhead (e.g., start bit, error checking and stop bits). In asynchronous serial protocols such as RS-232, the frame consists of one start bit, seven or eight data bits, parity bits, and stop bits. A timing diagram for an RS-232 frame consisting of one start bit, 7 data bits, one parity bits and two stop bits. Note that the exact structure of the frame must be 22
  • 23. agreed upon by both transmitter and receiver before the comm-link must be opened. Most of the bits in a frame are self-explanatory. The start bit is used to signal the beginning of a frame and the stop bit is used to signal the end of a frame. The only bit that probably needs a bit of explanation is the parity bit. Parity is used to detect transmission errors. For even parity checking, the number of 1's in the data plus the parity bit must equal an even number. For odd parity, this sum must be an odd number. Parity bits are used to detect errors in transmitted data. Before sending out a frame, the transmitter sets the parity bit so that the frame has either even or odd parity. The receiver and transmitter have already agreed upon which type of parity check (even or odd) is being used. When the frame is received, then the receiver checks the parity of the received frame. If the parity is wrong, then the receiver knows an error occurred in transmission and the receiver can request that the transmitter re-send the frame. 23
  • 25. 25