PDA

View Full Version : PIC instruction time



Adrian
- 25th June 2007, 20:51
I am just curious about PIC speed. I have a (working!) programme running on a 16F876A @ 4mHz ending with two PULSOUT commands, simply
PULSOUT 7, LX
PULSOUT 5, RX

The values of LX and RX are variable but in the region of 2.5mS.

If I scope the two outputs I see the second following the first but there is about a 58uS gap between the two pulses. Can anyone please tell me why there should be this gap - I naively thought the instruction time would be about 1 uS. I'm a bit new to all this!!!

With thanks

Adrian

HenrikOlsson
- 25th June 2007, 21:15
Hi,
You are correct in thinking it's 1uS per instruction at 4Mhz but that's 1uS per ASM instruction. The PULSOUT command consists of many ASM instructions so it takes longer time.

Since the PULSOUT automatically sets the pin to an output that takes time and since the 'active' state of the pulse depends on the current state of the pin when PULSOUT is issued the PIC needs to read the pin to determine if it should drive it high or low for the duration you specify - that also takes time.

Someone else can probably explain exactly where those 58uS goes.

HTH

/Henrik Olsson.

skimask
- 25th June 2007, 22:06
I am just curious about PIC speed. I have a (working!) programme running on a 16F876A @ 4mHz ending with two PULSOUT commands, simply
PULSOUT 7, LX
PULSOUT 5, RX
The values of LX and RX are variable but in the region of 2.5mS.
If I scope the two outputs I see the second following the first but there is about a 58uS gap between the two pulses. Can anyone please tell me why there should be this gap - I naively thought the instruction time would be about 1 uS. I'm a bit new to all this!!!
With thanks
Adrian

Open up your xxxxxx.LST file and you should see the instructions that are responsible for the gap, if not in the main line of the code, then somewhere in PBP's pulsout subroutine itself.
If you try:
main:
pulsout 5,LX
goto main
you'll probably see the same gap, maybe 60us (2us extra for the goto).

Adrian
- 25th June 2007, 22:19
Many thanks to you both

Regards

Adrian

Darrel Taylor
- 26th June 2007, 02:53
Well, that's the why?
All you need's a How to Fix.
Assuming you want a fix, (>> I am just curious about PIC speed.)

If you need the 2 pulses to transition at the same time, you could do something like this...
PORTB.7 = 1
PAUSEUS LX * 10 ; adjust to PULSOUT's 10us resolution @4mhz
PORTB = PORTB & %01011111 | %0010000 ; R-M-W both pins at the same time
PAUSEUS RX * 10
PORTB.5 = 0

Of course, this just shifts the extra time to the "Inside" of the pulses, instead of between them. But, that additional time can be minimized if LX and RX are already scaled to match PULSOUT's 10us resolution (*10).