Arduino Support Package: Reading PWM From Digital Pin
19 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
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.
0 个评论
社区
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!