Opto interrupter ;>


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    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.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Even more information would help. What type of motors, how are you driving them, what are the minimum & maximum motor speeds, what else does your firmware need to manage besides driving 3 motors, and counting pulses, etc.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    May 2010
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Even more information would help. What type of motors, how are you driving them, what are the minimum & maximum motor speeds, what else does your firmware need to manage besides driving 3 motors, and counting pulses, etc.
    i am driving 3x 2.4 1A motors (from electrical screwdriver) via relays (here is circuit: just i am using much more lower resistors 470Ohms.), what speed i don't know, searched for documentation but couldn't find. i will build 3 buttons to calibration mode, at start robot will go from any position to starting position. i think that's all.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Without some form of speed control you're going to need to know what the maximum RPMs are for these motors. Without knowing that you have no idea how much time you will have to count pulses.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    May 2010
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Without some form of speed control you're going to need to know what the maximum RPMs are for these motors. Without knowing that you have no idea how much time you will have to count pulses.
    hmm i don't have any idea how to measure it, i can only visually show how it's working but i don't think it will be helpful.

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