请教!!!下面的模拟滤波子程序,每次扫描它调用一次,没懂它为啥要左移4,右移四位,??他的注释说乘采样次数,请讨论!!!!

已锁定

Forver

  • 帖子

    42
  • 精华

    0
  • 被关注

    0

论坛等级:新手

注册时间:2003-06-06

普通 普通 如何晋级?

请教!!!下面的模拟滤波子程序,每次扫描它调用一次,没懂它为啥要左移4,右移四位,??他的注释说乘采样次数,请讨论!!!!

1203

8

2003-07-23 18:47:51

network1 Initialization of the Average and the Running Sum
LD First_Scan_On:SM0.1 // Load SM0.1.
MOVD +0, VD154 // Clear the workspace.
MOVD +0, VD158 // Clear the running sum.
MOVD +0, VD162 // Clear the running average.
network2 Compute the Difference between the New Value and the Average Value
LD Always_On:SM0.0 // Load SM0.0.
MOVW +0, VW154 // Clear the most significant
// word of the workspace.
MOVW AIW0, VW156 // Get the sampled AI value and
// put it in the scratchpad area.
-I VW164, VW156 // Compute the difference between
// the previous average and the
// new value and put the result
// in VW156.
network3 If New Value and Average Value Differ Greatly, Save the Last Sample
LDW>= VW156, +320 // If the difference between
// the new value and the average
// value is greater than or equal
// to 320 counts,
OW<= VW156, -320 // or if it is less than or equal
// to -320 counts,
+I VW164, VW156 // compute the last sample value
// without reading the analog input
// again
MOVW VW156, VW160 // and save the last sample.
LPS
A V160.7 // If the sample is negative,
MOVW 16#FFFF, VW158 // extend the sign to a double
// word value.
LPP
SLD VD158, 4 // Multiply this sample by the
// number of samples to produce
// a running sum.
MOVW +0, VW156 // Zero the difference between
// the new value and the previous
// value.
network4 If the Result Is Negative, Sign Extend the Difference
LD V156.7 // Read the sign bit of the new
// AI (WORD) value.
MOVW 16#FFFF, VW154 // If it is negative, extend the
// sign to make the entire DWORD
// negative.
network5 Compute and Output the Average Value, or Process an Error Condition
LDN Mod_0_IO_3:SM8.3 // If an analog input module is
// present
AN Mod_0_IO_2:SM8.2
NOT
AN Mod_0_Present:SM8.7
A Mod_0_IO_Type:SM8.4
AB= Mod_0_Error:SMB9, 0 // and no module error is detected,
+D VD154, VD158 // update the running sum.
MOVD VD158, VD162 // Move the sum into the location
// for the running average,
SRD VD162, 4 // shift the DWORD right by 4 bits
// [ln(SampleSize) / ln(2)] bits,
// (same as SUM / SampleSize),
MOVW VW164, VW166 // and move the averaged value to
// the filtered output.
NOT // If the module is not an analog
// module or a module error was
// detected,
= Q0.2 // set the analog input module
// error bit.
network6 end the subroutine
请教!!!下面的模拟滤波子程序,每次扫描它调用一次,没懂它为啥要左移4,右移四位,??他的注释说乘采样次数,请讨论!!!! 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC S7-200

共有33289条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。