Go Down

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

aleandrogreete

This is extremely interesting, any improvements?

fat16lib

I can't improve the speed since functions like pin.high() and pin.low() compile to a single sbi or cbi instruction for low address I/O ports.  All ports on the 328 and ports A-G on the Mega are low address.  These instructions execute in 2 cycles or 125 ns on a 16 MHz cpu.

I have added software SPI which runs at about 2 MHz.  This library supports all SPI modes for MSB first.  It would be easy to add an option for LSB first.

I have not posted the latest version as a standalone library.  The latest version of DigitalPin with SoftSPI is used in the new 20120719 version of SdFat.  The files DigitalPin.h and SoftSPI.h are in the SdFat/utility folder and SdFat is here http://code.google.com/p/sdfatlib/downloads/list.

I have also written a software I2C library based on the DigitalPin library that runs at 400 kHz.  I plan to post this I2C library soon.

aleandrogreete

Quote
I can't improve the speed since functions like pin.high() and pin.low() compile to a single sbi or cbi instruction for low address I/O ports.  All ports on the 328 and ports A-G on the Mega are low address.  These instructions execute in 2 cycles or 125 ns on a 16 MHz cpu....


Btw this is a great result! fastDigitalWrite it's still one of the most used library because the original digitalWrite it's silly slow for many applications but the development it's stuck at 2010 and not provide any support for new micros and with the new pin management of arduino I dubt it will be useful as in the past.
Man, you made a great work! I know that direct port manipulation it's easier but the beauty of change processor and reuse the libraries for experiments without spend hours around PORTwhatever it's a dream!
I will check how you used in your sdfatlib, I'm planning to apply to liquidCrystal lib (I hope will not a nightmare...) and was really great you added any unsupported processor.

raphendyr

Oh. You had same problem as I do. Arduino is slow... Well I had another problem. I can't create easy libraries with bare avr c. So I started project to overcome this problem.

As a result I have very nice implementation for digital pins. That is only thing really working yet. Timers and analogRead is next.

Wanted to let you know what I have found out, so here is the project: https://github.com/raphendyr/yaal

pYro_65

#29
Nov 01, 2012, 11:59 am Last Edit: Nov 01, 2012, 12:07 pm by pYro_65 Reason: 1

Oh. You had same problem as I do. Arduino is slow... Well I had another problem. I can't create easy libraries with bare avr c. So I started project to overcome this problem.

As a result I have very nice implementation for digital pins. That is only thing really working yet. Timers and analogRead is next.

Wanted to let you know what I have found out, so here is the project: https://github.com/raphendyr/yaal


Hi, had a look at your library. Seems you are doing similar things to the ideas I'm implementing in my own library. I also noticed you are using a very basic version of my AtomicBlock library. I'm about to release a new version compatible with AVR, AVR32, PIC32, ARM Cortex M/R  if you are interested.

Go Up