Today, I’m going to show you how to connect an encoder to a PLC using a Siemens S7-200 series PLC as an example. This is a common scenario in industrial automation where encoders are used to measure position or speed. Here's a step-by-step explanation of the setup and programming involved.
The main goal is to set up a counter that triggers an output when a specific number of pulses is reached. In this example, the set value is 10. When the encoder sends 10 pulses, the system will stop. Let’s walk through the program logic:
First, we initialize the high-speed counter (HSC0). The control byte is set to 16#C8, which means the counter requires an initial value, does not load the preset value, and counts only in one direction. Then, we define the mode for HSC0 as mode 0. After that, we set the initial value of the counter to 0 and start the counter with the HSC instruction.
The next part of the program checks if the current count reaches the set value of 10. If it does, the system stops by resetting the output. The program also includes logic to reset the counter after each cycle so it can be used again. Here’s the code snippet:
LD SM0.1
MOVB 16#C8, SMB37
HDEF 0, 0
MOVD +0, SMD38
HSC 0
This section initializes the counter and sets the mode. Now, here’s how the system resets after reaching the target count:
LDN M14.0
EU
MOVB 16#C8, SMB37
MOVD +0, SMD38
HSC 0
When the count reaches 10, M14.0 is triggered, and the counter resets for the next cycle. Here’s how the comparison works:
LDD < HC0, +10
= M14.0
Finally, the start and stop logic is implemented using inputs I0.1 (start) and I0.2 (stop). The output Q0.0 is activated when the counter has reached the set value:
LD I0.1
O Q0.0
AN I0.2
A M14.0
= Q0.0
In summary, this setup allows the PLC to monitor encoder pulses and control a device based on the count. It’s a simple but effective way to manage motion control in automated systems. Whether you're working with encoders, counters, or PLCs, understanding these basics can help you build more complex and reliable automation solutions.
KW4-Basic Miniature Micro Switch
Features
â—† Small Compact Size,Global safety approvals
â—† Long life & high reliability.
â—† Wide Range of wires Terminals.
â—†Variety of actuator and terminals
â—†Customized Designs
â—†Widely used in household appliances, electric force, telecommunications, machine tool, vessel, textile, printing, Mining machine, Mustic Instrument, etc.
Micro Contact Switch,Mushroom Button Switch,3 Pin Micro Switch,Basic Miniature Micro Switch
Ningbo Jialin Electronics Co.,Ltd , https://www.donghai-switch.com