शैडोइंग अभ्यास: PLC Programming #4: Functions, Function Blocks & Organization Blocks Explained - वीडियो के साथ अंग्रेजी बोलना सीखें

पाठ बनाया जा रहा है...
1
Hello and welcome back to the channel.
2
In today's video we'll be continuing our PLC tutorial series by looking at functions, function blocks and data blocks, and organization blocks.
3
The basic structure of how you create a large PLC program.
4
So of all the videos that we've done so far, this is the first one where much of what I'm saying will be Siemens specific
5
and there are a few other equipment manufacturers that use a similar structure to Siemens.
6
And there are some So I will try to call out what those differences are.
7
Broadly speaking, the topics will still apply to both and more universally any PLC that you're writing code for.
8
But some of the specific syntax will be Siemens specific in this tutorial.
9
Let's start from organization block.
10
The basic thing when you create a new PLC program, whether you're in Allen Bradley,
11
Rockwell or Siemens, you're going to be given main and it's going to be this special kind of
12
special kind of routine on both platforms.
13
Main is the PLC's main object loop.
14
It is the start here and go as fast as you can by default thing for both PLCs.
15
So if you remember or if you've seen the how PLCs work video that I published on my channel,
16
you'll know that we can go into a PLC and we can see how fast it's doing cycles.
17
That's this cycle time or scan time depending on what
18
scan of the PLC logic every millisecond
19
so that's a thousand times per second the longest one it's had is two milliseconds
20
and that was probably on boot so by default any code
21
that we drop in main is going to be getting processed as fast as the PLC can so
22
if we do just the very simplest piece of code we
23
could do to reorient everyone I have two input push buttons and one output light hooked up with.
24
If I just basically said, hey, when I push this button, I want this light to turn on,
25
I can put that in main main is a spot where you can technically write code.
26
But as we're going to talk about next, organizationally, you don't really want to put any functional code in main, all you want to do is call functions
27
and function blocks from main for almost any system that's going to be more than a few lines of code long.
28
So I put that code in and now I can push the start
29
and I can see the light turn on in the field.
30
So this is functional code.
31
But when you get to dozens or hundreds or thousands of IO points in a system, you don't want to put that stuff in main.
32
Instead, you want to create a new block, and here's where you need to decide between functions and function blocks.
33
And the number one thing I'm going to say the difference between functions and function blocks is, is memory.
34
Functions process things every scan, and then they make decisions about outputs, use them to calculate math and scale variables,
35
but they're not retaining anything in memory.
36
They don't have anywhere to store calculations in math that they did in the intermediate.
37
So functions are instantaneous.
38
So we'll just make an example function here
39
and we're going to replace this line of code in main
40
which is an organization block we're going to get rid of this
41
and instead we're going to call the example function
42
so this is the main loop saying all right go do this function
43
and then in this function we're going to evaluate here
44
and we're actually going to say okay
45
when I press the start button let's get rid of this momentary coil
46
and say when I press the start button set the light on and let's add a second rung of code
47
the stop push button, reset the light or turn it off.
48
Okay, so we've got this little function that says when the first button is pressed, turn that light on.
49
When I've got the second button, turn that light back off.
50
And then from main, which is my organization block, I'm saying, okay, call that function every scan of the cycle time.
51
Here you can see If I had hundreds of functions,
52
this main organization block can still stay fairly organized because all it's doing is calling specific functions in specific orders.
53
And if I had a function for every valve or every group of valves or every pump or every motor, it's still going to be pretty neat from the main organization block to go
54
and just see what gets called and in what order.
55
doing.
56
And they're very focused on a small subset of groups and functions.
57
So we'll go ahead and we'll download this real quick.
58
Okay, and now when I'm looking at main, I just see that the example function is lit up green, meaning it's getting called.
59
And if I go into example function, and I start monitoring it, I can see that the energy right is highlighted left here is green, and it's making it to these buttons.
60
So if I hold down the start button, and then release it, I've got the it resets it and it turns the light off.
61
So my function is working great.
62
And main, my organization block is calling that function.
63
Now, there's two other types of organization block we're going to touch on super quickly.
64
And then there's actually a lot more types of organization block, but they're a little more niche and nuanced.
65
So it's not really worth a high level overview covering them.
66
But if I go to organization block, I'm going to make one called startup.
67
And there's actually a block in Siemens called startup.
68
Alan Bradley, like I said, they don't have a special organization block for startup.
69
They have a bit that's like S colon FS, and it's a little different.
70
Logix 500 versus 5000, but they have a way to say, do this only on first scan is what they call it.
71
But the idea is the same.
72
Run this cycle of code exactly once when it starts up.
73
And the reason you might put in a certain state when they start up.
74
So like if I put the light here and I said, okay, the first time this code runs, I actually want that light to turn on because by default,
75
I'd like the light to be on until I come in and press the button to turn it off.
76
This is a spot where I could say right when the PLC boots up, turn that light on, but then it's going to stop getting called after that because it only runs on startup.
77
Similarly, one other type of organization block I here before we move on.
78
And you can actually see here a list of all the organization blocks that sort of come with TIA Portal.
79
But the other one I want to talk about is cyclic interrupt.
80
So you can have stuff that does not check that absolute as fast as the PLC can process, which is like every millisecond.
81
Here I can say, actually, I only want it to check 10 times a second.
82
So every hundred milliseconds or every half second.
83
So 500 milliseconds.
84
I can define how frequently I want
85
have issues with blipping sensors or things that happen way too frequently
86
and it's just creating noise for your program
87
or it's a little bit more processor intensive and
88
so it's actually harder for the plc to process it super
89
frequently things like pid loops have to go in cyclic interrupt blocks
90
because you can't update a pid a thousand times per second
91
and expect the the devices in the field to actually respond to that
92
so a cyclic interrupt is where you could say like okay
93
now I'm going to maybe get rid of the example function code where the stop push button is turning the light off.
94
And instead, I'm going to put this in cyclic interrupt, which means it's possible I'll have to hold that stop push button down for between, you know, one and 500 milliseconds,
95
depending on where in the scan cycle I am.
96
So I could drop this in the cyclic interrupt and delete it from example function.
97
And now I'm going to go ahead and download this.
98
What you'll notice is organization blocks, I did not have to add to main because organization blocks have rules about when they get called by default,
99
but you don't have to do anything special to make sure they get called.
100
Half second we made to get called every 500 milliseconds, and startup is going to get called when we boot the PLC up.
101
So I'm going to download this and a recap of everything we should have happen.
102
We're going to go ahead and continue.
103
We're going to have to restart the PLC, and we should have the light turn on.
104
and then we should be able to hold down the stop push button
105
and that'll make it turn off but
106
if I just click the stop push button we're not necessarily guaranteed to have the light turn off.
107
Okay so I can sit here and I can click the stop push button momentarily
108
and it's not turning the light off by default
109
because sometimes I'm clicking it way too fast but
110
if I hold it down I make sure that it gets scanned in
111
that half millisecond time and that actually gets it to turn off.
112
Okay so
113
an introduction to uh organization blocks right we have a startup one
114
that puts that light
115
or pumps valves motors devices in startup state whatever you want them to default to
116
when you first boot a system up main organization block is where we call all the functions
117
and function blocks that we want to have scan every loop of the plc
118
and you can use cyclic interrupts for things we've started covering functions a little bit,
119
let's go ahead and do a little bit more, right?
120
We can do something beyond just check if button pressed and set light on.
121
Something like a very common thing might be scaling a analog value.
122
So if we had a value that was coming in raw from a PLC, zero to 27 ,648, you know,
123
basically an unscaled electrical signal on an IO card, take our raw input
124
and we'll we'll make one up for this it's not a wiring lesson let's go ahead
125
and define a global memory word let's say word
126
and it's going to be an integer okay and let's just say
127
that we have this raw input coming in
128
and we want to divide it by 27 ,678 like I said 27 ,648 sorry it by 100.
129
So this is basically like a very simple scaling function.
130
Allen Bradley, they will call these compute blocks instead of calculate blocks.
131
But the idea is the same, you can take this input one, you can divide it by what's your max span of the unprocessed signal.
132
And then you can multiply it by 100.
133
So you're basically getting a zero to 100 value, not by 100 by input three.
134
There we go.
135
in another tag that we'll call scaled input.
136
OK, and we'll define that as a global memory as well.
137
and that'll be the next integer.
138
Okay.
139
All right.
140
So this is a good example of something you might use a function block for.
141
There's no need to store this in memory because it's something that's getting calculated every scan of the PLC.
142
So if you had a temperature here that's constantly fluctuating, you want to recalculate what the scaled input is every scan of the PLC.
143
One other little syntactic thing it's important to call out is because this is calculating an integer, right?
144
We made that a word.
145
So it's not a real, it's not capable of holding decimal points.
146
We actually want the internal math to be done as reals.
147
And Alan, Siemens does this really nice thing with the indicated with these little squares that it's doing implicit type changing.
148
So it's taking an integer value, it's converting it to a real, it'll do real math, and then I'll convert it to an integer on the outset.
149
Not every PLC platform does that.
150
So, you know, if this was just an
151
be doing this in one divided by into and then rounding to the nearest integer.
152
But the whole point of this is it's taking something
153
that could be up to 27 ,000 scaling it back
154
and then multiplying by 100 to basically get a zero to 100 % percentage.
155
So we want to calculate a real just a little bit of PLC programming fun there for everybody.
156
And let's go ahead and send that live.
157
Basically now input is 59.
158
But if this was some device in the field and oh, it saw a pressure spike or a temperature spike and goes up to 1800, it gets recalculated as a 65.
159
So scaling of analog values is a really great example of something where a function does everything you'd need it to do.
160
There's no need for function blocks here because that's an instantaneous calculation
161
that you want to have done every scan of the PLC.
162
So that's a decent explanation, I think, of functions.
163
Now do want function blocks.
164
But the most important use case is to keep in mind, do I want memory?
165
Do I want something that gets stored and retained between cycles?
166
Pretty simple analogy that I've seen before and had explained to me before is a function is like a vending machine.
167
You walk up, you put in money, you get whatever you ordered out.
168
And a function block is kind of like a bartender where they remember your favorite order
169
and you can walk in and they remember what you got making you your regular.
170
So if you're an analogies person, maybe that helps.
171
But let's use an example of let's say I had not just one light hooked up, but let's go ahead into PLC tags and say I had two lights hooked up.
172
Or, you know, really, you can put yourself in the shoes of like, hey, maybe I have hundreds or thousands of devices in my system.
173
So I have so many pumps or motors or valves, in the same way.
174
So now I have light zero and light one.
175
And I want to write just a light function that is going to handle some code for all of them.
176
So I'll just call this light and I'm going to make it a function block.
177
OK.
178
And the thing I want to retain the memory
179
that I want out of this function block is how long each light has been active.
180
OK, so I want to keep track of my input, which I'm going to come up here in the top section, which is where I can define inputs,
181
outputs, things that need to both get passed in and go out.
182
things, things that are going to get used inside of the routine only, as well as temporary and constant values.
183
Now for the input, I'm going to say, well, that's actually just going to be the light input.
184
Okay, so I'm going to tie whatever light this is keeping track of to this light input parameter
185
when I call the function.
186
And then the main thing I'm going to output is going to be runtime minutes, and I'll make it a real so we can keep track of fractional minutes.
187
And then in here, I'm going to make a very simple little bit of code.
188
I'm going to check when my light input is active.
189
Oh, I need the pound sign.
190
But so we're going to have this light input and we're going to have it activate a retentive timer.
191
Okay.
192
And if you're following along with the series, you're probably familiar with the T O N R, which is a timer that keeps counting up and will retain how long a timer has been active.
193
And we'll call this runtime.
194
because it's happening inside of a data block.
195
So we want it to get generated for every data block like this.
196
Again, single instance, multi -instance, parameter instance, these are all just options of creating timers.
197
The alternative would be you have to generate a new one
198
of these outside of your function every time you made a new one of these.
199
So we're gonna make it a parameter instance and it's going to automatically get dropped in, in, out.
200
We don't actually need it getting passed in or out.
201
video and then I'm gonna make this elapsed timer I'm gonna make it 10 minutes so that's 600 ,000 milliseconds
202
And then we're going to come down here and we're going to move that time value of elapsed time.
203
We're going to go ahead and move it into an intermediate value.
204
So we'll take runtime, hashtag runtime dot elapsed time,
205
and we're going to move it into an intermediate value that we'll just call runtime milliseconds.
206
So this way we can have a tag.
207
This will also be local static.
208
int, that'll be fine, didn't just to make sure it's big enough.
209
And now we have a milliseconds value we can do math on.
210
So then we'll last thing we'll do is we'll make a calculate block, and we'll take runtime milliseconds, and we'll divide it by 60 ,000.
211
Okay, and this will tell us our runtime minutes, whoops, runtime, underscore minutes.
212
Alrighty, and then the function for this in one divided by in two, like that.
213
And I think maybe the only thing we have to do here is say local output, local out, and real.
214
And I'm a little surprised I'm getting this at all.
215
Oh, yes, of course.
216
So the reason I'm getting the red squiggly lines on this first one
217
and down there is I accidentally put the hash signs in these tags when I define them up here, which is not correct.
218
You need the hash signs when you reference them down here, those pound signs, but you don't put them on the tag names up top.
219
So sorry for slipping.
220
These tutorials are a fast.
221
So everyone makes mistakes.
222
Okay, so to recap what we're doing here, we're going to pass in a value of a light, we're going to count up how long that timer has been counting,
223
convert it to a milliseconds value, divide it by 60 ,000 and report back the runtime minutes.
224
And we have two lights now.
225
So we'll go into example function.
226
And we'll say, all right, start push button is going to be button,
227
let's say, will be tied to light one.
228
I'll make these both momentary coils, and I'll just go ahead and delete half second and startup.
229
We don't need those anymore.
230
So basically, I'll even delete this calculate block.
231
We really don't need that either.
232
So basically the total code in the system now is
233
when I'm holding start push button down the light zero should turn on
234
when I'm holding the second button down light one should turn on
235
and I have this function called light that should give me a count up counter for both those lights.
236
But I have to do this last important step similar to the original function, I have to call them both.
237
So here I'm going to say light zero and you can see when I dragged that function block that I just defined.
238
into main to get called, it automatically said, hey, you need to make a data block to store the memory associated with this instance of your function block.
239
So I'll call this light zero data block.
240
And then I'm going to make another light.
241
And this is where you see the power of function blocks.
242
I'm going to make another light and call it light one data block.
243
And I'm going to tie this light input to light zero.
244
And I'm going to type this light input into light one.
245
I'm going to download this PLC function and if we did it right
246
and that's a big if I should have two different timers here
247
That when I hold down the two different buttons They're both going to activate different retentive timers
248
and I get the this functionality of seeing how long they've
249
been running for free Twice even though I only wrote the code once
250
so I'll hold down one button here
251
and the timer does not count up I'll hold down the other that timer does not count up epic
252
we got the wrong type here.
253
So yeah, so we're calculating a dent, which means an integer value, which means it's going to be rounding to the nearest whole minute, which is why nothing happened on the seconds order.
254
Let's go ahead and make that a real and download.
255
All right, but let's go back to main now that we're calculating reels.
256
And actually, you can see immediately, we have these fractional values already, which is cool.
257
So let's try this demo.
258
Let's hold down light one.
259
Okay, and now let's hold down light zero.
260
All right, and hopefully you can see, this is a very simple example because I'm trying to go fast for this YouTube tutorial,
261
but we got retentive timers to tell us how long these lights were running for free by writing general code,
262
generic code in a function block that can be extrapolated away to many instances.
263
So if I made a thousand light objects, I could call all of them from main,
264
And I would get this counter of how long they've each
265
been running just by tying the correct input to each of those data block instances.
266
So that's kind of the main reason to use function blocks and data blocks instead of just plain old functions.
267
That's how organization blocks work.
268
And again, PLC to PLC, these individual things can get called something different.
269
But the main way they work and the main thing they do are pretty universal across every platform.
270
So I hope you found this tutorial useful.
271
been enjoying the controls and automation series.
272
As always, let me know in the comments if you have any questions
273
or what you'd like to see more of on the channel.
274
Please consider leaving a like on the video and subscribing to the channel, and we'll see you next time.
275
Thanks.
276
Bye.

संदर्भ और पृष्ठभूमि

इस वीडियो में, हम PLC प्रोग्रामिंग के बारे में जानकारी हासिल कर रहे हैं, विशेष रूप से फंक्शंस, फंक्शन ब्लॉक्स और ऑर्गेनाइजेशन ब्लॉक्स के बारे में। यह एक महत्वपूर्ण विषय है जो मशीनों और उपकरणों की स्वचालन में सहायता करता है। यहां, विशेषज्ञ यह समझाते हैं कि कैसे आप विभिन्न प्रकार के प्रोग्रामिंग तत्वों का सही ढंग से उपयोग कर सकते हैं और PLC प्रोग्राम का सही ढंग से निर्माण कर सकते हैं।

दैनिक संचार के लिए शीर्ष 5 वाक्य

  • जब मैं स्टार्ट बटन दबाता हूँ, तो लाइट ऑन करो।
  • जब मैं स्टॉप बटन दबाता हूँ, तो लाइट बंद करो।
  • हमेशा ध्यान रखें कि फंक्शंस मेमोरी में कुछ नहीं रखते।
  • मुख्य लूप में केवल फंक्शंस और फंक्शन ब्लॉक्स को कॉल करना बेहतर है।
  • PLC के चक्र समय को समझना महत्वपूर्ण है।

चरण-दर-चरण शैडोइंग गाइड

इस वीडियो का लेकिन समझने के लिए, आप शैडो स्पीच तकनीक का उपयोग कर सकते हैं। इसे बेहतर बनाने के लिए, निम्नलिखित कदम उठाएँ:

  1. सुनना और समझना: पहले वीडियो को ध्यान से सुनें। मुख्य अवधारणाओं और वाक्यों पर ध्यान दें।
  2. अनुगमन करना: वीडियो में बोले गए शब्दों और वाक्यों को अपने तरीके से दोहराएँ। यह shadowspeaks का अभ्यास करने का एक बेहतरीन तरीका है।
  3. वाक्यांशों का उपयोग: ऊपर दिए गए वाक्यांशों को रोज़मर्रा की बातचीत में शामिल करें। इससे आपकी अंग्रेजी उच्चारण में सुधार होगा।
  4. फंक्शंस और ब्लॉक्स को समझें: यह सुनिश्चित करें कि आप फंक्शंस और फंक्शन ब्लॉक्स के बीच के अंतर को समझते हैं और उनका उपयोग कैसे किया जाता है।
  5. नियमित अभ्यास करें: इस प्रक्रिया को नियमित रूप से दोहराएं ताकि आप अपने shadowing site पर बेहतर प्रगति कर सकें।

इन कदमों का पालन करते हुए, आप न केवल PLC प्रोग्रामिंग की तकनीकी बारीकियों को समझेंगे, बल्कि अंग्रेजी बोलने और उच्चारण में सुधार भी कर सकेंगे।

शैडोइंग तकनीक क्या है?

शैडोइंग (Shadowing) एक विज्ञान-समर्थित भाषा सीखने की तकनीक है जो मूल रूप से पेशेवर दुभाषिया प्रशिक्षण के लिए विकसित की गई थी। विधि सरल लेकिन शक्तिशाली है: आप मूल अंग्रेज़ी ऑडियो सुनते हैं और तुरंत इसे ज़ोर से दोहराते हैं — जैसे वक्ता की छाया 1-2 सेकंड की देरी से। शोध से पता चलता है कि यह उच्चारण सटीकता, स्वर, लय, जुड़ी हुई ध्वनियाँ, सुनने की समझ और बोलने की प्रवाहशीलता में काफ़ी सुधार करता है।

शैडोइंग तकनीक: पूरी चरण-दर-चरण गाइड पढ़ें →