<!DOCTYPE html>
    <html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
    <head>
<title>Xử lý tín hiệu tương tự trong PLC S7 300</title>
<meta name="description" content="Xử lý tín hiệu tương tự trong PLC S7 300 - Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;giahungtech.com&#x002F;news&#x002F;savefile&#x002F;tin-tuc&#x002F;xu-ly-tin-hieu-tuong-tu-trong-plc-s7-300-8.html">
<meta name="author" content="CÔNG TY TNHH TỰ ĐỘNG HÓA GIA HƯNG TECH">
<meta name="copyright" content="CÔNG TY TNHH TỰ ĐỘNG HÓA GIA HƯNG TECH [mr.anhlv@gmail.com]">
<meta name="google-site-verification" content="gDGgLc4qBYy9_5H9NUfAy0BSdCWhxCiMIackhCSr2vg">
<meta name="msvalidate.01" content="171F162059CAB2E1BD9C86B5970FBF31">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index, archive, follow, noodp">
<meta name="msnbot" content="index, archive, follow, noodp">
<meta name="coccocbot-web" content="index, archive, follow, noodp">
<meta name="generator" content="TMS v4.5">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Xử lý tín hiệu tương tự trong PLC S7 300">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;giahungtech.com&#x002F;news&#x002F;savefile&#x002F;tin-tuc&#x002F;xu-ly-tin-hieu-tuong-tu-trong-plc-s7-300-8.html">
<meta property="og:site_name" content="CÔNG TY TNHH TỰ ĐỘNG HÓA GIA HƯNG TECH">
<meta property="og:image" content="https://giahungtech.com/uploads/plcnext_starterkit3.jpg">
<meta property="og:image:url" content="https://giahungtech.com/uploads/plcnext_starterkit3.jpg">
<meta property="og:image:type" content="image/jpeg">
<meta property="og:image:width" content="1280">
<meta property="og:image:height" content="720">
<meta property="og:url" content="https://giahungtech.com/news/savefile/tin-tuc/xu-ly-tin-hieu-tuong-tu-trong-plc-s7-300-8.html">
<link rel="shortcut icon" href="https://giahungtech.com/uploads/icon.ico">
<link rel="canonical" href="https://giahungtech.com/news/savefile/tin-tuc/xu-ly-tin-hieu-tuong-tu-trong-plc-s7-300-8.html">
<link rel="alternate" href="https://giahungtech.com/news/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://giahungtech.com/news/rss/dao-tao-ngan-han/" title="Tin Tức - Đào tạo ngắn hạn" type="application/rss+xml">
<link rel="alternate" href="https://giahungtech.com/news/rss/file-mau/" title="Tin Tức - File mẫu" type="application/rss+xml">
<link rel="alternate" href="https://giahungtech.com/news/rss/huong-dan/" title="Tin Tức - Hướng dẫn" type="application/rss+xml">
<link rel="alternate" href="https://giahungtech.com/news/rss/tin-tuc/" title="Tin Tức - Tin tức" type="application/rss+xml">
<link rel="preload" as="style" href="https://giahungtech.com/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="https://giahungtech.com/themes/default/css/bootstrap.min.css" type="text/css">
<link rel="preload" as="style" href="https://giahungtech.com/themes/default/css/style.css" type="text/css">
<link rel="preload" as="style" href="https://giahungtech.com/themes/default/css/style.responsive.css" type="text/css">
<link rel="preload" as="style" href="https://giahungtech.com/themes/default/css/news.css" type="text/css">
<link rel="preload" as="style" href="https://giahungtech.com/themes/default/css/custom.css" type="text/css">
<link rel="preload" as="style" href="https://giahungtech.com/themes/default/tms/css/swiper.css" type="text/css">
<link rel="preload" as="style" href="https://giahungtech.com/themes/default/css/tms_menu.css" type="text/css">
<link rel="preload" as="script" href="https://giahungtech.com/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="https://giahungtech.com/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="https://giahungtech.com/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="https://giahungtech.com/themes/default/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="https://giahungtech.com/themes/default/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="https://giahungtech.com/themes/default/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://giahungtech.com/themes/default/tms/js/swiper.js" type="text/javascript">
<link rel="preload" as="script" href="https://giahungtech.com/themes/default/js/tms_menu.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.googletagmanager.com/gtag/js?id=G-NTD0WQBV7B" type="text/javascript">
<link rel="preload" as="script" href="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1900612952327782" type="text/javascript" crossorigin="anonymous">
<link rel="preload" as="script" href="https://giahungtech.com/themes/default/js/bootstrap.min.js" type="text/javascript">
<link rel="stylesheet" href="https://giahungtech.com/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="https://giahungtech.com/themes/default/css/bootstrap.min.css">
<link rel="stylesheet" href="https://giahungtech.com/themes/default/css/style.css">
<link rel="stylesheet" href="https://giahungtech.com/themes/default/css/style.responsive.css">
<link rel="StyleSheet" href="https://giahungtech.com/themes/default/css/news.css">
<link rel="stylesheet" href="https://giahungtech.com/themes/default/css/custom.css">
<link rel="stylesheet" type="text/css" href="https://giahungtech.com/themes/default/tms/css/swiper.css">
<link id="theme" rel="stylesheet" type="text/css" media="all" href="https://giahungtech.com/themes/default/css/tms_menu.css" />
<style>
	body{background: #fff;}
</style>
<script data-show="inline">(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-70168873-1', '.giahungtech.com');
ga('send', 'pageview');
</script>
</head>
    <body>
<amp-auto-ads type="adsense"
        data-ad-client="ca-pub-1900612952327782">
</amp-auto-ads>
<script src="https://giahungtech.com/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4",nv_check_pass_mstime=59878000,nv_area_admin=0,nv_safemode=0,theme_responsive=1,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image";</script>
<script src="https://giahungtech.com/assets/js/language/vi.js"></script>
<script src="https://giahungtech.com/assets/js/global.js"></script>
<script src="https://giahungtech.com/themes/default/js/news.js"></script>
<script src="https://giahungtech.com/themes/default/js/main.js"></script>
<script src="https://giahungtech.com/themes/default/js/custom.js"></script>
<script type="text/javascript" src="https://giahungtech.com/themes/default/tms/js/swiper.js"></script>
<script type="text/javascript" src="https://giahungtech.com/themes/default/js/tms_menu.js"></script>
<script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Organization",
            "url": "https://giahungtech.com",
            "logo": "https://giahungtech.com/assets/images/logo.png"
        }
        </script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-NTD0WQBV7B"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag('js',new Date);gtag('config','G-NTD0WQBV7B');</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1900612952327782"
     crossorigin="anonymous"></script>
<script src="https://giahungtech.com/themes/default/js/bootstrap.min.js"></script>
</body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">CÔNG TY TNHH TỰ ĐỘNG HÓA GIA HƯNG TECH</h2>
		<p class="pull-right"><a title="CÔNG TY TNHH TỰ ĐỘNG HÓA GIA HƯNG TECH" href="https://giahungtech.com/">https://giahungtech.com</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Xử lý tín hiệu tương tự trong PLC S7 300</h1>
		<ul class="list-inline">
			<li>Thứ sáu - 17/09/2021 13:07</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
			Khi mới làm quen với PLC có lẽ mọi người cũng giống mình, luôn thắc mắc làm sao để đọc tín hiệu analog đầu vào và hiển thị lên màn hình? nó sẽ xử lý ra sao, viết hàm nhứ thế nào, rồi các module vvvv nói chung là rất nhiều câu hỏi đặt ra. Có nhiều bạn thậm chí đã lập trình rồi cũng không hiểu sao nó lại như vậy, thậm chí đọc help của Siemens lại càng không hiểu khi họ cho cái hàm, ví dụ hàm scale trong S7-300 FC105 lại càng khó hiểu hơn....
		</div>
				<div class="imghome">
			<img alt="Xử lý tín hiệu tương tự trong PLC S7 300" src="https://giahungtech.com/uploads/news/2016_08/1472611177.png" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<b>1. Tín hiệu Analog input</b><br />
Vậy nhưng nếu các bạn không cần lập trình mà chỉ cần dùng cái hàm này thì gia trị ra sẽ đúng. chỉ cần các bạn biết dùng thì không có gì là sai cả vì Siemens đã có các chuyên gia nghiêm cứu cái này rồi đó. Mình chép nguyên cái phần help cua Step 7 Manager ra đây nhé.<br />
<br />
<br />
<b>Lưu ý: Ở đây mình viết cho S7-300/400 nhưng với S7-200/1200/1500 cũng làm tương tự nhé</b><br />
The SCALE function takes an integer value (IN) and converts it to a real value in engineering units scaled between a low and a high limit (LO_LIM and HI_LIM). The result is written in OUT. The SCALE function uses the equation:<br />
<br />
<b>OUT = &#91; ((FLOAT (IN) – K1)/(K2–K1)) * (HI_LIM–LO_LIM)&#93; + LO_LIM</b><br />
<br />
The constants K1 and K2 are set based upon whether the input value is BIPOLAR or UNIPOLAR.<br />
<br />
·BIPOLAR: The input integer value is assumed to be between –27648 and 27648, therefore, K1 = –27648.0 and K2 = +27648.0<br />
<br />
·UNIPOLAR: The input integer value is assumed to be between 0 and 27648, therefore, K1 = 0.0 and K2 = +27648.0<br />
<br />
If the input integer value is greater than K2, the output (OUT) is clamped to HI_LIM, and an error is returned. If the input integer value is less than K1, the output is clamped to LO_LIM, and an error is returned.<br />
<br />
Reverse scaling can be obtained by programming LO_LIM &gt; HI_LIM. With reverse scaling, the value of the output decreases as the value of the input increases.<br />
<br />
Điều đặc biệt mình muốn các bạn chú ý là phần tô đậm màu xanh trong hàm trên. Đây chính là công thức mà Siemens áp dụng cho mọi module để đọc tín hiệu analoge của mình. Nếu như tín hiệu vào có đảo cực ví dụ từ -10V đến +10V ... thì set bipolar bằng 1 (tức là cho một bit nào đó bằng 1 rồi gán cho đầu vào này của FC105 là xong. Ở đây có cái hằng số K1, K2 là hằng số maximum mà module analog của Siemens có thể xử lý nên người ta đã viết cho dạng maximum.&nbsp;<br />
<b>Như vậy chương trình có sẵn của Siemens không phải lúc nào cũng tối ưu cho nên tất cả các chương trình của mình về tính toán Analog vì độ phân giải của module không giống nhau và có thể có những ứng dụng không cẩn Scale K1,2 là 27648 do vậy mình đầu viết lại để được tối ưu hơn. Mời các bạn tham khảo chương trình sau nhé.</b><br />
<br />
<b>&quot;Chương trình tối ưu hóa cho tính toán Analog được viết bởi Admin của vocsy&quot;</b><br />
<br />
Ở đây thay thế công thức của Siemens bằng công thức:<br />
<br />
<b>Out=((Raw-Raw_Min)*(Scale_Max-Scale_Min))/(Raw_Max-Raw_Min) + Raw_Min&nbsp;</b><br />
<br />
Ở đây ta có:<br />
Raw: là giá trị đọc được từ đầu vào Input module<br />
Raw_Max: là giá trị lớn nhất module có thể đọc được hoặc là mình muốn cho nó đọc. (Ở trên Siemens nói là từ nhỏ hơn 27648 đó, chính là giá trị lớn nhất mà module analog có thể xử lý được).<br />
Raw_Min: Là giá trị nhỏ nhất mà module có thể đọc.<br />
Scale_Max: Chính là giá trị lớn nhất mà mình mong muốn thực tế hay chính là giá trị Engineering đó. Chẳng hạn đây là fias trị nhiệt độ, áp suất thực tế ....<br />
Scalmin: là giá trị engineering nhỏ nhất.<br />
<br />
Chương trình được viết dưới dạng chương trình con để thuận tiện dùng:<br />
// Convert from interger to Real<br />
L #Raw<br />
ITD<br />
DTR<br />
T #_Raw_R<br />
L #Raw_Min<br />
ITD<br />
DTR<br />
T #_Raw_Min_R<br />
L #Raw_Max<br />
ITD<br />
DTR<br />
T #_Raw_Max_R<br />
// Calculation<br />
// Raw - Raw_Min<br />
L #_Raw_R<br />
L #_Raw_Min_R<br />
-R<br />
T #_temp_real<br />
<br />
// Scale_Max - Scale_Min<br />
L #Scale_Max<br />
L #Scale_Min<br />
-R<br />
//(Raw - Raw_Min) * (Scale_Max - Scale_Min)<br />
L #_temp_real<br />
*R<br />
T #_temp_real<br />
<br />
// Raw_Max - Raw_Min<br />
L #_Raw_Max_R<br />
L #_Raw_Min_R<br />
-R<br />
T #_temp_real2<br />
//(Raw - Raw_Min) * (Scale_Max - Scale_Min) / (Raw_Max - Raw_Min)<br />
L #_temp_real<br />
L #_temp_real2<br />
/R<br />
//(Raw - Raw_Min) * (Scale_Max - Scale_Min) / (Raw_Max - Raw_Min) + Scale_Min<br />
L #Scale_Min<br />
+R<br />
T #_Output<br />
Đây là chương trình được rút gọn vì thực tế mình còn thêm vài cái limit cho nó nữa. Các bạn cứ tham khảo chương trình này, nếu cần liên hệ admin sẽ tận tình chỉ thêm cho.<br />
Chương trình cụ thể đầy đủ xem hình đính kèm.<br />
Và đây là hình ảnh chương trình mẹ gọi chương trình con trên thực thi<br />
<img alt="analog 2 png" height="857" src="https://giahungtech.com/uploads/news/2016_08/1472611177.png" width="861" />
		</div>
				<div id="author">
						<p>
				<strong>Tác giả:</strong>
				<a href="https://giahungtech.com/news/author/admin/">admin</a>
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://giahungtech.com/news/savefile/tin-tuc/xu-ly-tin-hieu-tuong-tu-trong-plc-s7-300-8.html" title="Xử lý tín hiệu tương tự trong PLC S7 300">https://giahungtech.com/news/savefile/tin-tuc/xu-ly-tin-hieu-tuong-tu-trong-plc-s7-300-8.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; CÔNG TY TNHH TỰ ĐỘNG HÓA GIA HƯNG TECH
		</div>
		<div id="contact">
			<a href="mailto:mr.anhlv@gmail.com">mr.anhlv@gmail.com</a>
		</div>
	</div>
</div>

     <head>
      </head>     
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://giahungtech.com/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
    </body>
</html>