Simple Tools Toggle pin overhead
tdlivings
Posts: 437
As part of my exercise in toggling pins using the Simple Tools functions high(pin) low(pin)
I looked at what pulse width that produced . I also looked at the source for those functions
and wondered what the overhead for making a call to the code inside, which uses Propeller.h
functions.
I was surprised that it is as large as it is, like an order of 5 times for the overhead of two subroutine calls
The commented out code runs and produces the short pulse using basiclly the same code
in the functions high() and low(). Then I reran it with only the high low code and got the
longer pulse.
It is not the end of the world and I post only in case this raises a red flag to the team as not right.
Tom
I looked at what pulse width that produced . I also looked at the source for those functions
and wondered what the overhead for making a call to the code inside, which uses Propeller.h
functions.
I was surprised that it is as large as it is, like an order of 5 times for the overhead of two subroutine calls
The commented out code runs and produces the short pulse using basiclly the same code
in the functions high() and low(). Then I reran it with only the high low code and got the
longer pulse.
It is not the end of the world and I post only in case this raises a red flag to the team as not right.
/* Blank Simple Project.c Quick toggle test using Andy's high low code without the overhead */ #include "simpletools.h" // Include simple tools int main() // Main function { int scopepin = 15; // Add startup code here. /* int mask = 1 << scopepin; // Set the direction register for output DIRA |= mask; //Set the pin LOW OUTA &= ~mask; //Set the pin HIGH OUTA |= mask; //Set the pin LOW OUTA &= ~mask; */ high(scopepin); low(scopepin); while(1) // Repeat indefinitely { // Add main loop code here. } }
Tom
Comments
Although, I've heard that the "inline" keyword was just a suggestion to the compiler, and it may or may not inline. Likewise, even if it is not there the compiler may or may not inline. Maybe that's only within one compilation unit, however.
You can see what assembly code is generated with the -Wa,-alh,-L and -save-temps flags.
I'd prefer to avoid any optimizations on this function that might make it more difficult to read because I was saving it as a lesson on how the lower level code inside a library works.
The simpletools documentation introduces itself as "...convenience functions for a variety of microcontroller I/O, timing, conversion, and communication tasks." They are were designed with ease of use in mind first, understandability of the functions second, and performance third (though wherever it could reasonably be applied). We already have propeller.h on the other end of the spectrum, with performance as first priority, so that base is also covered.
Of course, the intent is also to have the community grow and improve these the Simple Libraries (keeping in mind the intent, existing tutorials, and style). We encourage anyone interested in participating to submit suggestions, or even modified and zipped libraries to editor@parallax.com.
No way when I posted the info did I mean you needed to rewrite simpletools and change the high() function.
I like the simpletools idea. The performance is fine for wiggling pins to interface to a sensor and using it that
way is a good way to teach sensor interfacing.
I only posted because it seemed much larger than I expected and thought it might be some feedback you
would like to know in case say the compiler or linker was left in debug mode generating a lot of extra code.
Tom
Yes, of course, it was definitely taken in the spirit that it was offered. Sorry for not acknowledging it in my first reply.
I was mainly trying to provide info for folks that might read this thread (54 views so far) to help make the intent behind the simple library code clear. I'm also hoping editor@parallax.com will get some offers to contribute libraries to the collection. With that in mind, I'm also trying to broadcast background information wherever possible so that volunteers can be more familiar before they start.
With a call to set_io_dt, you can really increase the performance by changing the duration parameter form 1 us increments to 12.5 ns increments. With that, here is code for a 12.5 ns pulse.
For more info in SimpleIDE, click Help and select Simple Library Reference. Then, click the link to libsimpletools.
Andy