Summary: The speed of the motor is measured in Rotations per Minutes,RPM.The RPM Meter is to read the running speed of Motor like DC MOTOR. Here the speed of the DC Motor is sensed with the help of a speed sensor and it is signal conditioned to have pulses which given as Timer1 clock input of PIC Microcontroller, configured to accept external clock input.The count value in Timer1 for one second represents speed in seconds which can be converted into RPM by multiplying the count by 60.The Display of the speed will be on Lyquid Crystal Display LCD .
AIM :
To develop a RPM meter using microcontroller & to display the speed on LCD Display PIC Microcontroller 16F877.
INTERFACING:
- Pulses from speed sensor connected to TMR1 clock input-RC2
- Run/Hold push button switch connected to –RC4
LCD Display –
- Data lines connected to Port C - RC0: RC7
- Control lines connected to Port D - RD0: RD2
- Timer0 used for generating time slice of 1/16 sec in interrupt driven mode
NOTE: DC motor, DC motor driver circuit, speed sensor, signal-condition circuit to be Provided.
schematic dgm
SCHEMATIC DIAGRAM:
Figure1: Schematic Block Diagram for RPM Meter
DESCRIPTION:
Pulses from the speed sensor, after signal conditioning, is connected to Timer 1 input.
RPM meter works in two modes viz RUN & HOLD. The mode toggles for every push of the mode selection push of the mode selection push button switch:
HOLD Mode: Previous value of the speed is displayed
RUN Mode: Speed is measured for every second
- By default meter will be in HOLD mode with display ‘00’.
- Mode of operation and the speed are displayed on LCD
FLOW CHART:
Flow Chart
Figure4: Functional Flow Chart for RPM Meter
LIST P=16F877
#INCLUDE"P16F877.INC"
CBLOCK 20H
HEX1
HEX2
DEC1
DEC2
DEC3
DEC4
DEC5
DD1
DD2
DV1
DV2
Q2
Q1
TEMP
DISNO
DLOC1
DLOC2
ENDC
ORG 00H
GOTO MAIN
MAIN CLRF CCP1CON ; CCP Module is off
CLRF TMR1H ; Clear Timer1 High byte
CLRF TMR1L ; Clear Timer1 Low byte
CLRF CCPR1L
CLRF CCPR1H
CLRF INTCON ; Disable interrupts and clear T0IF
BSF STATUS, RP0 ; Bank1
BSF TRISC, 2 ; Make CCP pin input
CLRF TRISD
CLRF TRISE
CLRF PIE1 ; Disable peripheral interrupts
BCF STATUS, RP0; Bank0
CLRF PIR1 ; Clear peripheral interrupts Flags
MOVLW 07 ; Capture mode, every 4th rising edge
MOVWF CCP1CON
BSF STATUS, RP0
BSF PIE1, CCP1IE
BCF STATUS, RP0
MOVLW 21H
MOVWF T1CON ; Timer1 starts to increment 1:8 PRESCALAR MODE
; The CCP1 interrupt is disabled,
; do polling on the CCP Interrupt flag bit
Capture_Event
BCF T1CON, TMR1ON; off the timer after capturing the 4th pulse
BANKSEL TRISA
CLRF TRISC
BANKSEL PORTA
BCF PIR1, CCP1IF ; This need to be done before next compare
MOVF CCPR1L, 0
MOVWF HEX1
MOVF CCPR1H, 0
MOVWF HEX2
BCF STATUS, C ; for performing right shift
RRF HEX2 ; dividing the period by 2 i,e right shift
RRF HEX1;
CALL DIVIDE ; converting the period into frequency i,e RPS=Fclk / (capture period)
CALL HEXDEC
BSF STATUS, RP0
CLRF TRISC ; configuring the PORTC as output in the LCD subroutine
BCF STATUS , RP0
CALL LCD ;display part
CALL DISP
GOTO MAIN
DIVIDE
NOP
MOVLW 0F4H ; loading the Fclk/2 value to the dividend, MSB IS DD1
MOVWF DD1
MOVLW 24H
MOVWF DD2 ; DD2 is the LSB
MOVF HEX1, 0 ; loading the capture period value to the divisor
MOVWF DV2
MOVF HEX2, 0
MOVWF DV1
CLRF Q1
CLRF Q2
BACK MOVF DV2, 0
SUBWF DD2, 1
BNC GETN
MOVF DD1, 0
BZ GETQT
MOVF DV1, 0
SUBWF DD1, 0
BNC GETQT
DECF DD1
GETN MOVF DV1, 0
SUBWF DD1, 1
BNC GETQT
INCF Q2
MOVF Q2, 1
BZ NQ
GOTO BACK
NQ INCF Q1
GOTO BACK
GETQT MOVF DD2, 0
ADDWF DV2, 0
MOVWF DD2
MOVF Q2, 0
MOVWF HEX1
MOVF Q1, 0
MOVWF HEX2
RETURN
DELAY CLRF DLOC2
MOVLW 03CH
MOVWF DLOC2
D1 MOVLW 0FFH
MOVWF DLOC1
DECFSZ DLOC1, 1
GOTO $-1
DECFSZ DLOC2, 1
GOTO D1
RETURN
HEXDEC CLRF DEC1
CLRF DEC2
CLRF DEC3
CLRF DEC4
CLRF DEC5
P100 MOVLW 64H ; START OF HEX-DEC CONVERTION
SUBWF HEX1, 0
BNC DIG2
B100
MOVWF HEX1
INCF DEC3, 1
MOVLW 0AH
SUBWF DEC3, 0
BZ CO3
GOTO P100
DIG2
MOVF HEX2, 1
BZ P10
DECF HEX2, 1
GOTO B100
P10
MOVLW 0AH
SUBWF HEX1, 0
BNC P1
MOVWF HEX1
INCF DEC2, 1
GOTO P10
P1
MOVF HEX1, 0
MOVWF DEC1
RETURN
CO3 CLRF DEC3
INCF DEC4, 1
MOVLW 0AH
SUBWF DEC4, 0
BNZ P100
CLRF DEC4
INCF DEC5, 1
GOTO P100
TABLE ADDWF PCL, 1
RETLW 'S'
RETLW 'P'
RETLW '='
CODE1 MOVWF TEMP
CALL BUSY
BCF PORTD, 1
BCF PORTD, 0 ; for WRITE OPERATION, R/W=0.
; To write the code, RS=0.
MOVF TEMP, 0
BSF PORTD, 2
MOVWF PORTC
BCF PORTD, 2
RETURN
BUSY BSF STATUS, RP0
MOVLW 0FFH
MOVWF TRISC
BCF STATUS, RP0
MOVLW 06H
MOVWF PORTD ; for READ OPRATION, R/W=1
; To read the busy flag,RS=0
MOVF PORTC, 0
BCF PORTD, 2
ANDLW 80H
BTFSS STATUS, Z
GOTO BUSY
BCF PORTD, 1
BSF STATUS, RP0
CLRF TRISC
BCF STATUS, RP0
RETURN
DATA1 MOVWF TEMP
CALL BUSY
BCF PORTD, 1
BSF PORTD, 0
MOVF TEMP, 0
BSF PORTD, 2 ; FOR WRITE OPN R/W=1
MOVWF PORTC ; RS=1;
BCF PORTD, 2
RETURN
; --------------------------------------------LCD-------------
LCD CALL DELAY
MOVLW 38H ; 8 BIT DATA LENGTH AND NUMBER OF DISPLAY .
CALL CODE1
MOVLW 0FH ; CLEAR DISPLAY
CALL CODE1
MOVLW 06H ; DISPLAY ON CURSOR ON.
CALL CODE1
MOVLW 01H
CALL CODE1
RETURN
DISP CLRF DISNO
BACK1 MOVF DISNO, 0
CALL TABLE
CALL DATA1
INCF DISNO, 1
BTFSS DISNO, 1
GOTO BACK1
BTFSS DISNO, 0
GOTO BACK1
MOVF DEC5, 0
ADDLW 30H
CALL DATA1
MOVF DEC4, 0
ADDLW 30H
CALL DATA1
MOVF DEC3, 0
ADDLW 30H
CALL DATA1
MOVF DEC2, 0
ADDLW 30H
CALL DATA1
MOVF DEC1, 0
ADDLW 30H
CALL DATA1
MOVLW 0C0H
CALL CODE1
MOVLW 'R'
CALL DATA1
MOVLW 'P'
CALL DATA1
MOVLW 'S'
CALL DATA1
RETURN
NOP
GOTO MAIN
END
References:
- Microchip Mid Range Manual on PIC Microcontroller
- PIC Microcontrollers by Peatman. Pearson Edn
0 comments:
Post a Comment