How to produce a pulse for 10Microseconds?
8 次查看(过去 30 天)
显示 更早的评论
I am programming my Arduino from matlab(I installed supporting package), in order to use Ultrasonic sensor I need to produce a trigger pulse for 10microseconds(from matlab) and I also need to read the time in microseconds. please tell me how to produce a delay of 10us or produce a constant value for 10us. I am using matlab2014b.
I need to produce the pulse in Yellow from matlab and read the pulse in Red in Matlab. Both are in microseconds thank you
0 个评论
回答(1 个)
Walter Roberson
2017-2-21
Technical notes:
Looking at:
Arduino code would look something like
digitalWrite(13, HIGH);
delayMicroseconds(10);
digitalWrite(13, LOW);
where the 13 would have to be adjusted to the appropriate pin number.
The MATLAB interface to digitalWrite is writeDigitalPin: https://www.mathworks.com/help/supportpkg/arduinoio/ref/writedigitalpin.html
The difficulty with using this is the timing: there is no way in MATLAB to pause for less than 1/1000 of a second (and you cannot even do that well on MS Windows.) If you could pause for that short of a period, the time required to send the new data to arduino would add a lot of uncertainty.
It would therefore be better to program the 10 microsecond pulse on the arduino side.
With regards to the TTL signal: is the idea that you get a response by reading the voltage? If so then it becomes important to know the minimum and maximum voltages. Or does "range in proportion" refer to time?
2 个评论
Walter Roberson
2017-2-22
I would not attempt to trigger a PULSEIN from the MATLAB level: your timing is too strict.
Always keep in mind: your MATLAB session might get suspended for an unknown number of hours while your PC does virus checking, or fetches email, or updates a "Push" page in the web browser you left open, and so on. MS Windows is not a real-time operating system and MATLAB itself does not try to be a real-time program.
I see https://www.mathworks.com/matlabcentral/answers/33710-how-to-replicate-an-arduino-timer-function-in-matlab showing code you can use on the Arduino side.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!