Need Help on Slow Execution Times

I’m using the STM32F405 microcontroller on the cerbuino bee board which has a CPU clock speed of 168MHz. I checked the time it takes to execute two lines of code:
long TIME_0 = Utility.GetMachineTime().Ticks;
long TIME_1 = Utility.GetMachineTime().Ticks;
It takes 210 microseconds to execute these two lines of code!
That’s over 35000 clock cycles!
Why is this microcontroller so slow?
Please help.

How are you converting between ticks, microseconds and clock cycles?

This is a complex, interpreted and managed system. is not fair to determine speed using simple statements like your example our by blinking an led. A fair test would be to run a complete application and things well be much better.

Hi Gus,
Yes I’m running a complete application that is time sensitive. I’ve found that it wasn’t running fast enough. This is what led me to investigate command execution times. I had a math error in my calculation. 210 ticks to execute the two lines of code in my last example. 210 ticks ÷ 10000 ticks per millisecond = 0.021millisecond. 0.021 milliseconds × 0.001 × 168MHz = 3528 clock cycles. Why does the simple code in my last example need 3528 CPU clock cycles to execute? Also, my main question would be is there anything I can do to speed up execution times?
Thanks

it’s not a compiled application. Speed sensitive in netmf means you want to look at GHI’s RLP additions. But Netmf is not a real time system

Hi Brett,
Reading about RLP looks like it may help speed up my application significantly. The RLP documentation is a little too high level for a first time RLP user like me. For example, under the “Compiling” section of the RLP documentation it says to run build.bat. When I double click build.bat, it says make: no target specified and no makefile found. What target does it need? How do I supply a makefile? How do I point it to use my RLP function? Can you please point me to a more step by step example on how to use RLP?
Thanks

Take a look on codeshare, there’s a good starter someone wrote that will be perfect for this (I hope - I haven’t used it)

https://www.ghielectronics.com/community/codeshare/entry/917

I have used em:blocks as suggested in this and the GHI suggested Yagarto tool chain. I can say that using Em:Blocks and Simons templates make RLP really easy.

Hi Brett,
Just completed a simple for loop in RLP and compared it to a for loop not using RLP and found that when using RLP the code executes a hell of a lot faster. This should fix the speed issues in the original application nicely. Thanks for your help!

Hi Hagster,
Yes, EM:blocks is the way to go. I’m using it. Is there an option to use c# instead of c in EM:blocks?
Thanks

@ tdcooper33 - no you cant use c# as that needs a dot net framework underneath. Using RLP you are doing proper ‘bare metal’ coding onto the chip. Simple things will compile to very few cpu instructions, so an addition for example could take just one or two clock cycles.

If you mean c++ then yes I think this is ok. Personally I try and keep my RLP functions as simple as possible and stick with basic c.

Actually, you could (theoretically) do C# without any .NET framework underneath. The C# language is typically (only?) used with the .NET framework, but the language itself doesn’t require it. Implement a C# frontend to GCC, and you’d be there. You wouldn’t have all the class library, or the GC, or any of that, but none of that is the C# language, it’s the .NET runtime.

By this I guess you would end up in an C++ clone. :think:

Here is an excellent example, a PNG file decoder viewer
https://www.ghielectronics.com/community/codeshare/entry/999

No cpp in rlp. It is loadable procedures, not projects and classes :slight_smile:

Indeed, but C# is what C++ should have been from the beginning :slight_smile:

Thanks Guys,
I think I’ll stay with C++ for now.