Rev counter issue?
msiriwardena
Posts: 301
Hi all,
I have the following code running in separate cog.When BLDC motor is attaced RPM is sown on a LGD correctly.Ithink so?
When is disconncted,the wires are NOT connecte to the Prop at all, But my Lcd show RPM= 1925 ?
Why is it? Is the code not correct.
Please help me to find out why?
Thank you,
Siri
con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq
MS_001 = CLK_FREQ / 1_000
REFRESH_RATE = 16_000_000 ' 80_000_000/5
RevPin = 6
Baud = 19200
Lines = 4
INPIN = 8 'RPM counter PIN from BLDC controller
MotorPin = 1 'Motor run/stop
I have the following code running in separate cog.When BLDC motor is attaced RPM is sown on a LGD correctly.Ithink so?
When is disconncted,the wires are NOT connecte to the Prop at all, But my Lcd show RPM= 1925 ?
Why is it? Is the code not correct.
Please help me to find out why?
Thank you,
Siri
con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq
MS_001 = CLK_FREQ / 1_000
REFRESH_RATE = 16_000_000 ' 80_000_000/5
RevPin = 6
Baud = 19200
Lines = 4
INPIN = 8 'RPM counter PIN from BLDC controller
MotorPin = 1 'Motor run/stop
Pub Revolution_Counter
ctra := %01010 << 26 + INPIN ' counter A in POSedge mode
frqa := 1 ' increment 1 per pulse waitcnt(clkfreq + cnt)
' measure the input duty cycle using counters.
waitUntil := cnt + REFRESH_RATE
repeat
phsa := 0 ' reset count registers
waitcnt(waitUntil+=REFRESH_RATE)
inFreq := phsa * (constant(80_000_000/REFRESH_RATE)) ' read the number of edges; convert to 1 second
RPM:=(15*inFreq)
Comments
-Phil
I will try that as soon as I can get some time.
Thanks again
Siri