Delay interfacing Arduino and Simulink

Hi All,
I am trying to read data from potentionmeter using an arduino microcontroller (tried both arduino UNO, arduino FIO) and using serial communication interface it to Simulink (I tried baud rates ranging from 57600-921600).
Following is the arduino code

/*
  AnalogReadSerial
  Reads an analog input on pin 0, prints the result to the serial monitor.
*/
#define ana_pin A0 

void setup() {
  analogReference(DEFAULT);
  Serial.begin(57600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(ana_pin);
  // print out the value you read:
  Serial.print(sensorValue);
 // delay(500);        // delay in between reads for stability
}

I interfaced it with Tera Term software and there is instantaneous change of values corresponding to 3 V or 0V.

However when I tried to interface it with Simulink model using instrument control toolbox(See attachment ICT_Simulink_Model.png) there is a 10 second lag when value changes from ASCII representation of 3V to 0V (See attachment ICT_scope.png). The block sample time is 0.01 seconds and the model configuration parameters are adjusted accordingly (I tried it for 1 second or more and the delay still remains. Also, I was able to record data from another sensor and
LPC1768 development board without any delay.

I also tried it with Arduino support libraries in Simulink (see attachment Arduino_Hardware_implementation.png). And it seems that no data is received, as you can see from Scope1 in the png file the status signal is always 0. I have also attached hardware implementation properties from Arduino block in Simulink (attachment Hardware_implementation_properties.png). I appreciate any guidance you guys can provide to sort this issue. Thank you for your time.

Can’t help you but please replace your color tags by code tags
[code] and [/code].

If you only send serial data when the value being sent has changed, does that reduce the lag?

I'm guessing that you are spamming Simulink.

I don't see how you expect Simulink to know where one value stops and another begins, when you send something like "512511510499498500512513".

Send the data using println() or send a space, comma or something between the values.

Hi thank you for your reply. As per your suggestion I used Serial.println function and set the terminator in the Instrument control toolbox as <\r\n>. However the 10 sec delay between perceived value changes still persists. Using Serial.println function and setting the terminator in ICT as , the delay increases by approximately sec (total delay 20 sec). Intuitively its understandable as the delay accounts to reading and displaying the ASCII character for ‘\r\n’. So I think am pretty sure the delay is due to arduino and simulink interface.

/*
  AnalogReadSerial
  Reads an analog input on pin 0, prints the result to the serial monitor.
*/

#define ana_pin A0 


void setup() {
  analogReference(DEFAULT);
  Serial.begin(57600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(ana_pin);
  // print out the value you read:
  Serial.println(sensorValue);
 // delay(500);        // delay in between reads for stability
}

No idea about Simulink; be aware that if Simulink opens and closes the serial port for every read, most Arduinos will receive a reset; that’s a 2 or 3 second delay. You can check by observing the pin13 led. If that led flashes two or three times during a read from Simulink, it means that the Arduino has received a reset.

For the FIO with an FTDI cable, you can prevent this by not connecting the DTR line (as far as I understand the description of the board).