How can I speed this code up? SHIFTOUT is slowing it down and I need a faster way.


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Use a 16 bit counter in assembly to count to 0FFF.
    In that loop, use the instruction -

    btg LATA.3

    You can't get much quicker than that.

    I haven't counted exactly, but it looks to be under 14 cycles. At 40Mhz, that is
    1.4uSEC = 714 Khz.
    Charles Linquist

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I should have stated that it is 1.4uSec per CYCLE. So 4096 cycles would take 5.8 milliseconds.
    Charles Linquist

  3. #3
    Join Date
    Mar 2010
    Location
    Minnesota, USA
    Posts
    41


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    Use a 16 bit counter in assembly to count to 0FFF.
    In that loop, use the instruction -

    btg LATA.3

    You can't get much quicker than that.

    I haven't counted exactly, but it looks to be under 14 cycles. At 40Mhz, that is
    1.4uSEC = 714 Khz.
    so do I just replace this:
    Code:
    	FOR C3 = 0 TO 4095
        		PORTA = %00001000
        		PORTA = %00000000
    	NEXT
    with this:
    Code:
    FOR C3 = 0 TO 4095
         btg LATA.3
    NEXT
    I do not know assembly at all thats why I went with PBP and keep in mind I am using a 16MHz Clock but I will be switching it up to a 20MHz
    Last edited by wolwil; - 9th May 2010 at 00:19.

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    No, it will take a bit more than that.

    I would have posted something more complete, but I don't have access to my development board until Monday. When I get to my board, I'll be able to send you something that has been tested.
    Charles Linquist

  5. #5
    Join Date
    Mar 2010
    Location
    Minnesota, USA
    Posts
    41


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    No, it will take a bit more than that.

    I would have posted something more complete, but I don't have access to my development board until Monday. When I get to my board, I'll be able to send you something that has been tested.
    That would be awesome! Thanks

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wolwil View Post
    That would be awesome! Thanks

    It will take me a bit longer than I thought. I think you said you were using a 16F chip. Bad news for me! The 16Fs are missing some of my favorite ASM instructions.

    I don't have any 16F stuff lying around, I'll have to find one.
    Charles Linquist

  7. #7
    Join Date
    Mar 2010
    Location
    Minnesota, USA
    Posts
    41


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    It will take me a bit longer than I thought. I think you said you were using a 16F chip. Bad news for me! The 16Fs are missing some of my favorite ASM instructions.

    I don't have any 16F stuff lying around, I'll have to find one.
    Thats alright I have been trying to get it to work with the HPWM but I just dont quite understand how to get it to work. I put a LED on PORTB.0 and typed the following code but nothing happens to the light:

    Code:
    DEFINE OCS 4
    
    C1 VAR WORD
    
    DEFINE CCP1_REG PORTB   'no clue what this does but I think I need it for the following line
    DEFINE CCP1_BIT 1     ' because 1 = portb.0 according to the manual I think?
    
    FOR C1 = 0 to 255
    HPWM 1,C1,1000 
    NEXT
    I was thinking I could use this for my clock pulse of 4096 times like this:

    Code:
    FOR C1 = 0 TO 15
    HPWM 1,127,frequency '50% duty/square wave
    NEXT
    for right now I have a second external clock hooked up that I am turning on with throwing a pin high for a couple milliseconds and it fixed what I am trying to fix but its not exact like I need it to be.

    Thanks again for your time with this!

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Some PIC's can map the output of the CCP-module to different pins, the 'F88 can map it to either RB0 or RB3. The defines you have tells PBP to generate code to map the CCP1 output to the pin you specify. However, BIT 1 as you've specified means it tries to map it to PORTB.1 which isn't valid.

    /Henrik.

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