PIC instruction time


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2007
    Location
    Suffolk, UK
    Posts
    59

    Default PIC instruction time

    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

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,528


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Adrian View Post
    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).

  4. #4
    Join Date
    May 2007
    Location
    Suffolk, UK
    Posts
    59


    Did you find this post helpful? Yes | No

    Default

    Many thanks to you both

    Regards

    Adrian

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


    Did you find this post helpful? Yes | No

    Default

    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...
    Code:
    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).
    DT

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  2. Replies: 67
    Last Post: - 8th December 2009, 02:27
  3. Can a PIC PIC a PIC?
    By afbecker in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd January 2008, 19:55
  4. Two PIC 16F877A fried in two days!
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th January 2007, 10:38
  5. instruction execution time
    By tjg in forum Code Examples
    Replies: 3
    Last Post: - 21st April 2004, 18:15

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