How count pulse when go up in simulink?

조회 수: 121 (최근 30일)
FRANCISCO JAVIER
FRANCISCO JAVIER 2013년 10월 17일
답변: Jonathan LeSage 2013년 10월 17일
How count pulse when go up in simulink, to obtaint the speed of the motor throught a encoder that emits 50 pulses for revolution. This is in discrete time 0.001. I delay the pulse and compare the pulse with the delay, but neither not count good and reset the counter a zero. Besides i do this through embedded function that this, where u is the pulse, u_r is the pulse delay, t is a clock, an y_r is the feedback of y. I need help, please.
function [y] = fcn(u,u_r,t,y_r) %#eml
persistent count; persistent tiempo;
if isempty(count) count=0; end
if isempty(tiempo) tiempo=0; end
y=y_r; % Realimentacion de velocidad
if count==0 % Si contactor esta cero, ponemos en marcha el tiempo tiempo=t; end if u==1 && u_r==0 % Si detecta flanco positivo, aumenta el contador count=count+1; end if count==50; % suponemos da 50 pulsos por vuelta, % Si llega a 50 pulsos, calculamos tiempo en dar una vuelta y=t-tiempo; count=0; % reseteamos contador end

채택된 답변

Jonathan LeSage
Jonathan LeSage 2013년 10월 17일
One potential method for counting pulses is to use the Detect Increase or Detect Rising Edge block to detect the rising edge of each pulse. If you set the output of either of these blocks to be an integer rather than a boolean, you can numerically sum the pulses via a Sum block. To keep a running total, you can use the Memory block.
Here are some links to some useful documentation:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by