PIC Math - the need for speed


Closed Thread
Results 1 to 19 of 19

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Apparently, your Scope works Really Well.

    I ran the numbers again for a 16F877 this time, and the results are rather surprising.
    Code:
    Start:                     ' Cycles   uS@20mhz
        PORTD.0 = 1            '    1         .2
        Delay = Value /*$004D  '  243       48.6
        PORTD.0 = 0            '    1         .2
        PauseUs 700            ' 3502      700.4
    Goto Start                 '    4         .8
                                 -----     -----
               '    Loop Total   3751      750.2
               ' Without Pause    249
    Code:
                                ' Cycles   uS@20mhz
    Dummy1 = OldPulseTime >> 2  '  37        7.4
    Delay = Dummy1 >> 2         '  37        7.4
    Delay = Delay + Dummy1      '   6        1.2
                                 -----     -----
                  '      Total     80       16.0
    Code:
                                ' Cycles   uS@20mhz
    Dummy1 = OldPulseTime >> 1  '   5        1.0
    Dummy1 = Dummy1 >> 1        '   3         .6
    Delay = Dummy1 >> 1         '   5        1.0 
    Delay = Delay >> 1          '   3         .6
    Delay = Delay + Dummy1      '   6        1.2
                                 -----     -----
                  '      Total     22        4.2
    I really didn't expect that much difference between the same code compiled for the 2 different chips.

    Way to go Ingvar.
    Last edited by Darrel Taylor; - 11th October 2005 at 00:57.
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,
    Wow, thanks!
    I agree, that's a bit strange isn't it? It's gonna be interesting to see how fast it will run on the 12F629 where it actually will reside and operate when it's finished. That timing routine of yours seems to come in handy from time to time!

    Thanks again!
    /Henrik Olsson.

  3. #3
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Thumbs up

    Darrel,
    You forget that your 18F uses it's hardware multiplier. The 16 series does not have one and needs to do a software multply, that's a HUGE difference. I'm a little surprised that the ">>2" takes that much longer than ">>1". I suspected around 10-20 cycles difference, not 60. It should take a little longer since it uses a looped code rather than the straight code ">>1" produces. Strange, perhaps i'll look into it sometime ............ or not.

    Henrik,
    You should make sure that the variables reside in the same memorybank. You do that by using the "BANK" statement. If you don't it will be slower since the pic needs to switch banks between each statement. Declare your variables like .....
    Code:
    Dummy1          VAR WORD BANK0
    Delay           VAR WORD BANK0
    OldPulseTime    VAR WORD BANK0
    /Ingvar

    PS. Henrik, vart skall jag skicka fakturan DS.

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


    Did you find this post helpful? Yes | No

    Default

    Right Ingvar,

    That's what it is, the Hardware Multiplier.

    The funny thing is that a couple of years ago, I did a comparison between 16F and 18F multiplication, and found that PBP didn't use the hardware MUL for 18F's. So, I made my own MUL routine for 18F's and have been using it ever since (when I need the speed). I hadn't looked since then, but, meLabs must have snuck it in there when I wasn't paying attention. Nothing listed in the Version History.

    That's good to know!
    <br>

    P.S. Ingvar, Add some to that bill for me too.
    Last edited by Darrel Taylor; - 13th October 2005 at 01:40.
    DT

  5. #5
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Question

    Sure, as soon as Henrik tells me where to send it

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default

    Ingvar,
    I thought you allready had my billing adress since you helped me with that asm isr a couple of years ago.....
    You're in Stockholm, right? Me and two friends are going there on Friday-Saturday to have some fun and visit the famous jazz-club Stampen. Come there and I'll buy you a beer or two! You too Darrel, but I guess it's a little too far off for you...

    Things have come in between me and this project right this week but I'll let you know how it all works out.
    I appreciate the help guys, I really do!

    /Henrik Olsson.

  7. #7
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Default

    Sorry Henrik, i live out my days on the westcoast, Kungsbacka to be precise. Good luck with the rest of the project ....... and don't smoke anything in a jazz-club, i hear it's not always tobacco Not that i'd really know since i'm not a jazzfan.

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 11:00
  2. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 15:46
  3. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 22:01
  4. My PIC can't do the math! Can yours?
    By sayzer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th May 2006, 08:28
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th March 2005, 00:14

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