Hi guys.. appreciate some help please with a 12f675 project. A rotating wheel produces 8 pulses per revolution. For each second second a minimum of 8 pulses or more must occur. Should the wheel stop or slow down an output signal must signal an event by setting a port output low. I only use PIC assembly programming and MPLAB IDE templates etc. I've included my code which gives an ouput on GPIO,1 for every 8 inputs switched at GPIO,0 ( I use a pic simulator to check my programs)
I'm not sure how to combine my code into a 1 sec time frame, so as long as 8 pulses or more occur every second then OK less than 8 is bad. I thought along the lines of maybe a 1 sec period is reset on every 8 pulses but whenever the number of pulses fall short of 1 sec an output signal is flagged up. Any help with an example code would be appreciated.
;******************************************************************************
; *
LIST P=12F675 ; list directive to define processor
#INCLUDE <P12F675.INC> ; processor specific variable definitions
;------------------------------------------------------------------------------
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
;***** VARIABLE DEFINITIONS (examples)
;example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR 0x20
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
RESET_VECTOR CODE 0x000 ; processor reset vector
goto main ; go to beginning of program
;call 0x3FF
; movlw 60h ; retrieve factory calibration value
; bsf STATUS,RP0 ; set file register bank to 1
;movwf OSCCAL ; update register with factory cal value
; 3460 @ 3F8
TIME EQU 42H
COUNT EQU 31H
COUNTA EQU 30H
COUNTB EQU 34H
; ======================== .25sec delay ===================================
DELAY1
MOVLW .25
MOVWF COUNT ; THIS SECTION PROVIDES A .25 SEC TIMMING PERIOD
TIMEA CLRF TMR0
LOOPC MOVF TMR0,W
SUBWF TIME,W
BTFSS STATUS,Z
GOTO LOOPC
DECFSZ COUNT
GOTO TIMEA
RETLW 0
; ======================= 1 SECOND DELAY =================================
DELAY
MOVLW .100
MOVWF COUNT ; THIS SECTION PROVIDES A 1 SEC TIMMING PERIOD
TIMEC CLRF TMR0
LOOPA MOVF TMR0,W
SUBWF TIME,W
BTFSS STATUS,Z
GOTO LOOPA
DECFSZ COUNT
GOTO TIMEC
RETLW 0
;===========================================================
main
bsf STATUS,RP0 ; select bank 1
vrcon=0
movlw 60h ; retrieved factory calibration value
movwf OSCCAL ; put value into mem loc file reg address 90
CLRF ANSEL
movlw B'00000001' ; SET BIT 0 INPUTS GPIO 1>7 AS OUPUTS
movwf TRISIO ; SET BITS 2,3 AS INPUTS
movlw B'00000111'
movwf OPTION_REG
MOVLW .39
MOVWF TIME
bcf STATUS,RP0 ; select bank 0
CLRF GPIO
MOVLW 07H
MOVWF CMCON ;cmcon=7 ;turn off comparitor
CLRF ADCON0
clrwdt
clrf TMR0
;======================== BEGINING OF PROGRAM ============================
BEGIN
MOVLW .8
MOVWF COUNT
CHK BTFSC GPIO,0
GOTO CHK
;CALL DELAY1
BCF GPIO,1
CHK2 BTFSS GPIO,0
GOTO CHK2
;CALL DELAY1
DECFSZ COUNT
GOTO CHK
BSF GPIO,1
CALL DELAY1
BCF GPIO,1
GOTO BEGIN
END
I'm not sure how to combine my code into a 1 sec time frame, so as long as 8 pulses or more occur every second then OK less than 8 is bad. I thought along the lines of maybe a 1 sec period is reset on every 8 pulses but whenever the number of pulses fall short of 1 sec an output signal is flagged up. Any help with an example code would be appreciated.
;******************************************************************************
; *
LIST P=12F675 ; list directive to define processor
#INCLUDE <P12F675.INC> ; processor specific variable definitions
;------------------------------------------------------------------------------
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
;***** VARIABLE DEFINITIONS (examples)
;example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR 0x20
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
RESET_VECTOR CODE 0x000 ; processor reset vector
goto main ; go to beginning of program
;call 0x3FF
; movlw 60h ; retrieve factory calibration value
; bsf STATUS,RP0 ; set file register bank to 1
;movwf OSCCAL ; update register with factory cal value
; 3460 @ 3F8
TIME EQU 42H
COUNT EQU 31H
COUNTA EQU 30H
COUNTB EQU 34H
; ======================== .25sec delay ===================================
DELAY1
MOVLW .25
MOVWF COUNT ; THIS SECTION PROVIDES A .25 SEC TIMMING PERIOD
TIMEA CLRF TMR0
LOOPC MOVF TMR0,W
SUBWF TIME,W
BTFSS STATUS,Z
GOTO LOOPC
DECFSZ COUNT
GOTO TIMEA
RETLW 0
; ======================= 1 SECOND DELAY =================================
DELAY
MOVLW .100
MOVWF COUNT ; THIS SECTION PROVIDES A 1 SEC TIMMING PERIOD
TIMEC CLRF TMR0
LOOPA MOVF TMR0,W
SUBWF TIME,W
BTFSS STATUS,Z
GOTO LOOPA
DECFSZ COUNT
GOTO TIMEC
RETLW 0
;===========================================================
main
bsf STATUS,RP0 ; select bank 1
vrcon=0
movlw 60h ; retrieved factory calibration value
movwf OSCCAL ; put value into mem loc file reg address 90
CLRF ANSEL
movlw B'00000001' ; SET BIT 0 INPUTS GPIO 1>7 AS OUPUTS
movwf TRISIO ; SET BITS 2,3 AS INPUTS
movlw B'00000111'
movwf OPTION_REG
MOVLW .39
MOVWF TIME
bcf STATUS,RP0 ; select bank 0
CLRF GPIO
MOVLW 07H
MOVWF CMCON ;cmcon=7 ;turn off comparitor
CLRF ADCON0
clrwdt
clrf TMR0
;======================== BEGINING OF PROGRAM ============================
BEGIN
MOVLW .8
MOVWF COUNT
CHK BTFSC GPIO,0
GOTO CHK
;CALL DELAY1
BCF GPIO,1
CHK2 BTFSS GPIO,0
GOTO CHK2
;CALL DELAY1
DECFSZ COUNT
GOTO CHK
BSF GPIO,1
CALL DELAY1
BCF GPIO,1
GOTO BEGIN
END