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
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    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.

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

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

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

  5. #5
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default Hpwm pbp

    Hi
    @30Mhz you can get way faster HPWM from the chip BUT you can NOT use the HPWM command in PBP. You need to get inside the car and drive yourself. Set up the HPWM module manually, examples on Page 87 in the datasheet Table 9-3

    Hope this helps

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sinoteq View Post
    Hi
    @30Mhz you can get way faster HPWM from the chip BUT you can NOT use the HPWM command in PBP. You need to get inside the car and drive yourself. Set up the HPWM module manually, examples on Page 87 in the datasheet Table 9-3

    Hope this helps
    HAHA well sure I could use the formula to find out if it will be fast enough but one needs to know what "log, log2 and bits" are first. I wish these manuals would explain the formulas a little better.

    How fast is "way faster"? keep in mind the 16f88 will be running at 20MHz but the external chip I am interfacing with can be driven with up to 30MHz.

    See I was thinking the fastest way would be to use some simple ASM to turn a Pin HIGH then turn Pin LOW and was thinking this could possibly achieve maybe a 5MHz signal.

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    I think that the highest frequency you can get out of the CCP module is 2.5Mhz when the chip running at 20Mhz. Even so I don't think it's going to do what you want since there's no easy way to control the number of cycles or "pulses" that is going out and as far I understand you need exactly 4096 "pulses".

    Perhaps it's possible to connect the CCP output back into a counter input and set that up to generate an interrupt which stops the CCP module at the right spot but it seems like a long shot.

    I'm definetly no "ASM-guy" but to set and reset a pin (or rather the port latch) in ASM you can do:
    Code:
    @ BSF PORTA, 3
    @ BCF PORTA, 3
    But even if you put 4096 of those in a row you won't get more that 2.5Mhz because each instruction takes one cycle and one cycle is Fosc/4 meaning 200ns per cycle @20MHz so the frequency would be 1/400ns=2.5Mhz. Not to mention you'd fill up the flash memory of the 16F88....

    How about this, I THINK it should run faster than your For i = 0 to 4095 loop.
    Code:
    i VAR BYTE
    j VAR BYTE
    For i = 1 to 16      '16*256=4096
      For j = 0 to 255
    @  BSF PORTA, 3
    @  BCF PORTA, 3
      NEXT
    NEXT
    If I'm right that inner loop seems to execute in 7 cycles and the outer loop seems to take another 12 for a total of (7*256*16)+(12*16)=28864 cycles @ 200ns each. A total of 5772.8us for 4096 pulses or an average frequency of ~709kHz. There will be some jitter in the pulsestream when it goes from the inner to outer loop but I guess it doesn't matter(?)

    /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