Arduino Support Package: Reading PWM From Digital Pin

18 vues (au cours des 30 derniers jours)
Elliot Nauert
Elliot Nauert le 24 Oct 2015
Réponse apportée : Dennie le 26 Oct 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!

Réponses (1)

Dennie
Dennie le 26 Oct 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.

Communautés

Plus de réponses dans  Power Electronics Control

Catégories

En savoir plus sur Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by