Pellet dispenser beam break latency

MEDState Notation Repository Forums Coding Help Archive Pellet dispenser beam break latency

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12835
    Med_Support
    Moderator
    blee13

    Hello,

    I am trying to write a program that reports the latency of beam breaks at a food dish. The program that I have essentially checks for a beam break every 0.01s and stamps into the dimension N every time the beam is broken. Because 0.01s is a really short time, the dimension N ends up becoming a pretty long array. And for my program, the total latency in dish ends up being computed as the length of the dimension of N in terms of 0.01s.

    This is the way my program does it right now:

    DIM N = 900000 \time at each head entry
    \ B = adds 1 every time head entry is registered every 0.01s
    
    S.S.1,
    S1,
    #START: ---> S2
    S2,
    #R^HeadEntry: ADD B; SET N(B) = U ---> S3
    S3,
    0.01": ---> S2
    
    S.S.29, \running time
    S1,
    #START: ---> S2
    
    S2,
    0.01": ADD S ---> SX
    
    S.S.30,
    S1,
    #START: ---> S2
    
    S2,
    0.01": SET U = S/100 ---> SX
    

     

    I was wondering if there is another way of coding latency? I would like it if you can do something like the following:
    S1,
    #R^HeadEntry: ADD A; stamp time of entry into W(A)—> S2
    S2,
    When R^HeadEntry is no longer detected: ADD E; stamp time of exit into C(E)—> S1

    then eventually you just subtract time of exit and entry ( C(E) – W(A) ) to get a latency period… which you can sum up in the end.
    The hard part is getting around S2. Is there a way of reporting an input when a certain input is OFF?

    Thanks!

    #12836
    Med_Support
    Moderator
    Jim Frei

    Hi Blee13,

    I’m a little confused on what you’re trying to calculate. You mention latency, but it sounds like you’re trying to time how long the animal is in the food dish because you say “subtract time of exit and entry ( C(E) – W(A) ) to get a latency period”. If you’re trying to time how long the beam is broken here is some sample code to help with that:

    \***************************************************
    \ RESPONSE DEFINED - 20ms BREAK, 20ms RELEASE
    \***************************************************
    S.S.2,
    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 Response. The second statement
    \ resets the counter every 20 ms so that a partial
    \ Response of less than 20 ms will not be counted.
    #R1: ADD Y; IF Y >= 2 [@Response, @NoResponse]
    @Response: SET Y = 0; Z3 ---> S2
    @NoResponse: ---> SX
    0.02": SET Y = 0 ---> S1
    S2, \ As long as the input is broken the second statement
    \ causes a re-entry to this State. This resets the
    \ internal 20 ms timer so it never times out. When the
    \ input is released for 20 ms the timer times out and a
    \ Z4 pulse signals the release.
    0.02": Z4 ---> S1
    #R1: ---> S2
    \***************************************************
    \ RESPONSE TIMER
    \***************************************************
    S.S.3,
    S1,
    #START: SET Z(I) = -987.987 ---> S2
    S2, \ Wait for a signal that the input has been broken.
    #Z3: SET T = 0 ---> S3
    S3, \ Wait for signal that the input has been released.
    \ Record the length of the Response.
    0.01": SET T = T + 0.01 ---> S3
    #Z4: SET Z(I) = T; ADD I; SET Z(I) = -987.987 ---> S2
    

    If that’s not what you’re trying to do please post back.

    Jim

    #12839
    Med_Support
    Moderator
    blee13

    This just might work for what I need! Thanks!

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