PDA

View Full Version : PULSOUT versus toggling a pin



RussMartin
- 26th January 2010, 07:07
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

Darrel Taylor
- 26th January 2010, 08:41
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/showpost.php?p=22098&postcount=22

Then just ...
PIN=1
@ DelayUS 5
PIN=0

It only works with constants though, no variables. :(

hth,

Bruce
- 26th January 2010, 16:57
Here's a simple macro I use for short delays.


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

mark_s
- 26th January 2010, 17:49
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

RussMartin
- 26th January 2010, 18:58
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.

tenaja
- 26th January 2010, 20:24
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

mark_s
- 26th January 2010, 21:37
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?

tenaja
- 26th January 2010, 21:44
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.

Archangel
- 27th January 2010, 02:54
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 . . .

mark_s
- 27th January 2010, 15:59
My mistake he goes by "tinaja" not Tenaja. Don Lancaster was a big influence for me in the late 70's and early 80's.