Shop OBEX P1 Docs P2 Docs Learn Events
BS2p40 PAUSE smaller than 1 ms??? — Parallax Forums

BS2p40 PAUSE smaller than 1 ms???

Pressus LimitedPressus Limited Posts: 23
edited 2010-06-10 14:15 in BASIC Stamp
Hi Guys,

linked to my previous post on stepper motor control, I need to introduce a·PAUSE smaller than the 1ms you get with the PAUSE command to allow me to increase the motor speed.· the A4983 datasheet says it needs a minimum 1uS HIGH step signal with a minimum 1uS LOW signal.··I've put in: FOR·c=1 TO 3:·NEXT·which seems to work ok, my question is, am I right in thinking that this will introduce a delay of approximately 25uS ( (1 sec /12000 instructions per sec) * 3)???

Is there a better or·more accurate way of doing it????

thanks

Jon

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2010-06-08 13:44
    If you have an unused pin, you can use a "PULSOUT" statement of the appropriate length.
  • Pressus LimitedPressus Limited Posts: 23
    edited 2010-06-08 15:54
    Thanks, but unfortunately I don't have any spare pins :-(
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-09 07:55
    You can send a string of positive-going pulses using SEROUT. Set it for inverted mode and send a string of $FF values using the REP modifier. You will get a pulse train whose period is governed by the baud rate. To double the width of each pulse, send $FE instead of $FF.

    -Phil
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-06-09 08:45
    Anything you do with program loops take 100s of microseconds, even on the BS2P40. It is an interpreted language. The figure of 12000 instructions per second (83 microseconds per instruction) is an average, and some instructions are faster, some a lot slower. The <FOR c=1 to 3:NEXT> would take more like 650 microseconds.

    Another way to get a string of pulses out fast is via the PWM command. For example,
    PWM 1,41,1
    or
    PWM 1,1,41
    either put out a string of 41 pulses, but the first form does it in less than 1 millisecond while the second form spreads it out over 41 times as long. The second argument (duty) should be less than 128 and the third argument (frames) can be up to 255.
    The individual pulses are a little over 1 microsecond long. (A PWM frame consists of 256 time slots that can be either low or high, and duty=128 gives half and half evenly spaced).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2010-06-09 08:52
    Pressus Limited,

    Here is where a scope really comes in handy. Below are a few different tests. I didn't have a BS2p40, but I used a standard BS2. The idea should still be the same however.

    Tracy Allen,

    Yes, the code is interpreted and it's going to take awhile to load, but you can create 'do nothing' functions using the LOOKUP or LOOKDOWN to act as a predictable hard coded timing loop, but again a SCOPE really helps to debug and determine what the timing is going to be.



    Note: The times below are measuring how long the test pulse was HIGH
    Test1:
      HIGH 0
      PAUSE 1             '1360us
      LOW 0
    
    Test2:
      HIGH 0
      FOR B0=1 TO 3:NEXT  '2440us
      LOW 0
    
    Test3:
      LOW 0
      HIGH 0    ' 140us
      HIGH 0    ' 280us
      HIGH 0    ' 420us
      HIGH 0    ' 560us
      HIGH 0    ' 700us
      HIGH 0    ' 840us
      HIGH 0    ' 980us
      HIGH 0    '1120us
      HIGH 0    '1260us
      HIGH 0    '1400us
      LOW 0
    
    Test4:
      HIGH 0
    ' LOOKUP 0,[noparse][[/noparse]0],W0                     ' 460us
    ' LOOKUP 0,[noparse][[/noparse]0,0],W0                   ' 570us
    ' LOOKUP 0,[noparse][[/noparse]0,0,0],W0                 ' 680us
    ' LOOKUP 0,[noparse][[/noparse]0,0,0,0],W0               ' 790us
    ' LOOKUP 0,[noparse][[/noparse]0,0,0,0,0],W0             ' 900us
    ' LOOKUP 0,[noparse][[/noparse]0,0,0,0,0,0],W0           '1010us
    ' LOOKUP 0,[noparse][[/noparse]0,0,0,0,0,0,0],W0         '1120us
    ' LOOKUP 0,[noparse][[/noparse]0,0,0,0,0,0,0,0],W0       '1230us
      LOOKUP 0,[noparse][[/noparse]0,0,0,0,0,0,0,0,0],W0     '1340us
      LOW 0
    
    

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

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 6/9/2010 8:57:45 AM GMT
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-06-09 16:32
    Hi Beau,
    The OP is asking about the BS2p40, and I surmise that the times you listed above are for the BS2 or BS2e. Right? Surmise based on the 140 µs time for LOW 0: HIGH 0. BS2p is a little over 3x faster. The LOW 0:HIGH 0 sequence takes close to 41 µs on the BS2p.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2010-06-09 16:53
    Tracy Allen,

    "The OP is asking about the BS2p40, and I surmise that the times you listed above are for the BS2 or BS2e. Right?" - Yes, that is correct, I did not have a BS2p40 to check, and I indicated that in my post. I was just showing a few different methods to get a deterministic amount of timing that was smaller than the 1ms intervals.

    A Scope is essential though when timing like this plays a big part of the design.

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

    IC Layout Engineer
    Parallax, Inc.
  • allanlane5allanlane5 Posts: 3,815
    edited 2010-06-10 14:15
    And I have used the "Ant-8" as a very nice USB-attached logic analyzer for these kinds of timing studies.
Sign In or Register to comment.