Arduino Support Package: Reading PWM From Digital Pin

19 ビュー (過去 30 日間)
Elliot Nauert
Elliot Nauert 2015 年 10 月 24 日
回答済み: Dennie 2015 年 10 月 26 日
Hi,
I am using a Maxbotix Ultrasonic Sensor with an Arduino Uno and would like to read the PWM values from the sensor. I have been able to use readVoltage to read an analog signal from the sensor, but PWM is much more consistent. It won't allow me to use readDigitalPin when the pin mode has been set to 'PWM', and in 'digitalInput' mode it just gives me a value of 0. I have also been able to read the PWM via the Arduino IDE, but have not figured out the best way to do this with Matlab's Arduino Support Package. Any guidance would be appreciated!
Arduino Uno R3 Matlab 2015a (32 bit) Windows 10
Thanks!

回答 (1 件)

Dennie
Dennie 2015 年 10 月 26 日
Hi Elliot, I'm currently dealing with similar issues in Simulink. What I've noticed is that matlab does not directly support reading out PWM frequencies. You said it worked from the arduino IDE, but I'm not sure what you exactly read out there. What worked for me was to configure the pin as a digital input and use readDigitialPin() to get out the signal. Then you can use a simple edge detector algorithm to get the time in between pulses and from there get the PWM frequency. Just make sure that the sample frequency is at least double the PWM frequency that you try to capture.
You can also try to do this in Simulink and see if you get a different result.
If this still doesn't work, you can also check your hardware. Make sure to use a common ground and a pull-up resistor, etc.

コミュニティ

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by