HeiFelix
Member level 1
Pulse Counter
I am useing PIC16F87A to detect the frequncy change on RA4 by counting the input pulse of TMR0. The frequency is around 80KHz depending on the sensor and the OSC is 8MHz. In every 160ms, the number of pulses is 0x36B5 or 0x36B6 which means the frequency is stable.
I want to detect one or two more pulses in this period as quick as possible. So, I set FIFO to record the number of the pulse in 16(X10ms) consectutive periods. In the end of each period, I get the sum of FIFO and compare it with the standard. I believe in this way I can detect the change in 10ms. But, I the sum of last 160ms is fluctuated from 0x36B3-0x36B6 which means that I can not get a standard to check. Some pulse should be lost when I record it. How can I get the expected sum as 0x35B5 or 0x35B6 in such 16X10ms period? The code is as following:
Thanks!
I am useing PIC16F87A to detect the frequncy change on RA4 by counting the input pulse of TMR0. The frequency is around 80KHz depending on the sensor and the OSC is 8MHz. In every 160ms, the number of pulses is 0x36B5 or 0x36B6 which means the frequency is stable.
I want to detect one or two more pulses in this period as quick as possible. So, I set FIFO to record the number of the pulse in 16(X10ms) consectutive periods. In the end of each period, I get the sum of FIFO and compare it with the standard. I believe in this way I can detect the change in 10ms. But, I the sum of last 160ms is fluctuated from 0x36B3-0x36B6 which means that I can not get a standard to check. Some pulse should be lost when I record it. How can I get the expected sum as 0x35B5 or 0x35B6 in such 16X10ms period? The code is as following:
Code:
..........
;;;;;;;;;;;;;;;;;; Interrupt Service ;;;;;;;;;;;;;;;;;;;;;
IntService
movwf W_Temp
swapf w,STATUS_Temp
movwf STATUS_Temp
bcf STATUS,RP0
btfsc INTCON,T0IF
call IntServiceTimer0
swapf STATUS_Temp,w
movwf STATUS
swapf W_Temp,f
swapf W_Temp,w
retfie
;;;;;;;;;;;;;;;;;; Interrupt Service for Timer0 ;;;;;;;;;;;;;;;;;;;;;
IntServiceTimer0
bcf INTCON,T0IF
incf TMR0_High,f
return
;;;;;;;;; Main Program;;;;;;;;
Mainline
call InitialPIC
call InitialDetector
movlw CounterLength
movwf CounterCounter
MainLoop
btfss PIR1,TMR2IF :10ms overfloe
goto MainLoop
bcf PIR1,TMR2IF
movf TMR0,w
clrf TMR0
movwf TMR0_TempL
movf TMR0_High,w
movwf TMR0_TempH
clrf TMR0_High
............ use TMR0_TempL and TMR0_TempH to get the sum in 16x10ms period .......
............. detect the change of frequncy and do certain operation .........
goto MainLoop