Go Down

Topic: ARDUINO + MATLAB Real time graph *help asap please (Read 1 time) previous topic - next topic

ricky882

Mar 05, 2013, 06:39 am Last Edit: Mar 05, 2013, 06:49 am by Coding Badly Reason: 1
I am working on a controls project. mech engr dont know much about ece
i have an IR emitter and detector that detects how fast the radiometer is spinning using the arduino uno
the code is here

Code: [Select]
int ledPin = 13;
int statusPin = 12;

volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};
volatile int stat;

void fan_interrupt() {
 time = (micros()-time_last);
 time_last = micros();
 
 if(stat == LOW) {
   stat = HIGH;
 }
   else {
     stat = LOW;
 }
 digitalWrite(statusPin, stat);
 
}

void setup() {
 Serial.begin(9600);
 
 attachInterrupt(0, fan_interrupt, FALLING);
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, HIGH);
 pinMode(statusPin, OUTPUT);
 
}

void loop() {
 int rpm = 0;
 
 while(1) {
   delay(1000);
   
   if(time>0) {
     rpm_array[0] = rpm_array[1];
     rpm_array[1] = rpm_array[2];
     rpm_array[2] = rpm_array[3];
     rpm_array[3] = rpm_array[4];
     rpm_array[4] = 60*(1000000/(time*4));
     
     rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4])/5;
   
   Serial.println(rpm,DEC);
   
   }
 }
}



i need help in creating the real time plot on matlab
the graph should show rpm vs time

a=arduino('com4');
Attempting connection .............
Basic I/O Script detected !
Arduino successfully connected !

i got the uno to connect to matlab
just need help on the code
can anyone help me please asap


Moderator edit: [code] [/code] tags added.

Coding Badly


PaulS

Quote
just need help on the code

Did you get help writing that Arduino code on the MatLab forum?

robtillaart


1000000  ==> 1000000L  to explicitely make it long, for the rest it should work (you do some average rounds per minute ?)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up