Shop OBEX P1 Docs P2 Docs Learn Events
programming delays less than 1ms — Parallax Forums

programming delays less than 1ms

davejamesdavejames Posts: 4,047
edited 2008-06-01 02:16 in General Discussion
Hi All,

I have need to program a delay less than the 1ms of which the PAUSE statement offers.

My first thought was to set up a test case where an I/O pin would be driven high, issue a "PAUSE 0", drive the I/O pin low and observe the time between the rising and falling edges on a scope to get an idea of how long the PAUSE command takes to execute.· Placing this method inside a FOR/NEXT with a variable for the upper count would give a level of less-than-1ms, programmable delay.· Granted, it wouldn't be overly accurate, but I'm not looking for high accuracy.

Anyone else have a nifty way of dealing with·this?

Thanks,

DJ
·

Comments

  • LeonLeon Posts: 7,620
    edited 2008-05-29 16:19
    Hardware and programming language?

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-29 16:47
    If you have a spare I/O pin, you could use a dummy PULSOUT statement to provide a variable delay. Remember that around 1ms, the execution time of the statements themselves becomes significant and you have to account for that.
  • davejamesdavejames Posts: 4,047
    edited 2008-05-29 17:59
    Leon...ooops - yeah, should have mentioned that I'm using a BS2 using the standard BASIC/P 2.5·language.

    Mr. Green - thanks, I'll read up on PULSOUT.

    I'm attempting to program some LS573 data latches that have setup/hold/propagation times in the order of 50ns and I'd like to not be saddle with 1ms intervals of delay time.· Every little bit helps, you know?

    DJ
  • davejamesdavejames Posts: 4,047
    edited 2008-05-30 15:45
    Hi All,

    Did an experiment last night (12AM...yawn...) where I programmed a PAUSE command with a value of 0 (zero) wedged in between an I/O pin going high and going low.· Using the nifty BSLA tool, it appears that a "PAUSE 0" has an execution time of approximately 390us.· This was a one-shot event.· I did not set up a loop, view it with a scope and calculate averages.

    This experiment was performed on with a Basic Stamp 2 running Parallax 2.5 BASIC.· I would imagine the other members of the Basic Stamp product line would give different results due to different clock rates and different internal efficiencies.

    I've yet to try the dummy PULSOUT suggestion from Mr. Green.

    Just in case you were wondering,

    DJ
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-05-31 03:30
    davejames,

    You can also use other "do nothing" commands other than PAUSE 0 to create a small similar effect delay... Here are some examples with ones you've tried included.



    'Baseline.... approx 420uS to execute two commands... TOGGLE and GOTO
    'TestLoop:
    'TOGGLE 0
    'GOTO TestLoop
    
    
    'TestLoop:
    'TOGGLE 0
    'PAUSE 0             '<- adds about 235uS to baseline value
    'GOTO TestLoop
    
    
    'TestLoop:
    'TOGGLE 0
    'W0=W0               '<- adds about 170uS to baseline value
    'GOTO TestLoop
    
    
    'TestLoop:
    'TOGGLE 0
    'B0=B0               '<- adds about 200uS to baseline value
    'GOTO TestLoop
    
    
    'TestLoop:
    'TOGGLE 0
    'B0=0                '<- adds about 165uS to baseline value
    'GOTO TestLoop
    
    
    'TestLoop:
    'TOGGLE 0
    'W0=0                '<- adds about 165uS to baseline value
    'GOTO TestLoop
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • davejamesdavejames Posts: 4,047
    edited 2008-05-31 16:42
    Mr. Schwabe,

    Thank you for the info.· May I ask what Stamp module was used to determine the noted time values?· And what method was used to qualify them?

    The 390us value I saw for a "PAUSE 0" on a BS2 was from the BSLA setup for 1M samples.· I think the BSLA reports fairly accurately as I used it to verify a "PULSOUT 1, 5" of 10us, although I haven't proved it with a scope yet.

    Thank you and thanks to the other Parallax employees who monitor this forum so frequently,

    DJ
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-05-31 19:56
    davejames,

    I used a BS2 RevE connected to a Tektronix TDS 220 scope. (Screen shot attached).
    The program uses the TOGGLE command to flip a pin either HIGH or LOW. The reason that TOGGLE is used instead of using the HIGH or LOW command is mainly for program execution symmetry. This allows the program to take the same amount of time to make the pin HIGH as it does to make the pin LOW. When using this method, program execution symmetry is important for correct timing measurements. Just keep in mind that if you look at the signal on a scope from rise time to rise time (The period) or fall time to fall time, that the value you read is actually twice the execution value that you are looking for. This is because the program (via the TOGGLE command) has to run through twice to accomplish the two similar events that you are looking for on the scope.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
    900 x 600 - 156K
  • davejamesdavejames Posts: 4,047
    edited 2008-06-01 02:16
    Mr. Schwabe,

    Understood - I forgot about the time it takes for a HIGH or LOW command to execute (as previously warned by Mr. Green).

    Thank you for the follow up, for taking the time to research the question and providing a scope shot.

    TDS220; great line of scopes. I've been using the TDS210 model over 10 years for debug in my classes. Hardly any problems.

    Regards,

    DJ
Sign In or Register to comment.