Arduino Support Package: Reading PWM From Digital Pin

4 visualizaciones (últimos 30 días)
Elliot Nauert
Elliot Nauert el 24 de Oct. de 2015
Respondida: Dennie el 26 de Oct. de 2015
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!

Respuestas (1)

Dennie
Dennie el 26 de Oct. de 2015
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.

Comunidades de usuarios

Más respuestas en  Power Electronics Control

Categorías

Más información sobre Arduino Hardware en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by