May 18, 2024, 01:05:25 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Advanced Timing Stuff

Started by JonnyMac, August 27, 2008, 02:58:01 PM

Previous topic - Next topic

JonnyMac

I received a request to write a program that "thrashes" a couple valves while an audio segment in the AP-8 is playing.  Here's how I solved it and I've pulled it out here so that you may glean something from it.

Since the valves are going to be thrashing a body I want a minimum on- or off-time of 150 milliseconds.  We might simply drop a PAUSE 150 statement into the code but we have to check on the AP-8 and that takes time that needs to be accounted for.

Here's a fragment from the program:

  SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)

Thrash_Baby:
  RANDOM lottery
  Valve1 = lottery                              ' get bit from lottery
  Valve2 = Valve1                               ' both valves the same
  PAUSE 106                                     ' for ~150 ms loop

Check_Audio:
  SEROUT Sio, Baud, ("!AP8", %00, "G")          ' request status (25 ms)
  SERIN  Sio, Baud, status                      ' (19 ms)
  IF playing = Yes THEN Thrash_Baby


So you're looking through the code and wondering why, if I want 150 milliseconds, I used a PAUSE value of 106.  Remember that it takes time to talk to the AP-8; 4.2 milliseconds per character and by sending the "G" (get status) request we consume about 25 milliseocnds.  And here's a bit of previously unrevealed knowledge: the AP-8 (and other EFX-TEK devices) will hold off sending their response for 15 milliseconds -- this gives the host plenty of time to get ready (the Parallax Javelin processor is particularly slow when reconfiguring its Sio pin).  Sending the status by back takes another 4.2 milliseconds so we can consider the SERIN line from the AP-8 to consume 19 milliseconds.

Hopefully the 106 now makes sense (106 + 25 + 19 = 150) and you'll consider these details as you develop your own programs.

Jon McPhalen
EFX-TEK Hollywood Office