Announcement

Collapse
No announcement yet.

Math Question re: TIMER and hz

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Math Question re: TIMER and hz

    My math is fuzzy beyond VERY basic Calculus and I've never been an electrician. Can anybody tell me how to convert intervals retrieved from the TIMER function (startTime@, elapsedTime@) and executed lines per second into a hz rate through a parallel port?

    I'm using PBCC 4.04 trying to benchmark the WinIo driver. The program generates this output (extraneous digits removed):

    InstallWinIoDriver() = 1
    InitializeWinIo() = 1
    ShutdownWinIo() = 1
    RemoveWinIoDriver = 1
    Elapsed time = 1.08 for 2400 iterations.
    Lines per second = 11131.7

    How does that translate into hz?


    Code:
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "f:\PBWin80\WinIO\WinIO.bas"
    
    FUNCTION PBMAIN () AS LONG
       LOCAL lResult AS LONG
       LOCAL startTime AS DOUBLE
       LOCAL elapsedTime AS DOUBLE
       LOCAL tempStr AS STRING
       LOCAL iteration AS LONG
       LOCAL PortAddr%
       LOCAL PortVal&
       LOCAL bSize?
       LOCAL PhysAddr&
       LOCAL PhysSize&
       LOCAL PhysMemHandle&
       LOCAL PhysVal&
       LOCAL LinAddr&
    
    
       lResult = InstallWinIoDriver("f:\PBCC40\My Source Code\", 0)
       PRINT "InstallWinIoDriver() = " lResult
       lResult = InitializeWinIo()
       PRINT "InitializeWinIo() = " lResult
       tempStr = WAITKEY$
    
       startTime = TIMER
       FOR iteration = 1 TO 2400
          lResult = GetPortVal(PortAddr%, PortVal&, bSize?)
          lResult = MapPhysToLin(PhysAddr&, PhysSize&, PhysMemHandle&)
          lResult = GetPortVal(PortAddr%, PortVal&, bSize?)
          lResult = GetPhysLong(PhysAddr&, PhysVal&)
          lResult = UnmapPhysicalMemory(PhysMemHandle&, LinAddr&)
       NEXT interation
       elapsedTime = TIMER - startTime
       linesPerSecond = 2400 * 5 / elapsedTime
    
       lResult = ShutdownWinIo()
       PRINT "ShutdownWinIo() = " lResult
       RemoveWinIoDriver()
       PRINT "RemoveWinIoDriver = " lResult
    
       PRINT "Elapsed time = " elapsedTime " for 2400 iterations."
       PRINT "Lines per second = " linesPerSecond
       tempStr = WAITKEY$
    
    END FUNCTION
    Thanks,
    Stan
    Do not go quiet into that good night,
    ... Rage, rage against the dark.

  • #2
    A "hertz" is an inverse second.

    So your "hertz" is simply (number of whatevers)/ (time in seconds).
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Originally posted by Michael Mattias View Post
      A "hertz" is an inverse second.

      So your "hertz" is simply (number of whatevers)/ (time in seconds).


      Thanks Michael. I thought I was on the right track.
      Do not go quiet into that good night,
      ... Rage, rage against the dark.

      Comment


      • #4
        Stan,
        what are you trying to do? That code makes no sense. You don't need to be mapping memory in order to read an I/O port.
        For speed, use direct port access, not the GetPortVal call.

        If you're trying to find out how fast you can read an I/O port it'll probably turn out to be around 1 to 4MHz, depending on your hardware.

        More generally, to get hertz it's just:
        (number Of Times Thing Is Done)/(Time in seconds) = frequency in Hz

        So if you do 2400 things in 1.08 seconds then you do those things at a frequency of 2,400/1.08=2,222Hz.

        Paul.

        Comment


        • #5
          Hi Stan,
          You might need to put a Sleep 0 in your loop somewhere to let windows do other stuff.
          Strictly speaking, you are after samples per seconds, but none the less you divide the number of iterations by the time.
          Either 2400/1.08 or 5*2400/1.08 will get you there.

          Oops - I just noticed that MCM beat me to it.

          Anyway, If you want some precision in your timing, look at David Roberts code in the "Source" forum.
          Why settle for milliseconds when you can have micro second resolution?

          Cheers
          Gary Barnes
          The Control Key

          If you are not part of the solution
          then you are either a gas, solid, plasma or some other form of matter.

          Comment


          • #6
            >but none the less you divide the number of iterations...

            ...or number of bytes, or the number of reads, or number of lollipops... "hertz" by itself is only a denominator: a numerator is required.

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Thanks Paul. I didn't realize I wasn't actually doing anything here. Hmmmm.
              :kick:


              Originally posted by Paul Dixon View Post
              Stan,
              what are you trying to do? That code makes no sense. You don't need to be mapping memory in order to read an I/O port.
              For speed, use direct port access, not the GetPortVal call.

              If you're trying to find out how fast you can read an I/O port it'll probably turn out to be around 1 to 4MHz, depending on your hardware.

              More generally, to get hertz it's just:
              (number Of Times Thing Is Done)/(Time in seconds) = frequency in Hz

              So if you do 2400 things in 1.08 seconds then you do those things at a frequency of 2,400/1.08=2,222Hz.

              Paul.
              Do not go quiet into that good night,
              ... Rage, rage against the dark.

              Comment

              Working...
              X
              😀
              🥰
              🤢
              😎
              😡
              👍
              👎