Go Down

Topic: Fast alternative to digitalRead/digitalWrite (Read 8 times) previous topic - next topic

extent

I was very interested in this because I'm writing for dedicated hardware with my LCD data pins contiguous and on the same port.  With a simple benchmark just converting the stock LiquidCrystal library to DigitalPin and nothing else I saw a 32% speed up.  By changing the write4bits method to shift the nibble directly into the port I only saw an additional 1.1% speed increase from the pure DigitalPin version.

Unless I totally mangled my direct port code, which is a very real possibility
Code: [Select]
PORTC = (PORTC & (~B00111100)) | ((value << 2) & B00111100);// D0-3 on A2-A5

When I removed the section setting the pins to output in each write the difference between digitalPin and direct port was only .06%

Is that basically what you're getting at or did I miss the point entirely?

fat16lib

You got the point exactly. 

Often what looks great in C/C++ code doesn't optimize well for I/O on AVR chips. 

avr-gcc seems to really understand single bit operations.  Sometimes it does really stupid things with more complex cases.

I am now doing a very general bit-bang SPI implementation for all SPI modes.  I get a factor of four speedup by simple changes that make the compile so what I expect.

pYro_65

@fat16lib, I have recently converted my older code using FastDigitalIO to your newer DigitalPin library.
The compilation size grew by two bytes, I cannot find the reason why either ( 2 bytes is nothing anyway ).
Also I noticed the 'mode()' function is gone, Was easier to implement in some circumstances.

fat16lib

I will be posting another version of digitalRead/digitalWrite.  The current version is not working well in a general implementation of software SPI master.  I am also using it for a fast software I2C master. 

cyclegadget


  I tested this library on my Uno against using digital.Write and I got a nice improvement in speed. I also thought your library was easy to use once I caught on to terms needed to activate the pins.

Can this library be used with any Arduino compatible board or do the pins have to be defined in the library first?

To narrow my question down, I would like to use it on a Leonardo board and "here comes a dream", try to use the library on a Maple.

Great work, thank you for your efforts!

Go Up