hello
i'm working with T3.5
i need my code to be faster and i was wondering if there are tools in the arduino\teensy that are ment for inspecting code for that manner . right now i'm using micros() and than i print the result in order to see how fast is a certain loop but i figured there must be something more accurate since printing and micros() takes time and all , not to mention i care about nanosecs so micros() is not good enough . in addition ,is there something like breakpoint ? i couldn't find info on google .
in another subject , i saw this link it has a lot of clear info about port manipulation
http://little-scale.blogspot.co.il/2013/05/teensy-basics-5-port-manipulation.html
but it didn't work out , perhaps because its not the same teensy ?
i tried to adjust pins with
but i got an error :
'DDRD' does not name a type
another question i had - someone told me to discard the digitalread/writefast and use port manipulation even when i need to set one pin only . is it actually faster ? how should i do it , say i want to turn pin 34 HIGH , which is pin 25 in port E . so i declare port E as
?
the full code :
i'm working with T3.5
i need my code to be faster and i was wondering if there are tools in the arduino\teensy that are ment for inspecting code for that manner . right now i'm using micros() and than i print the result in order to see how fast is a certain loop but i figured there must be something more accurate since printing and micros() takes time and all , not to mention i care about nanosecs so micros() is not good enough . in addition ,is there something like breakpoint ? i couldn't find info on google .
in another subject , i saw this link it has a lot of clear info about port manipulation
http://little-scale.blogspot.co.il/2013/05/teensy-basics-5-port-manipulation.html
but it didn't work out , perhaps because its not the same teensy ?
i tried to adjust pins with
Code:
DDRD = 0xFF;
'DDRD' does not name a type
another question i had - someone told me to discard the digitalread/writefast and use port manipulation even when i need to set one pin only . is it actually faster ? how should i do it , say i want to turn pin 34 HIGH , which is pin 25 in port E . so i declare port E as
Code:
DDRE = 0x1000000;
the full code :
Code:
// PTA (12 13) = [3 4] // ready signal and XS2
// PTB (0 1 2 3) = [16 17 19 18] // For address bits
// PTC (0 1 2 3 4 5 6 7 8 9 10 11) = [15 22 23 9 10 13 11 12 35 36 37 38] // For digital inputs from NI cards
// PTD (0 1 2 3 4 5 6 7 ) = [2 14 7 8 6 20 21 5] // For digital output to marker
// PTE (25) = [34] // for digital output to reward
byte inputPins[] = {3, 4, 16, 17, 19, 18, 15, 22, 23, 9, 10, 13, 11, 12, 35, 36, 37, 38};
byte outputPIns[] = {2, 14, 7, 8, 6, 20, 21, 5, 34};
int k;// set to 1 when marker activated , and to 0 when deactivated
unsigned long rewardON;
unsigned long T1;
elapsedMillis rewardTime;
elapsedMicros markerTime;
IntervalTimer myTimerOne;
IntervalTimer myTimerTwo;
void reward(void) {
if (!digitalReadFast(3) && ((GPIOB_PDIR & 0xF) == 4)){// reward command received
rewardON = GPIOC_PDIR;
//Serial.println("rewardIFtest - GPIOC_PDIR-");
//Serial.println(GPIOC_PDIR);
//Serial.println(rewardON);
//GPIOE_PDOR = 0x1;//reward
rewardTime = 0;//start counting until stop
}
}
void marker(void) {
if (!digitalReadFast(3) && ((GPIOB_PDIR & 0xF) == 1)){//marker command received
//Serial.println("markerIFtest - GPIOC_PDIR-");
//Serial.println(GPIOC_PDIR,BIN);
GPIOD_PDOR= (GPIOC_PDIR >>1) & 0x7FF;
k=1;
//Serial.println("GPIOD_PDOR-");
//Serial.println(GPIOD_PDOR,BIN);
markerTime = 0;//start counting until stop
}
}
void setup() {
//Serial.begin(9600); while(!Serial);
//pinMode(34,OUTPUT);same as DDR
//DDRE = 0x1000000;
//for (int pinnum = 0; pinnum < 18; pinnum++) {
// pinMode(inputPins[pinnum], INPUT_PULLDOWN);
//pinMode(inputPins[pinnum], INPUT);
DDRC = 0x0;
}
//for (int pinnum = 0; pinnum < 9; pinnum++) {
// pinMode(outputPIns[pinnum], OUTPUT);
DDRD = 0xFF;
}
myTimerOne.priority(0);
myTimerOne.begin(reward,100);
myTimerTwo.priority(1);
myTimerTwo.begin(marker,100);
}
void loop() {
//T1=micros();
if ( GPIOE_PDOR == 0x1 && rewardTime > rewardON) {//if the reward output is being sent for the input time
GPIOE_PDOR = 0x0;//stop reward
//Serial.println("looprewardtest TIME");
//Serial.println(rewardTime);
//Serial.println(rewardON);
}
if (k == 1 && markerTime > 25){//if the marker message is being sent for 25us (maybe the interval is too long\short for some devices)
GPIOD_PDOR = 0x00;//stop marker
k=0;
//Serial.println("loopmarkertest - markerTIME ");
//Serial.println(markerTime);
//Serial.print(micros()-T1);
//delay(1000);
}
}