Shop OBEX P1 Docs P2 Docs Learn Events
Rev counter issue? — Parallax Forums

Rev counter issue?

msiriwardenamsiriwardena Posts: 301
edited 2014-06-20 09:23 in Propeller 1
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

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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-06-20 09:05
    If the input pin is floating without anything attached, it could be picking up noise. Use a pull-up or pull-down resistor (~10K is okay) to prevent this from happening.

    -Phil
  • msiriwardenamsiriwardena Posts: 301
    edited 2014-06-20 09:23
    @Phil,

    I will try that as soon as I can get some time.

    Thanks again

    Siri
Sign In or Register to comment.