简体   繁体   中英

Delay interfacing Arduino and Simulink

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).

Here is the Arduino source 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:

在此处输入图片说明

there is a 10 second lag when value changes from ASCII representation of 3V to 0V

在此处输入图片说明

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:

在此处输入图片说明

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:

在此处输入图片说明

Could you help me understand what is going on and how to solve this issue?

@Patrick Trentin - I get a delay of 4 seconds when I use baud rates of 230400, 460800 and 921600. For baud rate of 57600, 115200 I get a delay of 10 seconds. Thank you for pointing it out I did not focus on that previously. However since I will be using the sensor in an application which accurately needs reading every 0.01 sec. I dont think I can work with 4 sec delay.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM