How count pulse when go up in simulink?
104 ビュー (過去 30 日間)
古いコメントを表示
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
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!