关于滤波

L     #DB_no                      //打开DB块
       OPN   DB [#temp1]
       L     #DB_addr_begin              //找到DB块存储区的开始
       SLD   3
       T     #temp2
       A     #Time_base                  //时基到,采集数据
       JCN   end
       L     #Mid
       L     1
       +I    
       T     #Mid
       L     #Mid
       L     #Degree
       >=I   
       JC    a1                          //采集次数未到,继续采集;采集完成,程序跳转到a1
       L     #Mid
       L     4
       *I    
       SLD   3
       L     #temp2
       +D    
       T     #temp3
       L     #Piw_addr
       ITD   
       T     DBD [#temp3]
       JU    end
 a1:   L     #temp2                      // 求最大值
       LAR1  
       L     DBD [AR1,P#0.0]
       T     #temp4
       L     #Degree
 max:  T     #temp6
       L     #Degree
       L     #temp6
       -I    
       L     4
       *I    
       SLD   3
       L     #temp2
       +D    
       T     #temp7
       L     #temp4
       L     DBD [#temp7]
       >D    
       JC    a2
       L     DBD [#temp7]
       T     #temp4
 a2:   L     #temp6
       LOOP  max
       L     #temp2                      //求最小值
       LAR1  
       L     DBD [AR1,P#0.0]
       T     #temp5
 min:  T     #temp8
       L     #Degree
       L     #temp8
       -I    
       L     4
       *I    
       SLD   3
       L     #temp2
       +D    
       T     #temp9
       L     DBD [#temp9]
       L     #temp5
       >D    
       JC    a3
       L     DBD [#temp9]
       T     #temp5
 a3:   L     #temp8
       LOOP  min                         //求和
       L     0
       T     #temp12
       L     #Degree
 sum:  T     #temp10
       L     #Degree
       L     #temp10
       L     4
       *I    
       SLD   3
       L     #temp2
       +D    
       T     #temp11
       L     #temp12
       L     DBD [#temp11]
       +D    
       T     #temp12
       L     #temp10
       LOOP  sum
       L     #temp12
       L     #temp4                      //减去最大值
       -D    
       T     #temp12
       L     #temp12
       L     #temp5                      //减去最小值
       -D    
       T     #temp12
       L     #temp12
       L     #Degree
       DEC   1
       DEC   1
       ITD   
       /D    
       T     #result
       L     #result
       T     #Average                    //输出平均值结果
       L     -1
       T     #Mid
       L     #Degree
 init: T     #temp10                     //初始化
       L     #Degree
       L     #temp10
       -I    
       L     4
       *I    
       SLD   3
       L     #temp2
       +D    
       T     #temp11
       L     #temp12
       L     DBD [#temp11]
       +D    
       T     #temp12
       L     #temp10
       LOOP  init
 end:  NOP   0

问题补充:
DB_no Int
 DB_addr_begin int
 Degree int
 Piw_addr int
 Time_base bool
 
 out
 Average int
 
 inout
 Mid  int
 result dint
 
 
 temp
 temp1  word
 temp2 dword
 temp3 dword
 temp4 dint
 temp5 dint
 temp6 word
 temp7 dword
 temp8 word
 temp9 dword
 temp10 int
 temp11 dword
 temp12 dint

地址定义如上,下载测试SF灯亮,不知道什么原因。

最佳答案

1、下载测试SF灯亮,不知道什么原因?
如果是程序运行时SF灯亮,从程序中看,一般问题会出现在地址指针寻址上。建议你采用单步跟踪的方法进行调试程序。调试程序要一部分一部分地加入程序,不要一股脑将程序全部投入,这样不便定位问题的所在。
2、关于滤波可以采用冒泡排序的方法,排序后取中间位置的数值即可。
如何实现冒泡排序(冒泡原理,学过语言的人都应该知道,如果不知道,请上网找一个吧,到处都是):
转帖:
假定十个数据,放在DB1中,安放顺序如下:
DBD0
DBD4

DBD36
下面是西门子的程序
OPN   DB    1                 /////打开DB1这个数据块
      L     10  ////装载10到MB0中,因为有十个数据,要进行十次排序,9次也可以的
LL0:  T     MB    0
      L     P#0.0   ////装载地址指针,这是关键,不要搞错了
      LAR1  
      L     9
LL1:  T     MB    2   ////内部循环,进行9次,直到把最大值排到最后
      L     DBD [AR1,P#0.0]
      L     DBD [AR1,P#4.0]
      <R    
      JC    LL2          ////比较前后两个值,如果前面大于后面的,则前后数据交换
      L     DBD [AR1,P#0.0]
      T     #m_temp
      L     DBD [AR1,P#4.0]
      T     DBD [AR1,P#0.0]
      L     #m_temp
      T     DBD [AR1,P#4.0]
LL2:  +AR1  P#4.0     ////指针自动进行加4,因为是浮点数,所以要跳过4个字节
      L     MB    2
      LOOP  LL1       ///这个指令自动的将A寄存器里的值减1
      L     MB    0
LOOP  LL0
3、参考相关文档:
《AD采集滤波算法》连接:
http://blog.chinaunix.net/u3/98807/showart_2015379.html
《模拟量信号采样滤波及STEP7语言的实现》连接:
http://wenku.baidu.com/view/8da0c4d4b9f3f90f76c61ba4.html
《有关采样滤波的编程》:
http://www.ad.siemens.com.cn/service/answer/solution.aspx?Q_id=56045&cid=1029

提问者对于答案的评价:
问题还没有解决。

原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc242860.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2018年12月1日
下一篇 2018年12月1日

相关推荐