在al循环中找到计数器 [英] Finding the counter in al loop
本文介绍了在al循环中找到计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在循环中有这个功能,所以我想计算转换次数。
来自exaplpe的
,当zero_cross从1移动到0时,它应该计数,当它从0移动时它也应该算一数。
我尝试过的事情:
i have this function in side a loop , so i want to count number of transmation .
from exaplpe , when zero_cross move form 1 to 0 , it shlould count , and when it moves from 0 to 1 it should count too.
What I have tried:
int Zero_Cross;
if(BackFromPowerLoss > 20)
{
Zero_Cross =0 ;
}
else
{
Zero_Cross = 1 ;
}
}
推荐答案
一个简单的方法是有两个额外的变量,一个用于跟踪从0到1的交叉,另一个用于跟踪从1到0的交叉点。您需要考虑的是,您只想在Zero_Cross更改时增加这些值。例如:
A simple way to do this is to have two extra variables, one to track the crossing from 0 to 1 and the other to track the crossing from 1 to 0. The thing you will need to take into consideration is that you only want to increment these values when Zero_Cross changes. As an example:
int oneToZero;
int zeroToOne;
int Zero_Cross;
if (BackFromPowerLoss > 20)
{
if (Zero_Cross == 1)
{
oneToZero++;
}
Zero_Cross = 0;
}
您应该可以从该代码段中填写其余部分。关键是你需要在更改之前检查Zero_Cross的先前值是什么。
You should be able to fill the rest in from that snippet. The key thing is that you need to check what the previous value of Zero_Cross is before you change it.
这篇关于在al循环中找到计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文