Opto interrupter ;>


Results 1 to 10 of 10

Threaded View

  1. #6
    Join Date
    May 2010
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    I think Henriks' idea of using a timer/counter is the way to go. This leaves you tons of time to handle other things while the counter works for you in the background.

    There is no need to wait with any WHILE/WEND, PAUSE, etc.

    Code:
    CMCON = 0        ' Disable comparators
    TRISA.4 = 1      ' RA4/T0CKI = input to TMR0 counter
    PORTB = 0        ' clear all outputs on PORTB
    TRISB = 0        ' PORTB outputs
    ANSEL = 0        ' All digital 
     
    ' OPTION_REG setup for Timer0
    ' Prescaler to WDT with 1:1 prescaler for TMR0
    ' TMR0 clock is external input on RA4/T0CKI
    ' Increment on low-to-high transitions on RA4/T0CKI
    ' Internal pull-ups disabled
     
       OPTION_REG = %10101000 
       TMR0 = 0     ' Clear TMR0 count
     
    Begin:
        IF TMR0 >= 20 THEN Ledas
     
        ' you have time to do lots of other thing here
        ' while Timr0 counts pulses in the background
     
        GOTO Begin
     
    Ledas:
       TMR0 = 0    ' clear Timer0 count here
       HIGH Led
       GOTO begin
    And if you prefer Timer0 to increment on high-to-low transitions on RA4, just change OPTION_REG = %10101000 to OPTION_REG = %10111000.
    This is nice feature in pic, but if i need to count 3 different optocouplers ? as i see in data sheet there are several pins which can do it. y ? BTW Thank You for Your response. I think i need to explain my project, it would be easier to get me on the path. My project is robot arm with 3 motors and 3 optical interrupters. i'm using opto interrupters to track my motors positions. and i am thinking alot about ti but cant find way to do it. at start i thinked about counting all free sensors in the same time but its quite hard to program for a newbie and if i think it will loose some pulses from other sensors because uC will do another processes in that time. also its quite hard to drive motors and count pulses at the same time is there any possibility to do it without interrupts or still its impossible ?
    Last edited by deimantas; - 4th June 2010 at 16:36.

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