Pages: [1] 2   Go Down
Author Topic: How do I figure out what the error codes mean?  (Read 622 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 I have a sketch roughly put together:
Code:
/* Finds time from TDC1, TDC4 and pulseStart. It's a finite state machine. Holds in a loop until the proper state occurs.
* First it looks for a LOW on the pulse detector to trigger an interrupt that logs the timing of the event. The INJECTORWAIT state isn't looking for a LOW on the pin.
* The interrupt does that. The INJECTORWAITT state is looking for data stored because the pin went LOW. Same with *the other 2 states The injector pulse comes before TDC1. How many degrees before top dead center BTDC is what we *are looking for */
#define INJECTORWAIT 0
#define TDCWAIT_1 1
#define TDCWAIT_2 2
#define AVERAGEWAIT

unsigned long tdcStartTime;
unsigned long tdcStartTime_1;
unsigned long tdcStartTime_2;
unsigned long injectorStartTime;
unsigned long Btdc;
unsigned long aveBtdc;
unsigned long oneRevTime;
unsigned long aveRevTime;
unsigned long btdcY;
unsigned long rpmX;

const int pulsePin = 2;
const int tdcPin = 3;
int count = 0;
byte state = INJECTORWAIT;

void setup() {
 Serial.begin(9600);
 pinMode(pulsePin, INPUT);
 pinMode(tdcPin, INPUT);
 while (digitalRead(tdcPin) == HIGH) { //wait here until we are at TDC (any TDC)
  }
 attachInterrupt(0,PulseIRPT,FALLING);  //enable interrupt attached to pin 2 pulse detector
 attachInterrupt(1,TdcIRPT,FALLING);    //enable interrupt attached to pin 3 flywheel laser sensor

 }
void loop () {
    Serial.print("DATA, TIME,,,");             // Opens PLX-DAQ data line
 void tdcIRPT() {                             // the interrupt routines
  tdcStartTime = micros();                
  }
 void pulseIRPT() {
  injectorStartTime = micros();
  }  
 while (state == INJECTORWAIT)  {
  if (injectorStartTime > 0 ) {
       state = TDCWAIT_1;
   }
   }
 while (state == TDCWAIT_1) {
  if (tdcStartTime > 0 ) {
      tdcStartTime_1 = tdcStartTime;      //here we stored the value from the tdcIRPT interrupt routine intdcStartTime_1
      tdcStartTime = 0;                   //set to 0 so the next state knows if it's been retriggered.
      state = TDCWAIT_2;
  }
  }
 while (state == TDCWAIT_2) {
  if (tdcStartTime > 0) {
        tdcStartTime_2 = tdcStartTime;    
      state = AVERAGEWAIT;
  }
  }
 while (state == AVERAGEWAIT) {                    // You now have the three times you need for all your calculations.
    Btdc = tdcStartTime_1 - injectorStartTime;        // BTDC in microseconds
  oneRevTime = tdcStartTime_2 - tdcStartTime_1;     // time for one revolution in microseconds
  injectorStartTime = 0;                            // gets zeroed every time
  tdcStartTime = 0;
  if (count < 16)  {
     aveRevTime = ((15 * aveRevTime) + oneRevTime)/ 16;                //a decaying average allows me to do this without an array
     aveBtdc =    ((15 * aveBtdc) +  Btdc) / 16;
     count++;
  }
  else {
      rpmX = (60000000 / aveRevTime);                                  //oodles of time so calculate RPM
      btdcY = ((aveBtdc) / ((oneRevTime) / 360));                      //don't waste the oodles
     Serial.print(btdcY);Serial.print(",");Serial.println(rpmX);      //Dumps the average results into excel columns D&E
     count = 0;                                                       // zeroing variables that get used for averaging
     state = INJECTORWAIT;                                           //sends it back to the beginning to wait for an injector pulse
  }
  }
 }
  // and around the loop() we go again.
}
 
 ///OOOOORRRRR should I do it this way?
        tdcStartTime_2 = tdcStartTime;
      //without the state=INJECTORWAIT here it should just go to the next line right?
  }
  }             // You now have the three times you need for all your calculations.
    Btdc = tdcStartTime_1 - injectorStartTime;        // BTDC in microseconds
  oneRevTime = tdcStartTime_2 - tdcStartTime_1;     // time for one revolution in microseconds
  injectorStartTime = 0;                            // gets zeroed every time
  tdcStartTime = 0;
  if (count < 16)  {
     aveRevTime = ((15 * aveRevTime) + oneRevTime)/ 16;   //a decaying average allows me to do this without an array
     aveBtdc =    ((15 * aveBtdc) +  Btdc) / 16;
     count++;
  }
  else {
      rpmX = (60000000 / aveRevTime);                                  //oodles of time so calculate RPM
      btdcY = ((aveBtdc) / ((oneRevTime) / 360));                      //don't waste the oodles
     Serial.print(btdcY);Serial.print(",");Serial.println(rpmX);      //Dumps the average results into excel columns D&E
     count = 0;                                                       // zeroing variables that get used for averaging
     state = INJECTORWAIT;
  }
//and aroound we go again  
 
 
I get a list of error codes that keep it from compiling.
 for example:
"diesel_interrupt_state.ino: In function 'void setup()':"
 I search for ino and get every post with arduino or in.
 I have no idea what ino means and search is no help.
 Other errors:
diesel_interrupt_state.ino: In function 'void setup()':
diesel_interrupt_state:31: error: 'PulseIRPT' was not declared in this scope
diesel_interrupt_state:32: error: 'TdcIRPT' was not declared in this scope
diesel_interrupt_state.ino: In function 'void loop()':
diesel_interrupt_state:37: error: a function-definition is not allowed here before '{' token
diesel_interrupt_state:40: error: a function-definition is not allowed here before '{' token
diesel_interrupt_state:58: error: expected primary-expression before ';' token
diesel_interrupt_state:61: error: expected primary-expression before ')' token
diesel_interrupt_state.ino: At global scope:
diesel_interrupt_state:81: error: expected declaration before '}' token
Just as difficult to search.

 diesel_interrupt_state is the title of the sketch.
 If I could work my way through them I'd find out where the highlight is on the others and know where the problem is but I can't even get past 'PulseIRPT'was not declared in this scope.
 Is there an easy way to figure out what the error codes mean?
« Last Edit: February 15, 2014, 10:16:39 pm by graphing » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 138
Posts: 5846
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have functions declared in a function. Move these out of the loop() function.
Code:
void tdcIRPT() {                             // the interrupt routines
  tdcStartTime = micros();                
  }
 void pulseIRPT() {
  injectorStartTime = micros();
  }  
Logged

Offline Offline
Faraday Member
**
Karma: 80
Posts: 3794
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The "ino" you're searching for is just the extension of your sketch file name. So this:

diesel_interrupt_state.ino: In function 'void setup()':
diesel_interrupt_state:31: error: 'PulseIRPT' was not declared in this scope


.... means that in the function void setup() of the file diesel_interrupt_state.ino, the error " 'PulseIRPT' was not declared in this scope" was found on line 31.

So look and see why setup() doesn't know about PulseIRTP, and as SurferTim pointed out, it's because you declared the interrupt handlers inside void() so only void() knows about them.
Logged

Although I answer in good faith, remember always: Your Mileage May Vary.
Get me on LinkedIn: za.linkedin.com/in/jimbrownza/

Saskatchewan, Canada
Offline Offline
Edison Member
*
Karma: 49
Posts: 1385
Coding Geezer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
void loop () {
    Serial.print("DATA, TIME,,,");             // Opens PLX-DAQ data line

No idea what "Opens PLX-DAQ data line" means, but you probably don't want to print the header every time you go through the loop. It will probbaly print a few hundred times between state changes.

Quote
Code:
     //without the state=INJECTORWAIT here it should just go to the next line right?

Not at all sure which statement you are referring to. You have placed some code after the TDCWAIT_2  loop.  Are you wanting to remove the statement setting INJECTORWAIT in the TDCWAIT_2 loop? If so, yes, it will just drop through into the next bit of code. That next bit of code, however, if it does not depend on a state that you set in TDCWAIT_2, will execute EVERY TIME through loop(), whether or not it has gathered all the data you are looking for.

I would either do as you have done; setting another state (you used AVERAGEWAIT for some unknown reason. You are not waiting for anything), or, alternatively, do your calculations within TDCWAIT_2. Better still, write a function that takes Btdc  pneRevTime, calculated in TDCWAIT_2, call it from within TDCWAIT_2, and in that function, do anthing you want with the data.. average if you want (no idea why you want to), display it, and so on.

« Last Edit: February 16, 2014, 04:59:40 pm by lar3ry » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help that cleared alot up for me.
 The numbers are code lines where the problem is,.. not a code for the type of mistake, doh.
 Also ino has nothing to do with describing the error.

 I tried moving the interrupt function into setup,.. that didn't work.
 So I tried moving it before setup, .. that didn't work either.
 After setup the same thing.

 I checked the referance page:
C:\Documents and Settings\craig\My Documents\Arduino\arduino-1.0.3\reference\AttachInterrupt.html
 Where it was moved to after the loop.
 Every time I still get the same error message: my interrupts are not declared.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed my code. I'm not going to show it to you. It doesn't compile. Why not?

The ball is in your court.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 I really appreciate your attempt to help Paul.
 You make it sound like I didn't post my code or tell you how I changed it.
I posted my code and told you how I changed it.
 I've always appreciated your straight to the point attitude and have learned alot from you over the last year of studying on this forum.
 .. but do I really need to repost the entire code with the interrupt routines moved into setup, then again after setup, then again after the loop for you to see what I've changed and understand why the error codes still exist?
 I know there are alot of things wrong with the rest of the code, especially toward the end, far from the interrupts.
 I'm trying to understand these interrupt errors, then work my way down.
 While still working to build/finish a proper sketch.
 This is the code that got moved around.

Code:
void tdcIRPT() {                             // the interrupt routines
  tdcStartTime = micros();                 
  }
 void pulseIRPT() {
  injectorStartTime = micros();
  } 

 FORE,.. oh wait that's golf.
 What do tennis players yell when they serve or return the ball?
Maybe just a grunt? ha. Not sure how to spell a grunt but I'll post that question in the spelling fora.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but do I really need to repost the entire code with the interrupt routines moved into setup, then again after setup, then again after the loop for you to see what I've changed and understand why the error codes still exist?
You need to post the code you are having problems with. You changed what you originally posted. That means that you need to repost.

There have been too many cases where people expect us to follow the changes that they made, when the made a lot more than they told us about. Ctrl-A, Ctrl-C, Ctrl-V really isn't more trouble than several paragraphs to describe the changes.

All of your code is not two snippets. How can you expect us to reproduce your problem with two isolated snippets.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is all my code.
 The whole thing is in the first post. Not 2 snippets, just one.
The interupt was just moved around.
 Here it is moved to after setup:
Code:
/* Finds time from TDC1, TDC4 and pulseStart. It's a finite state machine. Holds in a loop until the proper state occurs.
* First it looks for a LOW on the pulse detector to trigger an interrupt that logs the timing of the event. The INJECTORWAIT state isn't looking for a LOW on the pin.
* The interrupt does that. The INJECTORWAITT state is looking for data stored because the pin went LOW. Same with *the other 2 states The injector pulse comes before TDC1. How many degrees before top dead center BTDC is what we *are looking for */
#define INJECTORWAIT 0
#define TDCWAIT_1 1
#define TDCWAIT_2 2
#define AVERAGEWAIT

unsigned long tdcStartTime;
unsigned long tdcStartTime_1;
unsigned long tdcStartTime_2;
unsigned long injectorStartTime;
unsigned long Btdc;
unsigned long aveBtdc;
unsigned long oneRevTime;
unsigned long aveRevTime;
unsigned long btdcY;
unsigned long rpmX;

const int pulsePin = 2;
const int tdcPin = 3;
int count = 0;
byte state = INJECTORWAIT;

void setup() {
 Serial.begin(9600);
 pinMode(pulsePin, INPUT);
 pinMode(tdcPin, INPUT);
 while (digitalRead(tdcPin) == HIGH) { //wait here until we are at TDC (any TDC)
  }
 attachInterrupt(0,PulseIRPT,FALLING);  //enable interrupt attached to pin 2 pulse detector
 attachInterrupt(1,TdcIRPT,FALLING);    //enable interrupt attached to pin 3 flywheel laser sensor
  }
   void tdcIRPT() {                             // the interrupt routines moved to after setup
  tdcStartTime = micros();                
  }
 void pulseIRPT() {
  injectorStartTime = micros();
  }
void loop () {
    Serial.print("DATA, TIME,,,");             // Opens PLX-DAQ data line
  
 while (state == INJECTORWAIT)  {
  if (injectorStartTime > 0 ) {
       state = TDCWAIT_1;
   }
   }
 while (state == TDCWAIT_1) {
  if (tdcStartTime > 0 ) {
      tdcStartTime_1 = tdcStartTime;      //here we stored the value from the tdcIRPT interrupt routine intdcStartTime_1
      tdcStartTime = 0;                   //set to 0 so the next state knows if it's been retriggered.
      state = TDCWAIT_2;
  }
  }
 while (state == TDCWAIT_2) {
  if (tdcStartTime > 0) {
        tdcStartTime_2 = tdcStartTime;    
      state = AVERAGEWAIT;
  }
  }
 while (state == AVERAGEWAIT) {                    // You now have the three times you need for all your calculations.
    Btdc = tdcStartTime_1 - injectorStartTime;        // BTDC in microseconds
  oneRevTime = tdcStartTime_2 - tdcStartTime_1;     // time for one revolution in microseconds
  injectorStartTime = 0;                            // gets zeroed every time
  tdcStartTime = 0;
  if (count < 16)  {
     aveRevTime = ((15 * aveRevTime) + oneRevTime)/ 16;                //a decaying average allows me to do this without an array
     aveBtdc =    ((15 * aveBtdc) +  Btdc) / 16;
     count++;
  }
  else {
      rpmX = (60000000 / aveRevTime);                                  //oodles of time so calculate RPM
      btdcY = ((aveBtdc) / ((oneRevTime) / 360));                      //don't waste the oodles
     Serial.print(btdcY);Serial.print(",");Serial.println(rpmX);      //Dumps the average results into excel columns D&E
     count = 0;                                                       // zeroing variables that get used for averaging
     state = INJECTORWAIT;                                           //sends it back to the beginning to wait for an injector pulse
  }
  }
 }
 
  // and around the loop() we go again.
}
 
 ///OOOOORRRRR should I do it this way?
        tdcStartTime_2 = tdcStartTime;
      //without the state=INJECTORWAIT here it should just go to the next line right?
  }
  }             // You now have the three times you need for all your calculations.
    Btdc = tdcStartTime_1 - injectorStartTime;        // BTDC in microseconds
  oneRevTime = tdcStartTime_2 - tdcStartTime_1;     // time for one revolution in microseconds
  injectorStartTime = 0;                            // gets zeroed every time
  tdcStartTime = 0;
  if (count < 16)  {
     aveRevTime = ((15 * aveRevTime) + oneRevTime)/ 16;   //a decaying average allows me to do this without an array
     aveBtdc =    ((15 * aveBtdc) +  Btdc) / 16;
     count++;
  }
  else {
      rpmX = (60000000 / aveRevTime);                                  //oodles of time so calculate RPM
      btdcY = ((aveBtdc) / ((oneRevTime) / 360));                      //don't waste the oodles
     Serial.print(btdcY);Serial.print(",");Serial.println(rpmX);      //Dumps the average results into excel columns D&E
     count = 0;                                                       // zeroing variables that get used for averaging
     state = INJECTORWAIT;
  }
//and aroound we go again  

posting the other 2 ways I changed it exceeds the allowed post length so I'll make 2 more posts.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here the interrupts functions are moved before setup:
Code:
/* Finds time from TDC1, TDC4 and pulseStart. It's a finite state machine. Holds in a loop until the proper state occurs.
* First it looks for a LOW on the pulse detector to trigger an interrupt that logs the timing of the event. The INJECTORWAIT state isn't looking for a LOW on the pin.
* The interrupt does that. The INJECTORWAITT state is looking for data stored because the pin went LOW. Same with *the other 2 states The injector pulse comes before TDC1. How many degrees before top dead center BTDC is what we *are looking for */
#define INJECTORWAIT 0
#define TDCWAIT_1 1
#define TDCWAIT_2 2
#define AVERAGEWAIT

unsigned long tdcStartTime;
unsigned long tdcStartTime_1;
unsigned long tdcStartTime_2;
unsigned long injectorStartTime;
unsigned long Btdc;
unsigned long aveBtdc;
unsigned long oneRevTime;
unsigned long aveRevTime;
unsigned long btdcY;
unsigned long rpmX;

const int pulsePin = 2;
const int tdcPin = 3;
int count = 0;
byte state = INJECTORWAIT;
   void tdcIRPT() {                             // the interrupt routines
  tdcStartTime = micros();                 
  }
 void pulseIRPT() {
  injectorStartTime = micros();
  }

void setup() {
 Serial.begin(9600);
 pinMode(pulsePin, INPUT);
 pinMode(tdcPin, INPUT);
 while (digitalRead(tdcPin) == HIGH) { //wait here until we are at TDC (any TDC)
  }
 attachInterrupt(0,PulseIRPT,FALLING);  //enable interrupt attached to pin 2 pulse detector
 attachInterrupt(1,TdcIRPT,FALLING);    //enable interrupt attached to pin 3 flywheel laser sensor
  }
 
void loop () {
    Serial.print("DATA, TIME,,,");             // Opens PLX-DAQ data line
 
 while (state == INJECTORWAIT)  {
  if (injectorStartTime > 0 ) {
       state = TDCWAIT_1;
   }
   }
 while (state == TDCWAIT_1) {
  if (tdcStartTime > 0 ) {
      tdcStartTime_1 = tdcStartTime;      //here we stored the value from the tdcIRPT interrupt routine intdcStartTime_1
      tdcStartTime = 0;                   //set to 0 so the next state knows if it's been retriggered.
      state = TDCWAIT_2;
  }
  }
 while (state == TDCWAIT_2) {
  if (tdcStartTime > 0) {
        tdcStartTime_2 = tdcStartTime;     
      state = AVERAGEWAIT;
  }
  }
 while (state == AVERAGEWAIT) {                    // You now have the three times you need for all your calculations.
    Btdc = tdcStartTime_1 - injectorStartTime;        // BTDC in microseconds
  oneRevTime = tdcStartTime_2 - tdcStartTime_1;     // time for one revolution in microseconds
  injectorStartTime = 0;                            // gets zeroed every time
  tdcStartTime = 0;
  if (count < 16)  {
     aveRevTime = ((15 * aveRevTime) + oneRevTime)/ 16;                //a decaying average allows me to do this without an array
     aveBtdc =    ((15 * aveBtdc) +  Btdc) / 16;
     count++;
  }
  else {
      rpmX = (60000000 / aveRevTime);                                  //oodles of time so calculate RPM
      btdcY = ((aveBtdc) / ((oneRevTime) / 360));                      //don't waste the oodles
     Serial.print(btdcY);Serial.print(",");Serial.println(rpmX);      //Dumps the average results into excel columns D&E
     count = 0;                                                       // zeroing variables that get used for averaging
     state = INJECTORWAIT;                                           //sends it back to the beginning to wait for an injector pulse
  }
  }
 }
 
  // and around the loop() we go again.
}
 
 ///OOOOORRRRR should I do it this way?
        tdcStartTime_2 = tdcStartTime;
      //without the state=INJECTORWAIT here it should just go to the next line right?
  }
  }             // You now have the three times you need for all your calculations.
    Btdc = tdcStartTime_1 - injectorStartTime;        // BTDC in microseconds
  oneRevTime = tdcStartTime_2 - tdcStartTime_1;     // time for one revolution in microseconds
  injectorStartTime = 0;                            // gets zeroed every time
  tdcStartTime = 0;
  if (count < 16)  {
     aveRevTime = ((15 * aveRevTime) + oneRevTime)/ 16;   //a decaying average allows me to do this without an array
     aveBtdc =    ((15 * aveBtdc) +  Btdc) / 16;
     count++;
  }
  else {
      rpmX = (60000000 / aveRevTime);                                  //oodles of time so calculate RPM
      btdcY = ((aveBtdc) / ((oneRevTime) / 360));                      //don't waste the oodles
     Serial.print(btdcY);Serial.print(",");Serial.println(rpmX);      //Dumps the average results into excel columns D&E
     count = 0;                                                       // zeroing variables that get used for averaging
     state = INJECTORWAIT;
  }
//and aroound we go again 
 
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and here it is with the interrupt function moved to after the loop:
Code:
/* Finds time from TDC1, TDC4 and pulseStart. It's a finite state machine. Holds in a loop until the proper state occurs.
* First it looks for a LOW on the pulse detector to trigger an interrupt that logs the timing of the event. The INJECTORWAIT state isn't looking for a LOW on the pin.
* The interrupt does that. The INJECTORWAITT state is looking for data stored because the pin went LOW. Same with *the other 2 states The injector pulse comes before TDC1. How many degrees before top dead center BTDC is what we *are looking for */
#define INJECTORWAIT 0
#define TDCWAIT_1 1
#define TDCWAIT_2 2
#define AVERAGEWAIT

unsigned long tdcStartTime;
unsigned long tdcStartTime_1;
unsigned long tdcStartTime_2;
unsigned long injectorStartTime;
unsigned long Btdc;
unsigned long aveBtdc;
unsigned long oneRevTime;
unsigned long aveRevTime;
unsigned long btdcY;
unsigned long rpmX;

const int pulsePin = 2;
const int tdcPin = 3;
int count = 0;
byte state = INJECTORWAIT;


void setup() {
 Serial.begin(9600);
 pinMode(pulsePin, INPUT);
 pinMode(tdcPin, INPUT);
 while (digitalRead(tdcPin) == HIGH) { //wait here until we are at TDC (any TDC)
  }
 attachInterrupt(0,PulseIRPT,FALLING);  //enable interrupt attached to pin 2 pulse detector
 attachInterrupt(1,TdcIRPT,FALLING);    //enable interrupt attached to pin 3 flywheel laser sensor
  }
 
void loop () {
    Serial.print("DATA, TIME,,,");             // Opens PLX-DAQ data line
 
 while (state == INJECTORWAIT)  {
  if (injectorStartTime > 0 ) {
       state = TDCWAIT_1;
   }
   }
 while (state == TDCWAIT_1) {
  if (tdcStartTime > 0 ) {
      tdcStartTime_1 = tdcStartTime;      //here we stored the value from the tdcIRPT interrupt routine intdcStartTime_1
      tdcStartTime = 0;                   //set to 0 so the next state knows if it's been retriggered.
      state = TDCWAIT_2;
  }
  }
 while (state == TDCWAIT_2) {
  if (tdcStartTime > 0) {
        tdcStartTime_2 = tdcStartTime;     
      state = AVERAGEWAIT;
  }
  }
 while (state == AVERAGEWAIT) {                    // You now have the three times you need for all your calculations.
    Btdc = tdcStartTime_1 - injectorStartTime;        // BTDC in microseconds
  oneRevTime = tdcStartTime_2 - tdcStartTime_1;     // time for one revolution in microseconds
  injectorStartTime = 0;                            // gets zeroed every time
  tdcStartTime = 0;
  if (count < 16)  {
     aveRevTime = ((15 * aveRevTime) + oneRevTime)/ 16;                //a decaying average allows me to do this without an array
     aveBtdc =    ((15 * aveBtdc) +  Btdc) / 16;
     count++;
  }
  else {
      rpmX = (60000000 / aveRevTime);                                  //oodles of time so calculate RPM
      btdcY = ((aveBtdc) / ((oneRevTime) / 360));                      //don't waste the oodles
     Serial.print(btdcY);Serial.print(",");Serial.println(rpmX);      //Dumps the average results into excel columns D&E
     count = 0;                                                       // zeroing variables that get used for averaging
     state = INJECTORWAIT;                                           //sends it back to the beginning to wait for an injector pulse
  }
  }
 }
 
    void tdcIRPT() {                             // the interrupt routines moved to after the loop
  tdcStartTime = micros();                 
  }
 void pulseIRPT() {
  injectorStartTime = micros();
  }
 
  // and around the loop() we go again.
}
 
 ///OOOOORRRRR should I do it this way?
        tdcStartTime_2 = tdcStartTime;
      //without the state=INJECTORWAIT here it should just go to the next line right?
  }
  }             // You now have the three times you need for all your calculations.
    Btdc = tdcStartTime_1 - injectorStartTime;        // BTDC in microseconds
  oneRevTime = tdcStartTime_2 - tdcStartTime_1;     // time for one revolution in microseconds
  injectorStartTime = 0;                            // gets zeroed every time
  tdcStartTime = 0;
  if (count < 16)  {
     aveRevTime = ((15 * aveRevTime) + oneRevTime)/ 16;   //a decaying average allows me to do this without an array
     aveBtdc =    ((15 * aveBtdc) +  Btdc) / 16;
     count++;
  }
  else {
      rpmX = (60000000 / aveRevTime);                                  //oodles of time so calculate RPM
      btdcY = ((aveBtdc) / ((oneRevTime) / 360));                      //don't waste the oodles
     Serial.print(btdcY);Serial.print(",");Serial.println(rpmX);      //Dumps the average results into excel columns D&E
     count = 0;                                                       // zeroing variables that get used for averaging
     state = INJECTORWAIT;
  }
//and aroound we go again 
 
 
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 50
Posts: 2199
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1. It is an error to declare a function with in another function in C/C++.

2. the language is case-senisitive Fred is not the same as FREd or fred.

Mark
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11671
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#define AVERAGEWAIT

Is clearly wrong.

TdcIRPT  is a totally different identifier to tdcIRPT.

Your curly braces don't remotely match - you need to get the indentation
sorted first, if your not using a text editor with bracket-matching you
will benefit from one.

The global variables accessed in an interrupt routine must be declared volatile:
Code:
volatile unsigned long tdcStartTime;
unsigned long tdcStartTime_1;
unsigned long tdcStartTime_2;
volatile unsigned long injectorStartTime;

Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Edit for return key test.
OK, got rid of that error message.
 Thanks for everyone's help.
End of the code was cleaned-up alot as I work toward putting the math into a function to be called as lar3ry suggested.
And getting rid of all the garbage at the bottom before putting the interrupt functions there got rid of that "not declared" message.
 Thanks markT for catching the lower case function call that didn't match the function.
Played some more.
 Here's the code. and this time I got auto format working so it's easier to read:
Code:
/* Finds time from TDC1, TDC4 and pulseStart. It's a finite state machine.
* Holds in a loop until the proper state occurs.
* First it looks for a LOW on the pulse detector to trigger an interrupt
* that logs the timing of the event.
* The INJECTORWAIT state isn't looking for a LOW on the pin.
* The interrupt does that.
* The INJECTORWAITT state is looking for data stored because the pin went LOW.
* Same with *the other 2 states The injector pulse comes before TDC1.
* How many degrees before top dead center BTDC is what we *are looking for */
#define INJECTORWAIT 0
#define TDCWAIT_1 1
#define TDCWAIT_2 2
//declared volatile because it's a global variable used in a function
volatile unsigned long tdcStartTime; volatile unsigned long injectorStartTime;
volatile unsigned long tdcStartTime_2;
volatile unsigned long tdcStartTime_1;
unsigned long oneRevTime;
unsigned long btdcY;
unsigned long rpmX;
const int pulsePin = 2;
const int tdcPin = 3;

byte state = INJECTORWAIT;

void setup() {
  Serial.begin(9600);
  pinMode(pulsePin, INPUT);
  pinMode(tdcPin, INPUT);
  while (digitalRead(tdcPin) == HIGH)  //wait here until we are at TDC (any TDC)
  }
  injectorStartTime = 0;
  attachInterrupt (0,pulseIRPT,FALLING);  //enable pin 2 pulse interrupt
  attachInterrupt (1,tdcIRPT,FALLING);    //enable pin 3 tdc interrupt
}

void loop () {
  Serial.print("DATA, TIME,,,");             // Opens PLX-DAQ data line

  while (state == INJECTORWAIT)  {
    if (injectorStartTime > 0 ) {
      state = TDCWAIT_1;
      tdcStartTime = 0;
    }
  }
  while (state == TDCWAIT_1) {
    if (tdcStartTime > 0 ) {
      tdcStartTime_1 = tdcStartTime;  //we stored the value from the tdcIRPT interrupt
      intdcStartTime_1
      tdcStartTime = 0;    //set to 0 so the next state knows if it's been retriggered.
      state = TDCWAIT_2;
    }
  }
  while (state == TDCWAIT_2) {
    if (tdcStartTime > 0) {
      tdcStartTime_2 = tdcStartTime;
      injectorStartTime = 0;
    }
    unsigned long z;      //a call to the calculate function
    z = calculate (unsigned long tdcStartTime_1,unsigned long injectorStartTime,
    unsigned long tdcStartTime_2);
    delay 10000;
    state = INJECTORWAIT;
  }
}   //end of loop so interrupt and other functions go here
void tdcIRPT() {                     // the interrupt routines
  tdcStartTime = micros();                
}
void pulseIRPT() {
  injectorStartTime = micros();
}
int calculate  (unsigned long a, unsigned long b, unsigned long c);
{ //calculate function
  int btdcY;  //degrees before top dead center shouldn't be more than 30
  long rpmX; // can be up to 6000
  unsigned long Btdc;
  Btdc = a - b;                 // BTDC in microseconds
  oneRevTime = c - a;           // time for one revolution in microseconds
  rpmX = 60000000/oneRevTime;   //x-axis data to send to excel
  btdcY = ((Btdc/oneRevTime)/360);  //y-axis data to send to excel
  Serial.print(btdcY);
  Serial.print(",");
  Serial.println(rpmX);
}

woo hoo knocked some of them down and learned alot.
edited to swap in latest code,.. before anyone gave me crap about how bad I messed up the calculate function.
 Oh you think it's bad now? ha.
« Last Edit: February 17, 2014, 11:49:20 am by graphing » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
/* Finds time from TDC1, TDC4 and pulseStart. It's a finite state machine. Holds in a loop until the proper state occurs.
 * First it looks for a LOW on the pulse detector to trigger an interrupt that logs the timing of the event. The INJECTORWAIT state isn't looking for a LOW on the pin.
 * The interrupt does that. The INJECTORWAITT state is looking for data stored because the pin went LOW. Same with *the other 2 states The injector pulse comes before TDC1. How many degrees before top dead center BTDC is what we *are looking for */
#define INJECTORWAIT 0
Is your enter key broken? Get it fixed!
Logged

Pages: [1] 2   Go Up
Jump to: