While Loops Slow??


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    There is no way your original code could be 5 instructions or less per loop. Each line of code will create at least 1 instruction. You have 4 lines inside the while, so at least 4 instructions plus two for the while (test and branch) will be executed each loop. For every if statement that is true you will get at least 1 additional instruction if not more.

    So now you need to look at the old equipment and determine how fast you really need to detect changes. Is the original equipment running on a 1 MHz clock or is the output signal yopu want to monitor changing at a 1 MHz rate? If the signal you are looking at is changing at a 1 MHz rate, you will need a faster solution to detect it.
    Tim Barr

  2. #2


    Did you find this post helpful? Yes | No

    Default

    You know, thinking on it more, maybe speed is not an issue. If you are using the PIC to replace a 7 segment display with a dot matrix display, and you are trying to translate 7 segment lines into characters so you can send characters to a dot matrix display, this is something the human eye is looking at and the 7 segment display may not really be changing at a 1 MHz rate. I bet the old design is multiplexing the 7 segment displays at a much lower rate than you think. What you may need to do is detect which 7 segment digit is active, read the data going to that display and then translate it into a character to send to the dot matrix display. Typically that is milliseconds, not nanoseconds that you are dealing with. Unless the 7 segment displays have 7 segment decoders that the processor is writing to. Then you have to capture data when it is clocked into the decoder register. In that case, you could sense the clock edge and then read the data bus.
    Tim Barr

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hey Frozen001, any luck???
    Tim Barr

  4. #4
    Join Date
    Aug 2008
    Posts
    39


    Did you find this post helpful? Yes | No

    Default

    Well I boiled it down to the fact that PICBasic makes bloated code when you finally get to the actual number of inctructions it takes to perform certain tasks. My WHILE loops take more instructions than REPEAT:UNTIL loops. I got it working with a lot of tweaking by trying different commands.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Frozen001 View Post
    Well I boiled it down to the fact that PICBasic makes bloated code when you finally get to the actual number of inctructions it takes to perform certain tasks. My WHILE loops take more instructions than REPEAT:UNTIL loops. I got it working with a lot of tweaking by trying different commands.
    That's pretty much true of any "high level language". To get the ease of programming, you take a hit on performance. Unless you pay the big bucks for a "optimizing" compiler. And even optimized code doesn't get quite the performance as hand coding in assembly.

    Good to hear you got things to work otherwise.
    Tim Barr

Similar Threads

  1. 4 Channel Thermostat using PID loops
    By malc-c in forum Code Examples
    Replies: 36
    Last Post: - 18th March 2013, 11:17
  2. Multi Slow speed PWM and Instant Interrupts
    By DaveC3 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd November 2010, 13:50
  3. Slow code needs a tune up
    By Tobias in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th January 2010, 16:05
  4. Going Loopy - How do i get my Loops sorted out ???
    By gtvmarty in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th September 2009, 06:02
  5. Code Executing Slow
    By Frozen001 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 5th September 2008, 22:09

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