About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Search
Register or Sign In
Forum

IO Pi Performance

1427 Views - Created 30/12/2016

30/12/2016

Posted by:
voodoo_dev

Users Avatar

Recently received my IO Pi Plus, all setup with no issues at all on RPi 3 running Jessie.  Thought I'd test the performance to see the maximum speed I can toggle an IO line.  Using the provided tutorials, I removed the 'sleep' calls and measured the IO line with an oscilloscope.  I tested with Python 2 (tutorial1) and C code (demo-iopiwrite).  To my surprise, Python performed better giving approx 1KHz toggle frequency.  C code only gave around 400Hz.

Now, given that I want to use C code, this is problematic for me.  Any reason why the C code performance is so poor?

30/12/2016

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

The main reason for the decreased performance with the C version of the IO Pi library is due to the way the write_pin function works.

 With the python library each instance of the iopi is stored as an object which contains variables for the status of the pins on the IO Pi.  When you write to a single pin the python library updates the variable and then writes that to the IO Pi.

As C is not an object orientated language we wrote the C version of the library so the write_pin function reads the values from the port before updating a single bit and writing the value back to the port.  This is more reliable if you have more than one program writing to the IO Pi as it will always check the status of the port before updating it.  The downside is it requires two I2C packets to be sent to the IO Pi where as the python library only needs one which is why the C library is half the speed of the python library.

One way of improving the performance would be to use the write_port function instead of write_pin.  write_port updates all 8 pins on the port at the same time so it does not need to read the status of the pins first.  This means it only has to send a single I2C packet to the IO Pi so performace should be the same as the python version.  

AB Electronics UK Tech Support

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.