Reading level #R inputs

MEDState Notation Repository Forums Coding Help Archive Reading level #R inputs

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #13129
    Med_Support
    Moderator
    tip184

    I want to use infrared phototransistors to detect rotations of a running wheel. Holes in wheel will allow IR “light” to hit photocell, which reports a level input on #R1. When hole is not over photocell, #R1 will not show an input.

    With two photocells offset relative to each other (and the holes) I can create a “rotary encoder with quadrature output” and detect precisely very small movements of the wheel. Coding would be much simplified if I could read the state of #R1 directly, e.g.,

    if #R1 = ON, then …, else … (Pseudocode – I know this is not MedState correct)

    Is this possible? If not, is it possible to have #R1 set a variable to 1 when it is on and 0 when it is off:

    #R1: set X = 1 ---> Sx
    ???" set X = 0 ---> Sx
    

    — what should ??? be? if I use a time (e.g., .01″: set X = 0 —> Sx) I wait .01″ to determine that there is no #R1. Is there a “dummy” input (or whatever one calls the statement that precedes the “:”) that takes no time?

    Thanks!

    -tip184

    #13130
    Med_Support
    Moderator
    Gary Bamberger

    I think this code sample will accomplish what you want

    \***************************************************
    \ BEAM BREAK DEFINED - 20ms BREAK, 20ms RELEASE
    \***************************************************
    S.S.2, \ Beam Break Defined - 20ms Break, 20ms Release.
    S1, \ Inputs in Level Mode generate an input "count" on each
    \ interrupt. With a 10 ms system resolution 2 counts
    \ will be reached in 20 ms. The Z3 pulse is used to
    \ signal a completed Beam Break. The second statement resets
    \ the counter every 20 ms so that a partial Beam Break of
    \ less than 20 ms will not constitute a Response.
    #R1: ADD Y; IF Y >= 2 [@BeamBreak, @NoBeamBreak]
    @Break: Z3; SET Y = 0 ---> S2
    @NoBreak: ---> SX
    0.02": SET Y = 0 ---> S1
    
    S2, \ As long as the Beam is broken the second statement
    \ causes a re-entry to this State. This resets the
    \ the internal 20 ms timer so it never times out. When
    \ the Beam is released for 20 ms the timer times out
    \ and a Z4 pulse signals the release.
    0.02": Z4 ---> S1
    #R1: ---> S2
    

    It will send a Z-pulse with the IR Beam is broken and another when it is released.

    Gary

    #13133
    Med_Support
    Moderator
    tip184

    Thanks Gary. I have used this code before to monitor duration of nose pokes, and I think that you are right – it will work. However, it simply defers the collection of the info that I need to the next step (i.e., the reading and comparing of the z codes). I was hoping that there was a more direct solution.

    With this code I next need a S.S. that monitors the Zs. If Z1 means R1 on and Z2 means R1 off (and similarly Z3 and Z4 for R2) then the routine will look something like this:

    S.S.
    \Hole = state of illumination of one or both phototransistors
    
    #Z1: Set Hole = Hole + 1 ---> Sx; \ but will processing proceed if #Z1 is detected?
    #Z2: Set Hole = Hole - 1 ---> Sx;
    #Z3: Set Hole = Hole + 10 ---> Sx;
    #Z4: Set Hole = Hole - 10 ---> Sx;
    

    Because the two sensors are out of phase with each other, this will produce a cycling output of 00, 01, 11, 10, 00… for rotation in one direction, and 00, 10, 11, 01, 00… for rotation in the opposite direction (if my phototransistors are aligned properly).

    What I had hoped to do was to avoid the Z pulses. Would something like this work:

    S.S.2
    
    S1,
    .02": set Hole1 = 0 ---> Sx; \ resets Hole1 if NOT #R1
    #R1: set Hole1 = 1 ---> Sx; \ Hole1 is set to 1 as long as #R1 beam is broken
    
     
    
    S.S.3
    
    S1,
    .02": set Hole2 = 0 ---> Sx;
    #R2: set Hole2 = 10 ---> Sx;
    
    S.S.4
    
    S1,
    .01": Set Hole = Hole1 + Hole2; if (CODE to compare current Hole with last Hole to see if wheel has moved) [@moved,@notmoved]
    @moved: set move = move + 1 ---> Sx;
    @notmoved : ---> Sx;
    

     

    The easiest solution would be a single Boolean statement:

    Set Hole = (10 * #R2) + #R1

    if #R equated to 1 (or TRUE) when on and 0 (or FALSE) when off.

    Am I making it harder than it needs to be?

    Jeff

    #13135
    Med_Support
    Moderator
    Gary Bamberger

    Hi Jeff,

    If you want to remove the Z-pulses, then this would most likely work:

    \*****************************************************************
    \ BEAM 1 BREAK DEFINED - 20ms BREAK, 20ms RELEASE
    \*****************************************************************
    S.S.2, \ Beam Break Defined - 20ms Break, 20ms Release.
    S1, \ Inputs in Level Mode generate an input "count" on each
    \ interrupt. With a 10 ms system resolution 2 counts
    \ will be reached in 20 ms. The second statement resets
    \ the counter every 20 ms so that a partial Beam Break of
    \ less than 20 ms will not constitute a Response.
    #R1: ADD Y; IF Y >= 2 [@BeamBreak, @NoBeamBreak]
    @Break: SET Y = 0, X = X + 1 ---> S2
    @NoBreak: ---> SX
    0.02": SET Y = 0 ---> S1
    
    S2, \ As long as the Beam is broken the second statement
    \ causes a re-entry to this State. This resets the
    \ the internal 20 ms timer so it never times out. When
    \ the Beam is released for 20 ms the timer times out.
    0.02": SET X = X - 1 ---> S1
    #R1: ---> S2
    
     
    
    \*****************************************************************
    \ BEAM 2 BREAK DEFINED - 20ms BREAK, 20ms RELEASE
    \*****************************************************************
    S.S.3,
    S1,
    #R2: ADD Z; IF Z >= 2 [@BeamBreak, @NoBeamBreak]
    @Break: SET Z = 0, X = X + 10 ---> S2
    @NoBreak: ---> SX
    0.02": SET Z = 0 ---> S1
    
    S2,
    0.02": SET X = X - 10 ---> S1
    #R2: ---> S2
    

    You can then use your boolean statement to check the status of X.

    Gary

    #13137
    Med_Support
    Moderator
    tip184

    Thanks Gary,

    I think your code will work. If I read it correctly, x will provide all of the info that I need – 11 when both are broken, 10 when Beam2 is broken, 1 when Beam1 is broken, and 0 when neither is broken. Not really any Boolean math involved in this approach. It might be that I need to use x for Beam 1 and w for Beam 2, then compute x+w as the state of the two beams.
    As always, I appreciate your help!

    Jeff

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.