Shop OBEX P1 Docs P2 Docs Learn Events
Input from a reed switch? — Parallax Forums

Input from a reed switch?

rapscaLLionrapscaLLion Posts: 75
edited 2007-04-20 16:54 in Propeller 1
Hi,

I need to collect input from a rotating source which has a reed switch built into it. The reed switch switches on/off twice per revolution.
I have connected the reed switch to the 3v source on one end and input 2 on the other end. I have been using the "count" function from
the BS2 library, but I'm not entirely sure the results are accurate and also not entirely sure that this is the best way to do it. Theoretically
the fastest the rotation could be is about 30 rotations per second, or 1800 rpm. The slowest is 0. I imagine the average will be about 300-600.

Any ideas? I need to sample this twice per second.

Comments

  • bambinobambino Posts: 789
    edited 2007-04-19 16:19
    For 5 to 10 revolutions per second I would think the BS2 funtions in spin where adaquate, though I have not used them!

    You could poll for the input in Spin or assembly but the easiest way would be to use the cog counters and just read their current value whenever needed.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-04-19 16:31
    I've been using the counters to count pulses of light on a photodiode from a laser pointer, I'm pulsing the laser so that it appears less bright, I just wanted to check that it was working so I sent it 10 pulses and looked at the results.

    
    PHSA :=0
    FRQA := 1                                     ' added to PHSA on every pos edge
    CTRA := %01010 << 23 + 8           ' sets it in positive edge trigger and input pin 8
    
    ' Wait here for a specific time etc 
    
    CTRA := 0                                     ' Stops counter
    count := PHSA                               ' Phsa contains number of positive edges.
    
    
    



    I'm writing this from memory please consult description of CTRA in manual and also the counter app note if it doesn't work.

    One problem may be bounce, the counter will detect any positive edge whats so ever at a very high clock rate.

    Graham
  • inserviinservi Posts: 113
    edited 2007-04-20 16:54
    Hello,

    Take care about the rebound, or bounce. you have to debounce the mechanical contact. You need to do that with a small delay after each state changing.

    dro

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    in medio virtus
Sign In or Register to comment.