[英]Delay interfacing Arduino and Simulink
我正在尝试使用arduino微控制器(尝试过arduino UNO和arduino FIO)从电位计读取数据,并使用串行通信接口将其连接到Simulink (我尝试使用57600-921600的波特率)。
这是Arduino源代码:
/*
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
}
我将其与Tera Term软件进行了接口连接,并且对应于3 V或0V的值有瞬时变化。
但是,当我尝试使用仪器控制工具箱将其与Simulink模型连接时:
当值从3V的ASCII表示更改为0V时有10秒的延迟
块采样时间为0.01
秒,并相应地调整了模型配置参数(我尝试了1秒钟或更长时间,并且仍然保留了延迟。此外,我能够无延迟地记录来自另一个传感器和LPC1768开发板的数据。
我还在Simulink中的Arduino支持库中进行了尝试:
从png文件中的Scope1
可以看出,状态信号始终为0
,似乎没有接收到任何数据。 我还附加了Simulink中Arduino块的硬件实现属性:
您能否帮助我了解发生了什么以及如何解决此问题?
@Patrick Trentin-使用230400、460800和921600的波特率时,我得到了4秒的延迟。对于57600、115200的波特率,我得到了10秒的延迟。 谢谢您指出这一点,我以前没有关注过这一点。 但是,由于我将在需要精确地每0.01秒读取一次的应用中使用传感器。 我不认为我可以延迟4秒工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.