code needs much longer then expected


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    72

    Default code needs much longer then expected

    hi all

    on a 12f675 with internal osc speed 4mhz i have the following main routine. this toggles two digital outputs asyncronus. i thinked (dangerous?) that one cycle of this while execution needs some us - each line1 us. but in fact it needs much longer, around 800 us... any ideas why and what can be done for speed up?

    thanks a lot

    Code:
                  while z < 60                ' 30 cycles : 60 toggles of x=out1
                    if x > 0 then             ' as long as the half cycle is not at the end
                      x = x - 1               ' decrement     
                    else                      ' when the half cycle is finish
                      x = an1 + base1         ' set the delay new with the old values
                      z = z + 1               ' inc loop counter
                      out1 = out1 ^ 1         ' toggle output      
                    endif  
                    if y > 0 then
                      y = y - 1
                    else
                      y = an2 + base2
                      out2 = out2 ^ 1               
                    endif 
                  wend
    i know it's only microcontrolling, but i like it!

  2. #2
    Join Date
    Mar 2003
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Complex logic takes time

    I am not surprised that each line averages 800 uSecs. You have some pretty complex logic in those statements.

    Have a look at the machine code listing the basic source produces and you will see just how many instructions are involved.

    Also, you will find big differences in execution time for BYTE and WORD variables.

    For example
    A var byte
    w var word

    if a<9 then dosomething
    runs much faster than
    if w<9 then dosomething

    For any realtime work I define a port as a diagnostic pin and make sure it is an output then check the execution time with an oscilloscope.

    Diag var portb.0 (for example)
    Trisb = %11111110 (or whatever)

    Then before each program block I want to test for execution time I put

    Diag = 1
    Code to be tested goes here
    Diag = 0

    This runs a little faster than
    HIGH Diag
    Code goes here
    LOW Diag

    The oscilloscope is invaluable if you have a time critical application.

    HTH
    Brian

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. "Program Memory Error" with MPLAB IDE (PBP)
    By aggie007 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th November 2007, 19:27

Members who have read this thread : 1

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