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

    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

  2. #2
    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

  3. #3
    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

  4. #4
    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!

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    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.

  6. #6
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Default How about ASM replacement for PBP Shiftout?

    Hi Wolwil,

    You could replace PBP SHIFTOUT with attached ASM code example and reduce time spend in SHIFTOUT + loop to ~1/8. This is kind of tested, but no promises ... Check if it is usefull for you.

    PBP_shiftout execution time was around 814uS, but ASM_shiftout took only 104uS to do the same.

    Files:
    PBP_shiftout.pbp.txt <- Original, copied from 1st post
    ASM_shiftout.pbp.txt
    (Just remove .txt from end of files)

    I know that ASM version is spaghetti code but I don' really care
    So long time since last time when I did something with ASM.

    BR,
    -Gusse-
    Last edited by Gusse; - 11th May 2010 at 20:18.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    However, BIT 1 as you've specified means it tries to map it to PORTB.1 which isn't valid.

    /Henrik.
    See I was confused because in the manual it said:
    bit 3-0 CCP1M<3:0>: CCP1 Mode Select bits
    0000 = Capture/Compare/PWM disabled (resets CCP1 module)
    0100 = Capture mode, every falling edge
    0101 = Capture mode, every rising edge
    0110 = Capture mode, every 4th rising edge
    0111 = Capture mode, every 16th rising edge
    1000 = Compare mode, set output on match (CCP1IF bit is set)
    1001 = Compare mode, clear output on match (CCP1IF bit is set)
    1010 = Compare mode, generate software interrupt on match (CCP1IF bit is set, CCP1 pin is
    unaffected)
    1011 = Compare mode, trigger special event (CCP1IF bit is set, CCP1 pin is unaffected); CCP1
    resets TMR1 and starts an A/D conversion (if A/D module is enabled)
    11xx = PWM mode
    So I was thinking the xx was what I was setting so I figured the LSB was 1 for port B0 and 2 for B3. Like I said I was confused

    So you are saying all I need to do is say 0 and not 1, right?


    Quote Originally Posted by Gusse View Post
    Hi Wolwil,

    You could replace PBP SHIFTOUT with attached ASM code example and reduce time spend in SHIFTOUT + loop to ~1/8. This is kind of tested, but no promises ... Check if it is usefull for you.

    PBP_shiftout execution time was around 814uS, but ASM_shiftout took only 104uS to do the same.

    BR,
    -Gusse-
    Thanks I will try this out tonight!
    Last edited by wolwil; - 11th May 2010 at 21:34.

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


    Did you find this post helpful? Yes | No

    Default I was able to get the HPWM to work but no luck on the ASM

    here is the code for the PWM:
    Code:
    C1 var byte
    
    For C1 = 0 to 31
        hpwm 1,127,32767
    next
    looks like I didn't need all the extra mumbo jumbo before it as the 16f88 defaults to b0 for channel 1

    The sad thing is this still is not fast enough to do what I need it to do.

    I am trying to generate 4096 clock pulses as fast as possible. The chip will allow up to a 30MHz clock pulse to drive it but using the HPWM all I can get is 32,767Hz which is like paying full price for a Lamborghini that only has first gear.

    Does anyone have any ideas on how I might be able to achieve this?

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