read digital pin pulses

how could I read digital pin pulses from arduino in matlab?
I mean by writing readDigitalPin(a,'D4')
it shows just 0 or 1
but I want to read pulses from this pin which connected with the phase of increamental encoder

Réponses (1)

Asad Mirza
Asad Mirza le 24 Fév 2019

0 votes

Digital pins only return values of 0 or 1. If you want to read voltage information from an incremental encoder it would have to be connected to an analog in pin and then you would have to use readVoltage.

7 commentaires

john white
john white le 24 Fév 2019
actually I want to know the position of the encoder and I know that matlab has a code for this by using readCount of rotaryEncoder but I want to connect the pins of the encoder to different digital pins like 4 and 5 instead of 2 and 3 so I neet to know which pulses of the channels of encoder is in high level at the first to know the CW or CCW direction to adding count or decreasing count
Asad Mirza
Asad Mirza le 24 Fév 2019
I believe MATLAB has an example code that reports the position of an encoder. Granted they use pin's D2 and D3 but you can easily change it to be D4 and D5 for ChannelA and B and then have say D2 be for the pushbutton.
john white
john white le 25 Fév 2019
yes I know that Matlab has a code but when I change the pins number it shows an error that the pins in the rotaryEncoder command must be D2 and D3
Asad Mirza
Asad Mirza le 25 Fév 2019
Ah that might be because only D2 and D3 on a classic Arduino Uno have what are called interrupt pins which are needed for rotary encoder information. Arduino Interrupts explains a bit about this. As far as I know you cannot change the interrupt pins in MATLAB but using the Arduino ide you can program the Atmel chip to make any of the other digital pins interrupts like so.
john white
john white le 25 Fév 2019
yes I know that and I could change the other digital pins to Interrupt pins in the Arduino ide
but there is no way in Matlab.
Asad Mirza
Asad Mirza le 25 Fév 2019
Yeah, as far as I know MATLAB can't natively change the interrupt pins.
Welid Benchouche
Welid Benchouche le 15 Sep 2022
but can matlab call an interrupt in matlab code ?not the external interrupt or detect increase in simulink, in matlab code.

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by