24
© www.thaicontrol.wordpress.com 120 บทที 11 Digital Encoder เป็นอุปกรณ์บอกองศาการหมุน (ตําแหน่งเชิงมุม) โครงสร้างภายในประกอบด้วย 1) เพลา (Shaft) เป็นแกน หมุนต่อเข้ากับอุปกรณ์ 2) แผ่นดิสก์ (Disc หรือ Slit ) เป็นแผ่นทีเจาะเป็นแถบเล็กๆให้แสงผ่านได้ 3) Photo detector ใช้รับแสงสําหรับแปลงเป็นรหัสข้อมูล 4) LED ใช้เป็นแหล่งกําเนิดแสง ส่องผ่านเลนส์ (Convex lens) ให้ลําแสงส่องผ่านแถบเล็กๆ บน Disc (รูปจาก Rockwell Automation) Digital Encorder โดยทัวไปแบ่งได้ 2 ชนิดคือ Incremental Encoder และ Absolute Encoder Incremental Encoder บอกองศาการหมุน (ตําแหน่งเชิงมุม) ในรูปของสัญญาณพัลส์สีเหลียม ความละเอียด(Resolution) ของ Encoder ขึนอยู ่กับจํานวนพัลส์ต่อหนึงรอบการหมุน เรียกว่า Pulse per revolution (PPR) Incremental Encoder มีค่า PPR มาก ยิงมีความละเอียดสูง เราสามารถทราบตําแหน่งเชิงมุมได้จากการนับจํานวนพัลส์ โดยใช้การ์ด Counter เทียบกับ PPR โดยทัวไป Encoder ชนิดนีมีสัญญาณ Output อยู ่ 2 สัญญาณl คือ A และ B ซึงมีเฟสต่างกัน 90 องศา แต่ บางรุ่นได้เพิมสัญญาณตอนหมุนครบรอบ เรียกว่า “Markerหรือ Channel Z เข้ามาด้วย

บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 120

บทท� 11 Digital Encoder เปนอปกรณบอกองศาการหมน (ตาแหนงเชงมม) โครงสรางภายในประกอบดวย 1) เพลา (Shaft) เปนแกนหมนตอเขากบอปกรณ 2) แผนดสก (Disc หรอ Slit ) เปนแผนท�เจาะเปนแถบเลกๆใหแสงผานได 3) Photo detector ใชรบแสงสาหรบแปลงเปนรหสขอมล 4) LED ใชเปนแหลงกาเนดแสง สองผานเลนส (Convex lens) ใหลาแสงสองผานแถบเลกๆ บน Disc

(รปจาก Rockwell Automation)

Digital Encorder โดยท�วไปแบงได 2 ชนดคอ Incremental Encoder และ Absolute Encoder Incremental Encoder บอกองศาการหมน (ตาแหนงเชงมม) ในรปของสญญาณพลสส�เหล�ยม ความละเอยด(Resolution) ของ Encoder ข �นอยกบจานวนพลสตอหน�งรอบการหมน เรยกวา Pulse per revolution (PPR) Incremental Encoder มคา PPR มาก ย�งมความละเอยดสง เราสามารถทราบตาแหนงเชงมมไดจากการนบจานวนพลสโดยใชการด Counter เทยบกบ PPR โดยท�วไป Encoder ชนดน �มสญญาณ Output อย 2 สญญาณl คอ A และ B ซ�งมเฟสตางกน 90 องศา แตบางรนไดเพ�มสญญาณตอนหมนครบรอบ เรยกวา “Marker” หรอ Channel Z เขามาดวย

Page 2: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 121

(รปจาก Rockwell Automation)

ตวอยาง การอานคาองศาจาก Incremental Encoder ดวยการด High Speed Counter (1756-HSC)

สายสญญาณของ Incremental Encoder แบบ Differential จะตอเขากบอนพต A(+),A(-),B(+),B(-) และ Z(+),Z(-) ของการด High speed counter แตถาเปน encoder แบบ Single End สญญาณ A(-),B(-) และ Z(-) จะรวมกนรวมเขากบ Com (-) แทน ดงรปดานลาง

(ตอแบบ Differential รปจาก Rockwell Automation)

Page 3: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 122

(ตอแบบ Single End รปจาก Rockwell Automation)

Add High Speed Counter Module 1) คล�กขวาท� I/O Configuration ->New Module -> Add การด High Speed Counter 1756-HSC

2) คล�กแทบ General จากน �นกรอกขอมลตางๆใหถกตอง แลวคล �ก OK Name – ช�อการด Slot – หมายเลข Slot ท�การดตดต �งอย Description – ปอนคาอธบายของการด Comm Format – เลอกชนดการเช�อมตอกบการดใหเลอกเปน HSC Data

3) กาหนดคา RPI (Requested Packet Interval) ในแทบ Connection แลวคล �ก OK

Page 4: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 123

Requested package interval (RPI) – เวลาสงขอมล (คาพลสท�นบได) จากหนวยความจาของการด ออกไปยง Controller

4) คล�กแทบ Counter Configuration จากน �นกรอกขอมลตางๆใหถกตอง แลวคล �ก OK Operational Mode – กาหนดวธการนบพลสท�สงมาจาก Encoder เชนโหมด X1 จะนบข �นเม�อสญญาณจาก B นาหนาสญญาณจาก A อย 90 องศา และนบลงเม�อสญญาณจาก A นาหนาสญญาณจาก B อย 90 องศา

(รปจาก Rockwell Automation)

สวนโหมด X4 การทางานเหมอนกบโหมด X1 ยกเวนนบพลสท�ขอบขาข �นและขาลงของสญญาณ A และ B ทาใหไดความละเอยดมากกวาโหมด X1 ถง 4 เทา

Page 5: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 124

(รปจาก Rockwell Automation)

Storage Mode – เลอกวธในการเกบคาพลลท�นบไดลงใน Present Value Tag ของ Controller โดยอาศยสญญาณ Z (Gate/Reset) เปนตว trigger แบงยอยได 4 แบบ คอ

· Store and Continue Mode – คา Present Value Tag เทากบ Incoming Pulses วธน �ใชกบ Incremental Encoder

(รปจาก Rockwell Automation)

· Store, Wait, and Resume – คา Present Value Tag จะคงคาเทากบคา Stored Tag ในชวงท�ม

อนพตของสญญาณ Z (Wait) หลงจากน �น คา Present Value Tag กลบมาอพเดจตามเดม (Resume) วธน �ใชเม�อตองการใหนบในชวงท�กาหนดเทาน �น

(รปจาก Rockwell Automation)

Page 6: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 125

· Store and Reset, Wait, and Start– คา Present Value Tag จะถกรเซตเปนศนยเม�อมอนพตของสญญาณ Z (Reset) รอจนส �นสดสญญาณ Z (Wait) จงกลบมาเร�มนบใหม (Start) วธน �ใชเม�อตองการใหนบเปนรอบๆ ตามท�กาหนด

(รปจาก Rockwell Automation)

· Store and Reset, and Start– คา Present Value Tag จะถกรเซตเปนศนยเม�อมอนพตของสญญาณ Z (Reset) แลวกลบมาเร�มนบใหม (Start) ทนท

Rollover – กาหนดจานวนพลสสงสดเลอกวธในการเกบคาพลล ถาคาท�นบไดเกนคาน � Counter จะถกรเซตเปนศนยแลวเร�มนบใหมอกคร �ง

5) คล�กแทบ Output Configuration จากน �นเลอก Output ของการดท�ตองการสงสญญาณไปใหอปกรณภายนอกเม�อคาของCounter ตรงตามท�กาหนด (จะใชงานหรอไมกได) เสรจแลวคล �ก OK

Page 7: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 126

6) หลงจากคอนฟก High Speed Counter การดเสรจแลว เราสามารถอานพารามเตอรและคาท�นบไดผาน Output Tag ของการดไดโดยตรง คาพลสจาก Encoder จะเกบอยใน Tag Present Value

(รปจาก Rockwell Automation)

Page 8: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 127

7) เขยนโปรแกรมดงรปดานลาง

Page 9: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 128

Absolute Encoder บอกองศาการหมน (ตาแหนงเชงมม) ในรปของรหสแบบตางๆ เชน Binary,BCD และ Gray code แตละองศาใหคาสมบรณไมซ �ากน ขอดของ Absolute Encoder คอ ไมตองใช Counter นบพลสเพ�อคานวณหาคาองศาและในกรณแหลงจายไฟเกดขดของ Absolute Encoder ยงคงใหคาตาแหนงเดมไดหลงจากแหลงจายไฟกลบมาเปนปกต แตกตางกบ Incremental Encoder ท�ตองเคล�อนไปยงตาแหนง Home กอนเสมอ ความละเอยด(Resolution) ของ Encoder ข �นอยกบจานวนบตของ Output เชน 8 bits, 10 bits หรอ 24 bits เปนตน

(รปจาก Rockwell Automation)

Absolute Encoder สวนมากนยมใชแบบ Gray code โดยสามารถตอ Encoder เขากบ Digital Input Card ของ ControlLogix PLC ไดเลย แลวเขยนโปรแกรมเพ�อแปลงคาองศาจาก Gray code เปน Binary code โดยอาศยหลกการของ XOR ดงรป

Page 10: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 129

ถา Resolution ของ Encoder เทากบ 2 ยกกาลงจานวนบตเอาทพต คา 0 องศาจะเร�มตนท�คา 0 ในหนวย Binary เสมอ แตถา Resolution ของ Encoder ไมเทากบ 2 ยกกาลงจานวนบตเอาทพต คา 0 องศาจะเร�มตนท�คาอ�นดงตารางดานลาง

(รปจาก Automationdirect)

Page 11: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 130

ตวอยาง การอานคาองศาจาก Absolute Encoder ไปใชควบคมการทางานของเคร�องจกร

1) Add I/O การดใน I/O Configuration ของโปรเจคไฟล

2) คอนฟกการด Digital Input ใหถกตอง ดงรปดานลาง

Page 12: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 131

3) สราง Tag สาหรบใชงานตามท�กาหนด

Page 13: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 132

4) สราง New Routine ช�อ CAM_Position และ Gray_Binary_Conversion โดยรทน Gray_Binary_Conversion ใชสาหรบแปลงคาองศาจาก Gray code เปน Binary code สวน CAM_Position ทาหนาท�กาหนด Position Bit ของ Master Shaft ท�องศาตางๆกนแลวนาไปเขยนโปรแกรมส�งงานอปกรณ

5) เร�มเขยนโปรแกรมในรทน Gray_Binary_Conversion และ CAM_Position ดงรปดานลาง Gray_Binary_Conversion Routine

Page 14: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 133

Page 15: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 134

CAM_Position Routine

Page 16: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 135

Page 17: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 225

บทท� 16 Excel to ControlLogix Tags

ขอมล (Tag) ของ ControlLogix PLC ภายใน Controller สามารถนามาแชรใหกบโปรแกรมอ�นไดโดยผานซอรฟแวรท�ทาหนาท�เปน DDE/OPC Server เชน RSLink เปนตน

Dynamic Data Exchange (DDE) คอมาตรฐานในการตดตอส�อสารระหวางโปรแกรมบนระบบปฏบตการ Windows การแลกเปล�ยนขอมลจะเกดข �นได ตองประกอบดวย 3 สวนคอ

1) Application คอ โปรแกรมท�ตดตอดวย 2) Topic คอ กลมท�ขอมลอย 3) Item คอ ขอมลท�ตองการ

นอกจากน �ยงแบงตามชนดของการเช�อมตอได 2 วธคอ Hot Link คอ โปรแกรมเช�อมตอผาน Dynamic Data Exchange (DDE) ตลอดเวลา ใชสาหรบอานขอมลไดอยางเดยว (Read only) Cold Link คอ โปรแกรมเช�อมตอผาน Dynamic Data Exchange (DDE) เฉพาะเวลาท�กาหนดหรอตามเหตการณท�เกดข �น ใชไดท �งอานและเขยนขอมล (Read/Write) ข �นตอนการเช�อมตอ ControlLogx PLC กบ Excel แบบ Hot Link 1) รนโปรแกรม RSLink คล�กเมน File-> Open Project

Page 18: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 226

2) คล �กป ม New จากน �นพมพช�อโปรเจคท�ตองการ (ในตวอยางน �ต �งช�อวา CLX_Link) เสรจแลวคล�ก OK

3) คล �กเมน DDE/OPC จากน �นเลอก Topic Configuration

4) คล �กป ม NEW แลวต �งช�อ Topic (ในตวอยางน �ต �งช�อวา CLX_DATA) จากน �นใหคล�กท� ControlLogix PLC บนแทบ Data source

Page 19: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 227

5) คล �กแทบ Data Collection เลอก Processor Type เปน Logix5000 และเลอก Data Collection Modeเปน Polled Message พรอมท �งกาหนด Polled rate เทากบ 1000 msec

6) คล �กแทบ Advance Communication เลอก RSLinx Driver ท�เช�อมตอกบ ControlLogix PLC Processor เสรจแลวคล�กป ม Done

Page 20: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 228

7) คล �กเมน Edit จากน �นเลอก Copy DDE/OPC Link

8) คล �ก Topic ท�เราสรางข �นฝ�งซายมอแลวเลอก Item (Tag) ท�ตองการในฝ�งซายมอ จากน �นคล�ก OK ลงคของขอมลจะถกกอบป�ลง Clipboard

Page 21: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 229

9) เปดโปรแกรม Excel คล�กขวาบน Cell ท�ตองการวางขอมล จากน �นคล�ก Paste Special แลวเลอก Paste link แบบ Unicode Text เสรจแลวคล �ก OK

10) ขอมลจาก ControlLogix PLC จะแสดงข �นมาใน Cell ท�เลอกไว

Page 22: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 230

ข �นตอนการเช�อมตอ ControlLogx PLC กบ Excel แบบ Cold Link

1) เปดโปรแกรม Excel เปล�ยนช�อแผนงานจาก Sheet1 เปน DDE_Sheet โดยดบเบ �ลคล�กตรงแทบ Sheet1 แลวพมพช�อใหมลงไป

2) คล �กเมน View -> Toolbars -> Control Toolbox เพ�อเรยกหนาตางเคร�องมอข �นมา

3) คล �กป มกด (Command Button) ในหนาตางเคร�องมอ แลวนามาวางบน Sheet 2 ป มดวยกน

4) คล �กขวาท�ป มกดท�สรางข �นแลวเลอก Properties

Page 23: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 231

5) เปล�ยนช�อป มกดเปน btnWriteData/btnReadData ในชอง Name และเปล�ยนแสดงขอความบนป มเปน Write Data/Read Data ในชอง Caption เสรจแลวใหปดหนาตาง Properties โดยคล�กกากบาทมมบนขวามอ

6) คล �กขวาท�ป มกด Write Data แลวเลอก View Code

7) พมพคาส�งเขยนขอมลจาก Cell D7 ลงไปท� Data_DINT[4] ของ ControlLogix PLC เม�อมการกดป ม

Page 24: บทที11 Digital Encoder · Add High Speed Counter Module 1) คลิกขวาที I/O Configuration ->New Module -> Add การ์ด High Speed Counter 1756-HSC 2)

© www.thaicontrol.wordpress.com 232

8) คล �กขวาท�ป มกด Read Data แลวเลอก View Code

9) พมพคาส�งอานขอมลจาก Data_DINT[5] ของ ControlLogix PLC มาท� Cell F7 เม�อมการกดป ม

10) ออกจากโหมด Design โดยคล�กป ม Exit Design Mode ในหนาตางเคร�องมอ

11) ปอนคาลงใน Cell D7 แลวกดป ม Write Data ขอมลจะถกสงไปยง Data_DINT[4] ของ ControlLogix PLC จากน �นกดป ม Read Data ขอมลใน Cell F7 จะรบมาจาก Data_DINT[5] ของ ControlLogix PLC ดงรป