Hi Darrel Taylor
You said the ccp should work from 500 - 10,000 rpm. Please kindly advice how to measure rpm 0-10,000 rpm by use ccp module on [email protected] you have source code please show me. Thank you.
Hi Darrel Taylor
You said the ccp should work from 500 - 10,000 rpm. Please kindly advice how to measure rpm 0-10,000 rpm by use ccp module on [email protected] you have source code please show me. Thank you.
You'll need to count the timer overflows and use them as the high word of the period after a capture.
Then change all the math, because the values will be larger than 16-bits.
Since you are using an 877A, you won't have the luxury of using LONG variables.
DT
Thank you for your advice but i still not clear please kindly show example about your advice above. For my program show as below
PIC16F877A
DEFINE OSC 4
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 2
Define LCD_EREG PORTD
Define LCD_EBIT 1
Low PORTE.2
PIE1.2=1
Symbol Capture = PIR1.2 ' CCP1 capture flag
T1 VAR WORD ' 1st capture value
PW VAR WORD ' 2nd capture value & ultimately final pulse width
intermediate VAR WORD
Dummyvar VAR WORD
rpm VAR WORD
TRISC.2 = 1 ' CCP1 input pin (Capture input)
INTCON = 0 ' Interrupts off
ReLoad:
CCP1CON = %00000101 ' Capture mode, 4capture on rising edge
T1CON = 0 ' TMR1 prescale=1, clock=Fosc/4, TMR1=off (200nS per count @20MHz)
TMR1H = 0 ' Clear high byte of TMR1 counter
TMR1L = 0 ' Clear low byte
T1CON.0 = 1 ' Turn TMR1 on here
Capture = 0 ' Clear capture int flag bit
While (!Capture) ' Wait here until capture on rising edge
Wend
' Rising edge detected / stuff Timer1 value in T1
T1.HighByte = CCPR1H
T1.LowByte = CCPR1L
CCP1CON = %00000100 ' Configure capture for falling edge now
Capture = 0 ' Clear capture interrupt flag bit
While !Capture ' While here until capture on falling edge
Wend
' Falling edge detected / stuff Timer1 value in PW
PW.HighByte = CCPR1H
PW.LowByte = CCPR1L
PW = PW-T1 ' High pulse width = PW-T1
intermediate = 60 * 1000 / 4 ' Compulsory !!!
' ( no "intermediate CON xxx" allowed )
' Disable interrupts ... if some used !!!
Dummyvar = 1000 * intermediate
rpm = DIV32 PW
' re-enable interrupts allowed
lcdout $fe,1,"TCH",$fe,$84,DEC RPM
GOTO ReLoad
END
Bookmarks