Arduino
Jump to navigation
Jump to search
Arduino Due
Arduino due uses 32bit ARM Cortex M3 processor, 84 MHz
Speed
digitalWrite(pin #, HIGH/LOW) is much slower compared to direct register programming. I compared behaviour of both functions separately. The first option was to look only on digitalWrite:
digitalWrite(pin#, HIGH); delayMicroseconds(1); digitalWrite(pin#, HIGH); delayMicroseconds(1);
Secondly we looked on bare "C" code, and as it can be seen on a picture pulses follow 1 us without any delay, on the opposite the first signal is longer than it supposed to be around 3 us. Here is small program to compare speed of both functions.
#define LEDBIT (1<<21)
void setup()
{
pinMode(52, OUTPUT);
pinMode(50, OUTPUT);
PIOB->PIO_OWER |= LEDBIT; // Enabled direct writing to ODSR
Serial.begin(9600);
}
void loop()
{
while(1)
{
digitalWrite(50, HIGH);
PIOB->PIO_ODSR = LEDBIT; // turn the LED on (HIGH is the voltage level)
delayMicroseconds(1);
PIOB->PIO_ODSR = 0; // turn the LED off by making the voltage LOW
digitalWrite(50, LOW); // slower, although more scalable function
delayMicroseconds(1);
}
}
C code (Arduino due)
void setup() {
pinMode(36, OUTPUT);
PIOC->PIO_OWER |= (1<<4);
}
void loop(){
while(1){
PIOC->PIO_SODR = (1<<4); //makes the pin HIGH
PIOC->PIO_CODR = (1<<4); // makes the pin LOW
delayMicroseconds(1);
}
}
Gives 20-30ns.
Pin assignment:
Digital analog converter
I did DAC on 2 devices: Arduino nano +