Shop OBEX P1 Docs P2 Docs Learn Events
Simple Tools Toggle pin overhead — Parallax Forums

Simple Tools Toggle pin overhead

tdlivingstdlivings Posts: 437
edited 2013-05-20 21:31 in Propeller 1
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.
/*
  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
800 x 503 - 22K
800 x 503 - 22K

Comments

  • SRLMSRLM Posts: 5,045
    edited 2013-05-20 18:19
    Interesting. I suspect that the problem is because it's not inlined. The March 12, 2012 version of Pin.h from the PropGCC repository (link) has a header file that inlines everything. The next version pin.h (notice the lower case) doesn't have inline anymore (link).

    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.
  • jazzedjazzed Posts: 11,803
    edited 2013-05-20 19:11
    You can look at the generated asm code in simpleide by right-clicking a .c file in the project manager.
  • edited 2013-05-20 20:10
    You can take a look at the high function code in SimpleIDE by opening ...SimpleIDE\Learn\Simple Libraries\Utility\libsimpletools\libsimpletools.side. Then, in Simple View, click the bottom-left Show Project Manager button (if it isn't already visible along the left). Then, click source/high.c. You'll see that the code looks like this:
    #include "simpletools.h"                      // simpletools function prototypes
    
    void high(int pin)                            // high function definition
    {
      int mask = 1 << pin;                        // Set up mask
      OUTA |= mask;                               // Bitwise OR w/ OUTA & DIRA
      DIRA |= mask;
    }
    

    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.
  • tdlivingstdlivings Posts: 437
    edited 2013-05-20 21:06
    @Andy
    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
  • edited 2013-05-20 21:19
    @tdlivings
    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.
  • edited 2013-05-20 21:31
    Woops, I forgot to mention, the simpletools library still has some good performance benefits. Try this. It'll supply a high signal that lasts 1 us.
    low(15);
    pulse_out(15, 1);  
    


    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.
    set_io_dt(1);
    low(15);
    pulse_out(15, 1);  
    

    For more info in SimpleIDE, click Help and select Simple Library Reference. Then, click the link to libsimpletools.

    Andy
Sign In or Register to comment.