Comments (8)
On paper it's a good idea, but the key is compatibility. I want MiniCore to be as close to the original source code in terms of performance, even if the original source code is unnecessary slow.
MicroCore have to be as efficient as possible to even fit a small program.
However if the shiftIn and shiftOut functions were rewritten in the original source code I'd definitly update it in the MiniCore source code as well.
from minicore.
I think you are mistaken. For example, Wiring's digitalWrite() is much faster than Arduino's, without any apparent compatibility problems. Even with the official Arduino, the speed of digital IO can vary significantly depending on the hardware (8/16Mhz), and the version of avr-gcc used by the core.
But it's your project, so you are free to keep it as slow and bloated as the original Arduino core.
from minicore.
You're probably right. I'll put it on my todo-list. I want to do some testing on it as well. I think I'll have to use digitalPinToPort in order to make it fast enough
from minicore.
I'd keep the digitalWrite calls in my latest version of shiftIn, and use the digitalWrite/pinWrite code from Wiring:
https://github.com/WiringProject/Wiring/blob/master/framework/cores/AVR8Bit/WDigital.h
Like MicroCore, Wiring's digitalWrite compiles to a single sbi or cbi instruction when it is used with constant parameters.
In case you didn't know, Arduino forked from Wiring, but didn't keep up with some of the improvements that were made after the fork. Here's the long version of the story:
https://arduinohistory.github.io/
from minicore.
So with the implementation if shiftIn with MicroCore it doesn't really matter if I use direct port manipulation or digitalRead/digitalWrite, since it all compiles down to a single ski instruction?
from minicore.
Yes. Here's the asm for shiftIn when compiled with MicroCore:
46: 88 e0 ldi r24, 0x08 ; 8
48: c0 e0 ldi r28, 0x00 ; 0
4a: c0 9a sbi 0x18, 0 ; 24
4c: cc 0f add r28, r28
4e: b4 99 sbic 0x16, 4 ; 22
50: c1 60 ori r28, 0x01 ; 1
52: c0 98 cbi 0x18, 0 ; 24
54: 81 50 subi r24, 0x01 ; 1
56: c9 f7 brne .-14 ; 0x4a <__SREG__+0xb>
The initial version that I wrote using PINB is slightly faster because 'PINB = data' compiles to an out instruction which takes 1 cycle, while sbi & cbi take two. With Arduino's digitalWrite (at least the last time I looked at it), the code compiles to over a dozen instructions.
Here's one (of many) examples of people that looked into the performance issue:
https://www.codeproject.com/Articles/732646/Fast-digital-I-O-for-Arduino
from minicore.
Thanks for the tip about using Wiring's code!
from minicore.
Here's a version of shiftOut I just whipped up that would work for both MiniCore and MicroCore. It's about half the speed of the optimized shiftOut I wrote for MicroCore, but on the plus side it compiles to one less instruction on MicroCore.
void shiftO(byte dataPin, byte clockPin, byte bitOrder, byte value){
byte i = 8;
do {
if ( bitOrder == MSBFIRST){
if(value & 0x80)
digitalWrite(dataPin, HIGH);
else
digitalWrite(dataPin, LOW);
value <<= 1;
}
else{
if(value & 0x01)
digitalWrite(dataPin, HIGH);
else
digitalWrite(dataPin, LOW);
value >>= 1;
}
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
} while(--i);
}
from minicore.
Related Issues (20)
- atmega328pb wrong fuse settings? HOT 39
- No separate SPDR0 SPDR1 for the ATMega328PB? HOT 2
- avrdude urclock_res_check() error: HOT 9
- Clock options for ATMega328P are ambiguous HOT 1
- Not able to burn bootloader to Atmega88PB HOT 6
- MCUSR always reports 0 at startup HOT 13
- [feature] New 9.216MHz to Supported clock frequency. HOT 1
- Optiboot backward compatibility HOT 6
- Syntax Error HOT 11
- Trying to enlarge pinout diagrams in README fails with 'Non-Image content-type returned' HOT 2
- MiniCore Burn Bootloader - Not Working on M3 MacBook Pro HOT 5
- Warnings with TimerInterrupt library
- is LGT8F328P supported ? HOT 1
- Fails to compile Strings declared empty on Atmega328PB HOT 3
- Internal Pull up error mega328 HOT 3
- Adding `-B 4` by default to `avrdude` HOT 2
- ATmega328PB and the PWM output PB1, PB2 and PB3 HOT 2
- burn bootloader to mega88 fail HOT 1
- Boot time atmega168pb HOT 2
- Uploading error : given error when upload to Arduino UNO r3 using mobile app Arduino studio on HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minicore.