[SOLVED !] code execution real time


Closed Thread
Results 1 to 15 of 15

Thread: code execution real time1124 days old

  1. #1
    vice
    Guest vice's Avatar

    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. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    hadv215
    Guest hadv215's Avatar

    0 Not allowed!

    Default Re: code execution real time

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

  4. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,374
    Thumbs Up
    Received: 87
    Given: 183
    Total Downloaded
    5.30 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.

  6. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    hadv215
    Guest hadv215's Avatar

    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.

  8. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,374
    Thumbs Up
    Received: 87
    Given: 183
    Total Downloaded
    5.30 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.

  10. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    hadv215
    Guest hadv215's Avatar

    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.

  12. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Member flosigud's Avatar
    Join Date
    Oct 2013
    Posts
    208
    Thumbs Up
    Received: 13
    Given: 15
    Total Downloaded
    3.27 GB

    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

  14. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,701
    Thumbs Up
    Received: 361
    Given: 173
    Total Downloaded
    2.08 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 top204; 22nd August 2017 at 08:27.

  16. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,701
    Thumbs Up
    Received: 361
    Given: 173
    Total Downloaded
    2.08 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 top204; 22nd August 2017 at 09:03.

  18. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Member Dompie's Avatar
    Join Date
    Apr 2012
    Posts
    159
    Thumbs Up
    Received: 19
    Given: 15
    Total Downloaded
    5.19 GB

    0 Not allowed!

    Default Re: code execution real time

    Thanks Les this is an awfull simple solution!

  20. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  21. #11
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,701
    Thumbs Up
    Received: 361
    Given: 173
    Total Downloaded
    2.08 GB

    1 Not allowed!

    Default Re: code execution real time

    Thanks Dompie. That's because the compiler is both powerful, and simple to use. Blowing my own trumpet there. LOL

  22. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  23. #12
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,966
    Thumbs Up
    Received: 96
    Given: 34
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: code execution real time

    G'day Les,
    That's a really neat include. This question has been discussed many times. Would you please put it in the WIKI? It will be easier to find in future. I'd be happy to do it for you but you should appear as the author and if you need to edit it in future.
    John

  24. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  25. #13
    hadv215
    Guest hadv215's Avatar

    0 Not allowed!

    Default Re: code execution real time

    IMHO this 'solution' leaves much to be desired.
    First it's nothing new, debugging by means of the UART is pretty common practice. (although this isn't a disadvantage)
    Second is that it requires a dedicated timer which may be unavailable.
    Third is that the time to be measured is limited.
    Fourth is that the solution itself takes time to execute, this means that if you would want a section to be measured inside another section to be monitord you'll have to compensate.
    Fifth it is that it is unpredictable if the part being measured will not be executed exactly the same way every time. E.g. parsing a string: the number of iterations isn't fixed but depends on the size of the string to be parsed.
    Fifth is that it is not what TS asked: available during programming. (although I think there is no way to solve this).

    Trust me, using a simulator is the most flexible solution and does not require extra resources or recompiling.
    One of the nicest features the fact that you can modify the values of variables during simulation.

  26. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  27. #14
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,701
    Thumbs Up
    Received: 361
    Given: 173
    Total Downloaded
    2.08 GB

    0 Not allowed!

    Default Re: code execution real time

    The one big problem with simulations is if the microcontroller is interfacing with peripherals, which is usually the case. It is usually required that the peripheral answers the microcontroller, and if there is no answer because the peripheral cannot be simulated, then what? Or the peripheral is giving constant values to the microcontroller, and the program depends on what is received. If none of these occur, it knocks off the program into something it would not normally do, so timings are then irrelevant! Using an ICD or ICE environment would be better, but the ICD on PIC microcontrollers is dreadful, and ICE costs a fortune!

    Unfortunately, we live in a simulation world, and this brings a huge amount of problems in itself, as not a single simulator offers real world simulations, and they actually introduce problems that do not exist in the real world. Or worse still, they do not simulate problems that DO happen in the real world. You cannot beat building a circuit and testing with either code, or a logic analyser, or an oscilloscope. Using the USART is one of my favourite debugging methods, but it will not give accurate timings on its own, it will simply give locations or variable contents etc. Don't get me wrong... for testing simple code, a simulator is great, but for full programs that have to operate in the real world, they are absolutely dreadful, and simply do not work! IMO, they are still just elaborate toys.

    Using any of the 16-bit timers is possible with the above routines, or 32-bit timers if using some of the newer devices, or all the PIC24 or dsPIC devices, so timing durations could be huge. It's also possible with a very small modification to joint two 16-bit timers together, with an overflow. Just choose the timer, or timers, that your program is not using, there's plenty of them, and it is rare that all are being used in a single program. The above routines take 2 cycles and 4 cycles each, or 1 cycle and 2 cycles for PIC24 devices, so the programming overhead is very minimal, and it gives a "real" time result, even if interfacing with peripherals.
    Last edited by top204; 23rd August 2017 at 21:07.

  28. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  29. #15
    hadv215
    Guest hadv215's Avatar

    0 Not allowed!

    Default Re: code execution real time

    I agree that peripherals will lead to headaches in simulators. Testing that should be left to scopes and log analysers.
    But you can simulate bytes coming from the UARTs and buttonpresses, but an ADC measurement or a USB signal is out of the question.

    As always it boils down to chosing the right tool for the problem at hand.

  30. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

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. Enabling IOCB register stops code execution
    By VaGyver in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 30th April 2015, 11:31
  3. [SOLVED !] real time clocks
    By ADLIN SYSTEMS in forum The Lounge
    Replies: 4
    Last Post: 7th June 2010, 19:22
  4. Replies: 3
    Last Post: 28th April 2010, 11:16
  5. Real Time Clock
    By belsenthegreat in forum The Lounge
    Replies: 5
    Last Post: 27th February 2007, 22:14

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