Problem with simulating an incremental rotary encoder and decoding algorithm in Simulink

6 次查看(过去 30 天)
Hi, I am currently trying to simulate an incremental rotary encoder and decoding algorithm (for obtaining velocity measurements) in Simulink. The main purpose of this simulation is to analyze the performance of the decoding method before actually implementing it on an Arduino board.
The decoding method is actually quite simple: it is a fixed time method wherein the number of pulses from the encoder are counted within a given time period. The velocity of the shaft is then calculated based on the number of counts and the resolution of the encoder. From what I understand, such approach has large errors in calculating the velocity at relatively slow speeds, the magnitude of error depending on the resolution of the encoder and the length of the time period.
This is where the simulation comes in. In simulation, I would like to check whether the performance of the algorithm is sufficient for my needs. Until now, I have simulated the incremental rotary encoder using Simscape (see below). I have only used signal A for now (surely, using both A and B will increase performance). 'Solver Configuration' is set to default values. There seems to be no problem here.
In order to count the number of pulses (rising edges for now) from the encoder during a given time period, I used two counters. One counter ('Counter' in figure below) counts 'Up' the rising edges. The other counter ('Counter1' in figure below) counts 'Down' in 'Free running' mode and resets 'Counter' at regular time intervals. I suspect there are no problems here, either.
Here is the problem. In real implementation, the counting is done by the Arduino and the number of counts are sent to my PC over serial communication. I would like to simulate this behavior. In other words, I would like to only retrieve the number of counts from 'Counter' at the time when it is reset, i.e. only the total number of counts during the given time period. What would be the best practice in simulating such behavior?
I have attached the simulink model file.
Thank you.

回答(1 个)

niraj
niraj 2018-1-15
hope u have solved the problem already, still one suggestion, u can attach the falling edge detector at the digital pulse input and connect it through switch to obtain the count value.

Community Treasure Hunt

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

Start Hunting!

Translated by