Timing between events

Discussion in 'Questions (Windows Mobile)' started by Zenerdiode, Aug 26, 2008.

  1. Zenerdiode

    Zenerdiode Active Member Licensed User

    I'm using the Com port as a crude digital input device. I want to time between raising DSR and raising CTS; to an accuracy of 10ms. The time interval may be anything between one and 500 seconds. I'm trying to use the code below with timers to avoid burning CPU cycles but I'm losing track of what I'm doing(!)

    Timer 2 and Timer 3 are set to 1ms.
    Code:
    #Region Timer
    Sub TimeEvent
       Port.DTREnable=
    True
       WatchDog=HW.GetTickCount
       Timer2.Enabled=
    True
       Timer3.Enabled=
    True
    End Sub

    Sub Timer2_Tick
       
    If Port.DSR=True Then
          DSRtime=HW.GetTickCount
          Timer2.Enabled=
    False
          
    Return
       
    End If
       
    If (HW.GetTickCount-WatchDog)>500 Then
          Timer2.Enabled=
    False
          Timer3.Enabled=
    False
          Port.DTREnable=
    False
          
    Msgbox("DSR has not responded; check cable and connections.","Error",cMsgBoxOK,cMsgBoxHand)
       
    End If
    End Sub

    Sub Timer3_Tick
       
    If Port.CTS=True Then
          CTStime=HW.GetTickCount
          Timer3.Enabled=
    False
          Port.DTREnable=
    False
          
    Return
       
    End If
       
    If (HW.GetTickCount-WatchDog)>500000 Then
          Timer2.Enabled=
    False
          Timer3.Enabled=
    False
          Port.DTREnable=
    False
          
    Msgbox("CTS has not responded; Check cable and connections.","Error",cMsgBoxOK,cMsgBoxHand)
       
    End If
    End Sub
    #End Region
    The time interval is then CTStime-DSRtime, but I don't know where to put it. Ideally, I would also like to be able to call the routine five times with a two second interval between, but because each sequence may be upto 500 seconds long, the CPU has to be free.

    Am I missing the point here and be better using:
    Code:
    Do Until Port.DSR=True
       Sleep(
    1)
    Loop
    But that will lock into that loop for the duration; and I will not be able to update the elapsed time on screen (thats what I'm doing with Timer1)

    I hope this makes sense as I'm tying myself in knots as I'm trying to get my problem across.
    :sign0148:
     
    Last edited: Aug 26, 2008
  2. Erel

    Erel Administrator Staff Member Licensed User

    I'm not sure that I understood your program.
    However 1ms interval is too short. The tick event is only fired when the cpu is free.
    The events will be accumulated and not timed properly.

    Can't you update the screen inside the 'Do until' loop?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice