Go to last post By: charliecoultas
Today 08:15
Forum: The Lounge
Starter: RGV250
Views: 0
Replies: 3
Go to last post By: AlbertoFS
Today 07:07
Forum: Proton Plus Compiler v3
Starter: Dave-S
Views: 0
Replies: 16
Today 02:00
Forum: New devices and techniques
Starter: normnet
Views: 0
Replies: 1
Go to last post By: John Drew
Today 00:04
Forum: The Lounge
Starter: fanie
Views: 0
Replies: 14
Yesterday 17:34
Forum: Proton 24
Starter: johngb
Views: 0
Replies: 5
+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: code execution real time36 days old

  1. #1
    Junior Member vice's Avatar
    Join Date
    May 2013
    Posts
    4
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    0

    0 Not allowed!

    Default code execution real time

    Hello guys,
    I would like to ask is there a plug in or a way to see what is the real time for executing the code or a section of the code in the Compiler while writing the code?!
    Thank you in advance...

  2. #2
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,031
    Thumbs Up
    Received: 84
    Given: 16
    Total Downloaded
    923.15 MB

    0 Not allowed!

    Default Re: code execution real time

    You'll have to do that using a simulator with timing option.
    Try this link.

  3. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,255
    Thumbs Up
    Received: 47
    Given: 112
    Total Downloaded
    2.36 GB

    0 Not allowed!

    Default Re: code execution real time

    How about using a spare GPIO and a cheapo logic analyser. Set the bit when you want to start the measurement, clear it when you want to end, trigger the LA off that bit and bob's your uncle. My Saleae will sample at 24Mb/s, I can't do the math but you should be able to get results well within 1 instruction.
    George

  4. #4
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,031
    Thumbs Up
    Received: 84
    Given: 16
    Total Downloaded
    923.15 MB

    0 Not allowed!

    Default Re: code execution real time

    But then you're not really sure about exactly where you are in your program. Besides, MPSim will allow you to set breakpoints, contains a Stopwatch and includes a Stimulus which allows you to change the state of the pins. Besides, MPLab is free and not everybody owns a Logic Analyzer.
    And, as requested by vice, MPLab allows you to measure specific parts of the program. Now try that with an LA.

  5. #5
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,255
    Thumbs Up
    Received: 47
    Given: 112
    Total Downloaded
    2.36 GB

    0 Not allowed!

    Default Re: code execution real time

    But then you're not really sure about exactly where you are in your program
    I don't know what this means

    Besides, MPSim will allow you to set breakpoints
    Vice, didn't mention breakpoints

    Besides, MPLab is free
    Yes it's free and many would agree there is a good reason for that. I sure you would agree that the learning curve for MPLab (lets not even go there with MPLabX) is pretty steep. IMO it's probably the most inaccessible program I've tried to used. Not only that but it's deprecated.

    not everybody owns a Logic Analyzer
    You can get a Saleae clone for £4.65 (with free postage) on eBay and before anybody decides to take the high road, Saleae no longer sell that model so you couldn't buy one if you wanted to.

    And, as requested by vice, MPLab allows you to measure specific parts of the program.
    Personally I could live with recompiling to test different sections, if I got a real world result, it cost less than £5 and I didn't have to do battle with MPLab (but thats just me, no flames please). I'm sure there are many adherents to MPLab, but ask yourself realistically how long did it take you to learn it?

    in the Compiler while writing the code
    Actually neither of us addressed the last part of the original post. If there were no external stimuli I guess it's technically possible but I don't think either Proton or any plug in does this. Of course it can't be that difficult to do it manually, after all there is a lot less variation in instruction time than say an Pentium, on a PIC it's either 1,2 or 3 cycles (I think, I may be wrong about that).
    George

  6. #6
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,031
    Thumbs Up
    Received: 84
    Given: 16
    Total Downloaded
    923.15 MB

    0 Not allowed!

    Default Re: code execution real time

    George,
    well he mentioned "the code or a section of the code", to me this looks very hard to do using an LA because you never know exactly at what point the program is. Of course toggling pins can be of help, but it means you'll need a big enought device to measure all sections you want to monitor.

    TS does not mention breakpoints because I think he has not been thinking of a simulator.

    I agree on the learning curve, but that's exactly why I wrote the article referred to in post #2 so you don't have to learn ALL about MPLab. BTW, I don't think working with the basic functions of the Simulator took me more than an hour, the Stimulus part took another hour.

    IMHO you're exaggerating a bit about the accesibility op MPLab. But the fact that it is deprecated does not mean it doesn't work anymore (My TV set is no longer in production but it still works fine). I fully agree with respect to MPLabX (I have it on my machine only for the device files of the devices not supported by MPLab).

    You are correct regarding not addressing determining execution times during programming. Frankly I think this can't be done. You are right about the number of cycles, but that would mean that a plugin has to know exactly what code will be generated, and then I don't even mention the instructions being generated by the compiler for all built-in commands and functions and the different levels of optimization. Although I have written a number of plugins I would not even begin to consider to build something like this.
    I think the best you can get is an approximation based on the .lst/.asm files, but then the code must have been compiled before you can do anything.

    But the bottomline is that I fail to understand what the added value of a tool like this would be. There's little you can tweak in Proton except from inserting assembler statements.
    Talk about learning curve (I started progamming in assembler, both 16F and 18F, and know how much time it costs to master that).

    harm
    Last edited by hadv215; 21st August 2017 at 23:11.

  7. #7
    Junior Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    34
    Thumbs Up
    Received: 4
    Given: 1
    Total Downloaded
    779.67 MB

    0 Not allowed!

    Default Re: code execution real time

    If I need to know the execution time of something I just look at the assembler and count the instructions. Most instructions are one cycle except those that jump which are two cycles and conditional jump instructions are two if they jump.
    Flosi Guğmundsson
    Reykjavík

  8. #8
    Developer Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,178
    Thumbs Up
    Received: 215
    Given: 77
    Total Downloaded
    1.50 GB

    0 Not allowed!

    Default Re: code execution real time

    As mentioned above. The best way to see timing of routines is in a simulator. Download the demo version of the Proteus simulator, and you'll see the times in the taskbar when breakpoints are added to the code.

    If the code is a bit too involved for a simulator, a simple way to calculate the timing between two points of a program is to use a timer peripheral, then convert cycles to microseconds. The program below shows how this can be done for any device that contains a Timer1 peripheral.

    Code:
    ' Calculate the timing between two point in a program
    '    
        Device = 18F452
        Declare Xtal = 20
        Declare Hserial_Baud = 9600
    
        Dim Commands_TimeUs As Word     ' Holds the time between start and stop of Timer1    
        Dim wTimer1 As TMR1L.Word       ' Create a 16-bit SFR of TMR1L\H
    $define _fOSC_ $eval (_xtal / 4)    ' Holds the actual cycle time of the device
        
    '---------------------------------------------------------------
    ' Reset and start Timer1
    '
    $define Timer1_Enable() '
        Clear wTimer1       '
        T1CON = 1
        
    '---------------------------------------------------------------
    ' Stop Timer1
    '    
    $define Timer1_Disable() T1CON = 0
    
    '---------------------------------------------------------------
    ' Calculate the time between Timer1 start and stop (in microseconds)
    '
    $define CycleTimeUs() wTimer1 / _fOSC_ 
    
    '---------------------------------------------------------------
    ' The main program counts the time between two points
    '
    Main:
    
        Timer1_Enable()                 ' Enable the Timer
    
        DelayUS200                     ' Create a delay so we can test the timing routines
    
        Timer1_Disable()                ' Stop the Timer
    
        Commands_TimeUs = CycleTimeUs() ' Get the time, in microseconds, between start and stop of Timer1 into variable Commands_TimeUs
        
        HRSOutLn "It Took: ", Dec Commands_TimeUs, " Microseconds"
    
        Stop
    To count the routines timings, add Timer1_Enable() and Timer1_Disable() between the points requiring timing. Then use CycleTimeUs() to calculate the time, in microseconds, between them. Make sure there is not too much time between the routines, otherwise 16-bit Timer1 will overflow, and give the wrong times.
    Last edited by Les; 22nd August 2017 at 08:27.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  9. #9
    Developer Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,178
    Thumbs Up
    Received: 215
    Given: 77
    Total Downloaded
    1.50 GB

    1 Not allowed!

    Default Realtime BASIC Code execution time calculation

    If the above mechanism for commands timing is to be used within many programs, an include file could easily be made. And, maybe, named "Command_Timing.inc"

    The include file would contain:
    Code:
    $ifndef _Command_Timing_
    $define _Command_Timing_
    
        Dim Commands_TimeUs As Word         ' Holds the time between start and stop of Timer1   
        Dim Timing_wTimer1 As TMR1L.Word    ' Create a 16-bit SFR of TMR1L\H
        
    $define _fOSC_ $eval (_xtal / 4)        ' Holds the actual cycle time of the device
        
    '---------------------------------------------------------------
    ' Reset and start Timer1
    '
    $define Timing_Enable()   '
        Clear Timing_wTimer1  '
        T1CON = 1
        
    '---------------------------------------------------------------
    ' Stop Timer1
    '    
    $define Timing_Disable() T1CON = 0
    
    '---------------------------------------------------------------
    ' Calculate the time between Timer1 start and stop(in microseconds)
    '
    $define CommandTimeUs() Timing_wTimer1 / _fOSC_
    
    $endif  ' _Command_Timing_
    And a demo using the include file is:
    Code:
    ' Calculate the timing between two points in a program
    '    
        Device = 18F452
        Declare Xtal = 20
      
        Declare Hserial_Baud = 9600
      
        Include "Command_Timing.inc"      ' Load the command timing routines into the program
    
    '---------------------------------------------------------------
    ' The main program counts the time between two points
    '
    Main:
        Timing_Enable()                   ' Enable the Timer
    
        DelayUS 200                       ' Create a delay so we can test the timing routines
    
        Timing_Disable()                  ' Stop the Timer
    
        Commands_TimeUs = CommandTimeUs() ' Calculate the time between start and stop of Timer1 (in microseconds)
        HRSOutLn "It Took: ", Dec Commands_TimeUs, " Microseconds"  ' Display the time on a serial terminal
    Notice the name changes of the defines, so it is more clear what is happening.
    Last edited by Les; 22nd August 2017 at 09:03.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  10. #10
    Junior Member Dompie's Avatar
    Join Date
    Apr 2012
    Posts
    23
    Thumbs Up
    Received: 3
    Given: 7
    Total Downloaded
    891.68 MB

    0 Not allowed!

    Default Re: code execution real time

    Thanks Les this is an awfull simple solution!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. HRSout Even or Odd at execution time
    By ricardourio in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 26th September 2016, 17:34
  2. [SOLVED !] Enabling IOCB register stops code execution
    By VaGyver in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 30th April 2015, 11:31
  3. Real time code with battery backed-up PIC
    By shantanu@india in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 28th April 2010, 11:16
  4. Real Time Clock
    By belsenthegreat in forum The Lounge
    Replies: 5
    Last Post: 27th February 2007, 22:14

Members who have read this thread since 13th September 2017, 07:19 : 1

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts