Hi All,
I'm new to Teensy/Arduino and definitely new to ARM assembly.
I have managed to create a program that reads digital pin 16 on a Teensy 3.1 n number of times.
I'm using the Arduino IDE with all the Teensy stuff installed.
My code runs fine, but I would like to know if it can be made faster, specifically, this loop:
From my calculations, it's running in 7 clicks(per loop), does anyone see how this could be reduced.
Even 1 clock tick would be great. Can the indexing mode of the store instruction somehow also be used as the loop counter? In other words, is there a mode of the strb.w instruction that would allow a conditional branch once the index got to 1000? (Thereby getting rid of the need for the subs r1, #1 instruction)
Here's the whole enchalada:
Thanks for any help
Louie G
I'm new to Teensy/Arduino and definitely new to ARM assembly.
I have managed to create a program that reads digital pin 16 on a Teensy 3.1 n number of times.
I'm using the Arduino IDE with all the Teensy stuff installed.
My code runs fine, but I would like to know if it can be made faster, specifically, this loop:
Code:
606: f44f 717a mov.w r1, #1000 ; 0x3e8
60a: 4b06 ldr r3, [pc, #24] ; (624 <loop1+0x16>) //load pin16 address
60c: 4c06 ldr r4, [pc, #24] ; (628 <loop1+0x1a>) //load address of data array
0000060e <loop1>:
60e: 681a ldr r2, [r3, #0] // read pin
610: f804 2f01 strb.w r2, [r4, #1]! //store data and index the pointer
614: 3901 subs r1, #1 //dec
616: d1fa bne.n 60e <loop1>
From my calculations, it's running in 7 clicks(per loop), does anyone see how this could be reduced.
Even 1 clock tick would be great. Can the indexing mode of the store instruction somehow also be used as the loop counter? In other words, is there a mode of the strb.w instruction that would allow a conditional branch once the index got to 1000? (Thereby getting rid of the need for the subs r1, #1 instruction)
Here's the whole enchalada:
Code:
#define HWSERIAL Serial1
int sensorPin = 16; // select the input pin
int sensorValue = 0; // variable to store the value
int rcount=0;
const int tmax=2000;
unsigned long mstart;
unsigned long mstop;
byte data[5000];
int batchcount=1;
int dmax=10;
int dcnt=0;
int i;
void setup() {
HWSERIAL.begin(115200);
mstart=micros();
pinMode(sensorPin,INPUT);
}
void loop() {
ReadOnTrigger1();
}
void ReadOnTrigger1(){
dcnt=dmax;
do {
if (digitalReadFast(sensorPin)>0) { //wait for pin to go low for dmax ticks
dcnt--;
}
else {
dcnt=dmax; //pin went high, reset count
}
}
while (dcnt>0);
FastRead();
SendData();
}
void SendData(){
HWSERIAL.print("Batch:");
HWSERIAL.println(batchcount);
HWSERIAL.print("Start Clock:");
HWSERIAL.println(mstart);
HWSERIAL.print(" End Clock:");
HWSERIAL.println(mstop);
for (int i=1;i<=tmax;i++){
HWSERIAL.print(i);
HWSERIAL.print(", ");
HWSERIAL.println(data[i]);
}
batchcount++;
HWSERIAL.println("ENDDATA");
HWSERIAL.flush();
delay(250);
}
void FastRead(){
data[1]=digitalReadFast(16);
mstart=micros();
asm volatile(
"mov r1, 1000\n\t"
"ldr r3, [pc, #24]\n\t" //address of pin 16
"ldr r4, [pc, #24]\n\t" //address of data[]
"loop1:"
"ldr r2, [r3, #0]\n\t" //read pin 16
"strb r2, [r4, #1]!\n\t" //store in data[]
"subs r1,1 \n\t" //dec
"bne loop1 \n\t"
:::
"r1","r2","r3","r4"
);
mstop=micros();
}
Thanks for any help
Louie G
Last edited: