How count pulse when go up in simulink?
조회 수: 104 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!