Code speed and execution time


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39

    Default Code speed and execution time

    I am using a For/Next loop to sent the variable out to an I2C DAC. The variable is counting from 1 to 255.

    The sawtooth waveform only has a frequency of 1.33 hz indication an execution time for each loop of 3mSec.

    I am using a 16F690 PIC running at 8Mhz, PBP and MPLAB IDE V8.63. Does this time to execute one loop sound right?

    The other question is the number of lines of code compiled. In the MPASM window it tell me the number of lines assembled is 9082. Again does this sound right?

    Thanks
    aajgss

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    Well that does seem really Slloooooowwwww. but maybe a little more info please. code and configs would go a long way here.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Apr 2011
    Location
    NSW, Australia
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    Bert,
    Thanks for the quick reply
    OK more info - one other question how do I get my code into the scrolling window?

    I have a line in there :- i2cread DPin,CPin,$90,1,[c], if I take it out the code doesnt work.


    Code

    DEFINE osc 20
    DEFINE LOADER_USED 1
    INCLUDE "MODEDEFS.BAS"
    DEFINE I2C_SLOUT
    ANSEL =%00000001 ' Enable ADC channel-AN0
    ANSELH =%0000
    'ADCON0.7 = 1
    SSPCON =%00101011
    TRISB.4 =0
    TRISB.6 =0
    TRISA =%00001111
    TRISC =%00000000
    CPin VAR PORTB.6
    DPin VAR PORTB.4
    a var word
    c var byte

    MAINLOOP
    for a = 1 to 255
    I2Cwrite DPin,CPin,$90,a
    i2cread DPin,CPin,$90,1,[c]
    next
    goto Mainloop

  4. #4
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    Add code tags - select the text and then click on # above the edit window.
    Code:
    DEFINE osc 20
    DEFINE LOADER_USED 1
    INCLUDE "MODEDEFS.BAS"
    DEFINE I2C_SLOUT
    ANSEL =%00000001 ' Enable ADC channel-AN0
    ANSELH =%0000 
    'ADCON0.7 = 1
    SSPCON =%00101011
    TRISB.4 =0
    TRISB.6 =0 
    TRISA =%00001111 
    TRISC =%00000000 
    CPin VAR PORTB.6
    DPin VAR PORTB.4
    a var word
    c var byte
     
    MAINLOOP
    for a = 1 to 255
    I2Cwrite DPin,CPin,$90,a
    i2cread DPin,CPin,$90,1,[c]
    next
    goto Mainloop

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    The easy to answer question is to put your code in the cool code box, you have to do this:
    [ code ]

    put code here

    [ / code ]

    but with no spaces

    Still thinking on the real question
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    I am not familiar with I2C, but I do notice that in your initial description you say the crystal is 8M, but in the code it is defined 20M...

    The rest I do not know, but some thoughts...

    Commenting the 2 I2C lines and recompile would give an indication of how much code is actually there (in I2C part)--and how that interface affects speed. The difference (between with no I2C and with I2C) should match pretty closely with datasheet transaction time for DAC chip?

  7. #7
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default Re: Code speed and execution time

    Using the software implementations of i2c read/write are DREADFULLY SLOW. Yes, I am not surprised you get such a slow loop.

    There are several ways to dramatically speed it up.
    1. use the hardware i2c--this will speed it up by about 30-40x at least.
    2. put the addressing with STARTs, etc, outside the loop, and just clock the data sequentially. This will get you almost 4x improvement.
    3. Use a repeat until or do while instead of a for-loop. The For-loop is a lot slower than the other loops when timing is important...but it won't help nearly as much as 1 or 2.
    4. Send 256 bytes instead of 255...that way it can init at 0 and loop until 0 again, and that's often a one-instruction savings, depending on the pic.

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