PULSOUT versus toggling a pin


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263

    Question PULSOUT versus toggling a pin

    I need to send a 5 us pulse to a pin. I'm using a 16F88 at 8 MHz and need to keep processing overhead down.

    Which is faster, using PULSOUT or this:

    PIN=1
    PAUSEUS 5
    PIN=0

    I have to do this at different (and varying) times on 5 different pins.

    Russ
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    At 8mHz, the minimum PAUSEUS is 12uS (14-bit cores).

    Minimum PULSOUT is 5uS.

    Apples and Oranges (no tomatoes)

    Although, here's an ASM delay routine that can do down to 1uS at 8mHz.
    http://www.picbasic.co.uk/forum/show...8&postcount=22

    Then just ...
    Code:
    PIN=1
    @  DelayUS 5
    PIN=0
    It only works with constants though, no variables.

    hth,
    DT

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Here's a simple macro I use for short delays.
    Code:
    asm
    DelayCycles macro ncy ; ncy can be from 1 up to 256
      local n
    n set   (ncy)   ; assign ncy value to label n
    
      while n > 2   ; inserts goto $+1 while n > 2
        goto $+1    ; burn 2 cycles
    n   set   n - 2 ; n = n - 2
      endw
                    ; handle left-overs
      while n > 0   ; 1 nop for odd numbers
        nop         ; burn 1 cycle
    n   set   n - 1 ; n = n - 1
      endw
      endm
    endasm
    
    Main:
      HIGH 0
      @ DelayCycles 1  ; adds 1 nop
      LOW 0
      @ DelayCycles 5  ; adds 2 x goto $+1 and 1 x nop
      GOTO Main
    It provides delays from a single instruction cycle up to 256. For a 5uS delay at 8MHz just
    use @ DelayCycles 10
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Hello

    Here a simple way to do a fast pulse out delay. At 8mhz setting portb =1 takes 2 cycles or 1us.


    Portb.1 =1
    Portb.1 =1
    Portb.1 =1
    Portb.1 =1
    Portb.1 =1
    Portb.1 =0

    Regards

  5. #5
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    At 8mHz, the minimum PAUSEUS is 12uS (14-bit cores).
    Oh, <i>DUH!</i> I <u>did</u> know about that minimum; I can't believe I forgot it!

    Interestingly, if you give PAUSEUS anything less than 12 (at 8 MHz), it defaults to 12. I verified this on the scope.

    Also from looking at the scope: Using PULSOUT takes longer despite allowing the shorter pulse length.

    Mark, thanks for the idea. Ideally, I'd like to have a 3 us, so I'll play with your suggestion and see how it looks.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  6. #6
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    While Mark's way is functional, I prefer other methods to avoid thinking the repetitive PortB.1=1 isn't a typo or accidental copy/paste.

    There are two more ways to do it. Using NOP's makes it very clear that it is a delay.

    PortB.1=1
    asm
    NOP
    NOP
    NOP 'repeat as necessary
    endasm
    PortB.1 = 0

    However, using GOTO's executes in the same amount of time, but uses half the program space. You have to be cautious of pages, though. The best way is with the basic goto command, but then you might get excess overhead with page checking.

    Portb.1 = 1
    goto skip1 'kills a minimum of 2 cycles
    skip1:
    goto skip2
    skip2:
    portb.1=0

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Russ,
    Using the same idea you can control all you pins at same time. Its not pretty or clever, but it works

    PortB = %00000001 ;pin 0 high 3us
    PortB = %00000001
    PortB = %00000001
    PortB = %00000010 ;pin 0 low, pin 1 high 3us
    PortB = %00000010
    PortB = %00000010
    PortB = %00000100 ;pin 1 low, pin 2 high 3us
    PortB = %00000100
    PortB = %00000100
    PortB = %00000000 ;all pins off

    Loop etc

    Tenaja is your name Don L?

  8. #8
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mark_s View Post
    Russ,
    Using the same idea you can control all you pins at same time. Its not pretty or clever, but it works

    PortB = %00000001 ;pin 0 high 3us
    PortB = %00000001
    PortB = %00000001
    PortB = %00000010 ;pin 0 low, pin 1 high 3us
    PortB = %00000010
    PortB = %00000010
    PortB = %00000100 ;pin 1 low, pin 2 high 3us
    PortB = %00000100
    PortB = %00000100
    PortB = %00000000 ;all pins off

    Loop etc
    Repetitive port settings on 16F (and lower) devices must also take into account the read/modify/write timing. If you place two consecutive settings in a program, you could end up with a random output setting because of the r/m/w delays.

    Tenaja is your name Don L?
    No.

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mark_s View Post

    Tenaja is your name Don L?
    Don L. lives in Arizona, and sells stuff on ebay
    Edit: Oh and he will autograph his books too . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  3. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. Help Quick Need to make code smaller
    By Programmednew in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th January 2005, 03:46

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts