Opto interrupter ;>


Results 1 to 10 of 10

Threaded View

  1. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    The problem with your current aproach is that if the input stays high longer than it takes for the program to cycle it will keep on counting. Think of it, the input goes high, the variable is incremented and the program starts over, the input is still high, the variable get incremented and the program starts over and so on.

    We're talking micro seconds here so if one pulse from your opto-interupter is 2ms long you may count from 0-10 in one single pulse. You need to wait for the input to go high, increment your count variable then wait for the input to go low again before you allow another count. Something like:
    Code:
    loop:
      if opto = 1 then
        counts = counts+1
        if counts >=10 THEN 
          high led
        endif
        
    Code:
    While opto = 1      'Loop here until input goes low.
        Wend
       endif
    goto loop



    A better way though would be to use one of the PICs internal timers configured as a counter and simply let it count the pulses. Have a look at the TMR1 section of the datasheet.

    About your code then, you haven't DEFINEd the oscillator speed and there's a colon missing after the loop label...

    /Henrik.

    EDIT: OK, I give up....why the heck does the editor keeps inserting code tags on it's own in the middle of a section already surounded by code tags??
    Last edited by HenrikOlsson; - 4th June 2010 at 10:26. Reason: The bloody editor keeps inserting code tags on it's own - AAARGH.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts