1
00:00:00,720 --> 00:00:07,710
OK for our next example we're going to write a C program to control the machine in front of us.

2
00:00:07,710 --> 00:00:12,710
We have a pump that fills the tank within that tank.

3
00:00:12,720 --> 00:00:17,070
We have four floats which is at various levels.

4
00:00:17,250 --> 00:00:24,160
You'll recognize here we have our high high level our high level our low level and our low low level

5
00:00:24,170 --> 00:00:24,580
.

6
00:00:24,840 --> 00:00:31,080
And we also have a discharge valve naturally located at the bottom of the tank so it'll be gravity fed

7
00:00:31,830 --> 00:00:37,540
and we are going to write the program that will fill and drain this tank.

8
00:00:37,950 --> 00:00:44,220
So once again I've set up largely clean Bill C program.

9
00:00:44,560 --> 00:00:51,750
I've got our main ladder calling our digital gyro and our controls which are the only ladders we'll

10
00:00:51,750 --> 00:00:55,940
will be using on our IO configuration.

11
00:00:55,950 --> 00:01:02,660
I still have 8 inputs on slot 1 and I have 8 outputs on slot 2.

12
00:01:02,670 --> 00:01:11,850
All are digital and we are going to jump right into bringing our IO in.

13
00:01:11,850 --> 00:01:23,730
So going back to our graphic we have 1 2 3 4 inputs and we have 1 2 outputs those are pump in our valve

14
00:01:23,740 --> 00:01:25,550
.

15
00:01:26,970 --> 00:01:32,550
Let's go ahead and start laying these out and I'm going to work through this a little bit more quickly

16
00:01:32,550 --> 00:01:38,910
than I have in past examples because I know you've been keeping up I know you understand this by now

17
00:01:38,910 --> 00:01:44,790
and I don't want to kill you with redundancy but I certainly do want you to understand and retain these

18
00:01:44,790 --> 00:01:45,720
things.

19
00:01:46,230 --> 00:01:55,800
So let's go ahead and address our first input that's on slot 1 channel zero and we're going to go ahead

20
00:01:55,800 --> 00:01:58,500
and call that our low low switch

21
00:02:02,580 --> 00:02:06,690
then we're going to associate that with a bit in our data table.

22
00:02:06,690 --> 00:02:18,420
We'll take our first one be 3 0 0 and we'll define that as our L-L switch.

23
00:02:18,420 --> 00:02:22,130
Now just to program a little faster.

24
00:02:22,290 --> 00:02:29,910
I'm going to go ahead and copy rungs 0 and paste it three more times and I'm going to copy and paste

25
00:02:29,910 --> 00:02:37,800
my way through some of this so I just copied the description out of I call and 1 slice zero and I'm

26
00:02:37,800 --> 00:02:45,720
going to change the second rung to 1 which is our next channel and that's just going to be Elle's switch

27
00:02:45,720 --> 00:02:49,820
input because that's the low not the low low.

28
00:02:49,830 --> 00:02:55,350
The next one I said is two and this one's actually going to be H for high.

29
00:02:55,980 --> 00:03:02,490
And the last one on one is set for three and we're going to call that H.H. which is high high

30
00:03:05,280 --> 00:03:09,390
and just like we did that on the left.

31
00:03:09,390 --> 00:03:14,510
And when I come over here and cheat the same way on the right.

32
00:03:15,030 --> 00:03:21,660
So we have an el switch.

33
00:03:23,520 --> 00:03:25,650
Then we have an eight switch.

34
00:03:25,650 --> 00:03:27,600
Again that's our high switch

35
00:03:32,160 --> 00:03:38,260
and last but certainly not least is going to be our high high switch.

36
00:03:38,820 --> 00:03:43,490
And you'll remember that L-L and H.H. are four alarm conditions.

37
00:03:43,770 --> 00:03:53,310
So I'm programming the alarm level switches in here and the L-L and the a change but I'm not actually

38
00:03:53,310 --> 00:03:57,210
going to program the alarms just yet.

39
00:03:57,220 --> 00:04:03,630
We're going to hold off until the next section on alarms and notifications and we're going to come back

40
00:04:03,630 --> 00:04:06,860
to this program and we're going to put those in at that time.

41
00:04:07,020 --> 00:04:11,780
But we've gone ahead and set up the IPO now.

42
00:04:12,600 --> 00:04:18,660
And now we've got two more that's are going to be our digital outputs.

43
00:04:18,660 --> 00:04:24,130
So the first thing we need to do is establish control bits for them.

44
00:04:24,240 --> 00:04:26,700
We have one that's going to be our pump

45
00:04:33,690 --> 00:04:36,940
and we have one that's going to be our valve

46
00:04:44,430 --> 00:04:48,000
and we need to tie those to the output.

47
00:04:48,900 --> 00:04:55,140
So we'll say that our valve is on output 2 channels 0

48
00:05:06,010 --> 00:05:09,420
and we'll put our pump on channel 1.

49
00:05:10,090 --> 00:05:12,750
So that is it for our show.

50
00:05:12,760 --> 00:05:15,260
We've got that all mapped out.

51
00:05:15,400 --> 00:05:22,030
Now we're ready to jump into the exciting part that's the controls and figure out how we want to make

52
00:05:22,120 --> 00:05:24,640
all of this stuff work.

53
00:05:24,640 --> 00:05:30,650
The first thing we know we want to look at is our low and high switches.

54
00:05:30,660 --> 00:05:33,730
Remember those are process control.

55
00:05:33,790 --> 00:05:36,340
Low low and high high.

56
00:05:36,520 --> 00:05:38,440
Those are four alarms.

57
00:05:38,440 --> 00:05:46,170
Right now we're just programming process controls so we can for go worrying about the L-L and H.H. until

58
00:05:46,180 --> 00:05:48,910
we get to the next section.

59
00:05:48,910 --> 00:05:56,770
So we're going to be pulling B-3 0 1 and B-3 0 2 into our controls.

60
00:05:56,770 --> 00:06:00,570
So let's create a few rungs here.

61
00:06:02,080 --> 00:06:07,380
We're going to go ahead and use excise sees examine if closed blocks

62
00:06:11,620 --> 00:06:17,230
and we're going to go ahead and look at our low and high switches.

63
00:06:17,230 --> 00:06:23,080
Then we also know we're going to want a couple of rungs that are going to energize our pump and our

64
00:06:23,080 --> 00:06:24,370
valve.

65
00:06:24,370 --> 00:06:31,110
So let's go back and look those are on B-3 0 4 and B-3 0 5.

66
00:06:31,390 --> 00:06:44,260
So we're going to go ahead and put output energises and be 3 0 4 and 1 4 be 3 0 5.

67
00:06:44,260 --> 00:06:50,860
So we've got our inputs we've got our outputs now we have to do is put some logic in that makes these

68
00:06:50,860 --> 00:06:52,010
things work.

69
00:06:52,030 --> 00:06:57,770
So when we think about our tank we are going to really be running two modes.

70
00:06:57,790 --> 00:07:06,520
We're going to be running a fill and we're going to be running a drain now the way I'm envisioning this

71
00:07:06,520 --> 00:07:14,140
working right now is when the pump is running the valve is closed and that's going to fill our tank

72
00:07:14,200 --> 00:07:21,010
up to the high level and then the pump is going to shut off and the valve is going to open that's going

73
00:07:21,010 --> 00:07:25,560
to drain our tank down to the low level when we get to the low level.

74
00:07:25,630 --> 00:07:30,490
We're going to close our discharge valve again and start our fill pump.

75
00:07:30,490 --> 00:07:37,870
So this maybe isn't a very practical operation but we want this tank just to fill and drain and fill

76
00:07:37,870 --> 00:07:43,220
and drain and cycle back and forth and that's what we're going to reprogram it to do right now.

77
00:07:43,600 --> 00:07:52,420
We're going to look at the low switch and when that's going to tell us when the level is low that means

78
00:07:52,540 --> 00:07:56,360
it's going to trigger the fill mode.

79
00:07:56,410 --> 00:08:06,700
So when we're setting modes we can use an integer if there are more than two modes or we can use a bit

80
00:08:06,710 --> 00:08:06,900
.

81
00:08:07,270 --> 00:08:10,020
If there's only two modes.

82
00:08:10,330 --> 00:08:18,580
So in this case we only have two modes and we've already seen an example of using an integer to control

83
00:08:18,580 --> 00:08:21,160
status with our blower example.

84
00:08:21,160 --> 00:08:26,610
So this time I'm going to use a bid to control the mode.

85
00:08:26,920 --> 00:08:35,549
So our low switch is going to energize a bit and that is going to set our film mode.

86
00:08:35,770 --> 00:08:40,600
And when that bit is de-energize we're going to call that our dream mode.

87
00:08:40,690 --> 00:08:48,700
The thing is if you understand anything about levels of fluids or liquids inside of a tank especially

88
00:08:48,700 --> 00:08:56,020
when you're pumping into that tank or draining with a valve you know it's not always a smooth level

89
00:08:56,020 --> 00:09:01,250
on the top the pump especially tends to create some waves.

90
00:09:01,570 --> 00:09:06,760
And when you're working with the level switches again you have to consider reality when you're writing

91
00:09:06,760 --> 00:09:12,520
PLC program when the level is right next to that switch.

92
00:09:12,520 --> 00:09:17,870
That switch is going to be rocking back and forth opening and closed open and closed.

93
00:09:18,160 --> 00:09:26,230
If we are triggering our pump based directly on that switch then our pump is going to be starting and

94
00:09:26,230 --> 00:09:33,180
stopping back and forth and it's not going to take too long before our pump burns up the valve will

95
00:09:33,190 --> 00:09:39,390
be doing the same thing clicking and chattering back and forth and it's actuators going to burn up.

96
00:09:39,640 --> 00:09:44,780
So we need to put some smart code into this program.

97
00:09:44,950 --> 00:09:51,460
That's not going to allow the pump to rock back and forth is not going to allow the valve to open and

98
00:09:51,460 --> 00:09:53,040
close repeatedly.

99
00:09:53,290 --> 00:10:01,130
And the way we're going to do that is we're going to use delay timers to establish these modes.

100
00:10:01,810 --> 00:10:10,780
So I'm going to go to timer counter and I'm going to use our timer on delay and I'm going to set a timer

101
00:10:11,170 --> 00:10:19,100
for zero and that's going to be our fill mode delay timer

102
00:10:23,080 --> 00:10:29,740
and we'll go ahead and leave that as a second time or we don't need milliseconds or hundreds of a second

103
00:10:29,740 --> 00:10:36,640
for this kind of operation and let's call it a 10 second delay on that timer.

104
00:10:37,020 --> 00:10:44,100
What that means is when this level switches close and that's going to happen when the water level drops

105
00:10:44,110 --> 00:10:50,890
down below the low level switch then this timer is going to energize and start timing.

106
00:10:51,040 --> 00:10:54,280
And we're going to get a down get out of that timer.

107
00:10:54,490 --> 00:11:03,370
So let's go ahead and add a couple of rungs in here because we still haven't set a mode for anything

108
00:11:03,380 --> 00:11:03,410
.

109
00:11:03,430 --> 00:11:07,030
All we've really done so far is energized the timer.

110
00:11:07,300 --> 00:11:16,220
So we want to analyze that down bit for T for zero.

111
00:11:17,050 --> 00:11:23,110
And that's our Phil mode delay timer if you remember back from programming fundamentals the way that

112
00:11:23,110 --> 00:11:31,860
a timer works is when it times all the way down this down bit Energizers and it'll stay energized until

113
00:11:31,870 --> 00:11:41,620
this rung is deactivated by rendering the conditions to the left as false or until the reset command

114
00:11:42,070 --> 00:11:47,700
is activated against this timer rocking the accumulator back to zero.

115
00:11:48,280 --> 00:11:52,670
So right now we're not going to worry about resetting that circuit.

116
00:11:52,720 --> 00:12:00,310
We're going to worry about when this film mode delay timer times out then we want to go ahead and set

117
00:12:00,370 --> 00:12:17,580
a bet and this bet is going to be film mode equals one drain mode equals zero.

118
00:12:17,590 --> 00:12:26,580
So this is our control bet and we'll go ahead and give it a simple symbol as well fill mode.

119
00:12:28,090 --> 00:12:36,550
OK so now let's think through this when the level in our tank gets down to the low switch it's going

120
00:12:36,550 --> 00:12:38,530
to rock back and forth a little bit.

121
00:12:38,560 --> 00:12:43,950
And this timer is going to start and then stop and reset itself and start again.

122
00:12:44,320 --> 00:12:49,510
But that water levels going to keep going down and pretty soon it's going to get far enough below the

123
00:12:49,500 --> 00:12:53,300
switch that it's going to close and stay closed.

124
00:12:53,560 --> 00:12:59,320
And when that happens then this time is really going to be able to make some progress and start counting

125
00:12:59,320 --> 00:12:59,990
up.

126
00:13:00,220 --> 00:13:07,390
And once it times all the way up to 10 seconds without the water level creeping back up then this down

127
00:13:07,470 --> 00:13:12,050
it's going to energize and we're going to start film mode.

128
00:13:12,070 --> 00:13:19,080
Now we already know once we start film mode this system's going to start filling back up and the level's

129
00:13:19,090 --> 00:13:23,200
going to come up above the low switch pretty quickly.

130
00:13:23,560 --> 00:13:30,430
Once it does the way this program is written right now the timer will de-energize the down bit will

131
00:13:30,430 --> 00:13:35,580
be lost and this mode is going to change right back to drain mode.

132
00:13:35,880 --> 00:13:39,170
And that means our water levels are going to start going down again.

133
00:13:39,460 --> 00:13:42,910
And that's not good process control.

134
00:13:42,900 --> 00:13:50,500
If you remember we wanted to go down to the low level then we wanted to start filling and stay filling

135
00:13:50,950 --> 00:13:53,270
all the way up to the high level.

136
00:13:53,800 --> 00:14:03,430
So what we need is a latch something that once this film mode bit is triggered it's going to lock it

137
00:14:03,430 --> 00:14:04,170
in.

138
00:14:04,300 --> 00:14:13,570
And even when this bit for T4 0 is lost we want something to hold this until we get up to the higher

139
00:14:13,570 --> 00:14:14,420
level.

140
00:14:14,830 --> 00:14:25,810
So we're going to put a branch around this condition here and we're going to use this bit as its own

141
00:14:25,810 --> 00:14:26,960
hold in.

142
00:14:27,150 --> 00:14:34,520
So we're going to put in excise C and we're going to address it to be 3 0 6.

143
00:14:34,690 --> 00:14:39,740
So we're referring to the bit that's energized on the same run.

144
00:14:40,170 --> 00:14:45,150
And let's step by step through just this run so far.

145
00:14:45,150 --> 00:14:53,800
What's happening is when this timer times out and then this down is going to energize and it's going

146
00:14:53,800 --> 00:14:57,840
to energize this a bit right here.

147
00:14:58,890 --> 00:15:02,010
The next time this scans.

148
00:15:02,160 --> 00:15:05,000
Now this is going to be energized.

149
00:15:05,200 --> 00:15:06,670
So we can't.

150
00:15:06,660 --> 00:15:16,380
We have a path through here on the top branch of this run we also have a path on the bottom branch so

151
00:15:16,410 --> 00:15:25,200
fill mode is going to stay energized though level in our tank is going to start coming up and eventually

152
00:15:25,200 --> 00:15:31,620
it's going to go above the level switch which means this timer will reset and it's down.

153
00:15:31,620 --> 00:15:41,370
It will open but since this was already energized this will still be true and we'll still be able to

154
00:15:41,370 --> 00:15:49,500
come in around this down bit and we'll still have a path to keep this film mode energized and it'll

155
00:15:49,500 --> 00:15:53,040
stay energized and keep filling the tank.

156
00:15:53,040 --> 00:15:56,550
Now we need a way to terminate Phil mode.

157
00:15:56,640 --> 00:16:03,990
So let's look to our high switch once again and the same problem we had when our level was at our low

158
00:16:03,990 --> 00:16:04,760
switch.

159
00:16:04,830 --> 00:16:06,970
We're going to have our high switch.

160
00:16:07,200 --> 00:16:12,930
That means the water levels are going to rock back and forth and this switch is going to open close

161
00:16:12,930 --> 00:16:14,230
open close.

162
00:16:14,400 --> 00:16:21,360
And we solved that above with a timer and I don't see any reason why a timer won't work here as well

163
00:16:21,360 --> 00:16:21,910
.

164
00:16:21,930 --> 00:16:30,260
So this is going to be our drain mode delay timer.

165
00:16:31,300 --> 00:16:34,840
Are going to go ahead and set that as a one second timer.

166
00:16:35,370 --> 00:16:38,280
And we're going to give it 10 seconds as well.

167
00:16:38,460 --> 00:16:47,940
And now we're going to use the down bit of this timer as an interrupt for the hold in the circuit on

168
00:16:47,940 --> 00:16:50,090
this run.

169
00:16:50,340 --> 00:16:59,400
So we're going to use the x y o command and we're going to address that to the timer for one's down

170
00:16:59,410 --> 00:17:03,720
bit for coal and one slash Dnt.

171
00:17:04,020 --> 00:17:06,470
So that's step by step through this again.

172
00:17:06,720 --> 00:17:14,130
We already know that this timer is going to trigger this bit which is going to energize this that we're

173
00:17:14,140 --> 00:17:17,079
just going to make this true.

174
00:17:17,460 --> 00:17:24,710
And that gave us a path through this branch to sustain this even once we lose that.

175
00:17:25,020 --> 00:17:32,760
Now as of yet our drain mode delay timer that's not going to start timing until our high switch is met

176
00:17:32,770 --> 00:17:33,040
.

177
00:17:33,300 --> 00:17:36,640
So this down bit is going to be open.

178
00:17:36,720 --> 00:17:42,930
It's going to be de-energized and that's good because we're looking at that bit and saying we want it

179
00:17:42,930 --> 00:17:44,430
to be de-energized.

180
00:17:44,520 --> 00:17:51,090
And as long as it is de-energized this instruction is going to be true and our film mode is going to

181
00:17:51,090 --> 00:18:00,690
be locked in and it's going to keep going up up up until our high switches met for 10 straight seconds

182
00:18:01,350 --> 00:18:07,530
then we're going to energize our down bit making this condition false.

183
00:18:07,650 --> 00:18:10,190
We already know this is still going to be false.

184
00:18:10,230 --> 00:18:11,850
This will be false.

185
00:18:11,880 --> 00:18:15,120
That means our film mode is going to be lost.

186
00:18:15,270 --> 00:18:24,540
De-energized intend drain mode and it's going to stay in drain mode until we re-energise with our low

187
00:18:24,540 --> 00:18:27,280
switch and the former delay timer.

188
00:18:27,510 --> 00:18:33,960
So right now we've got the code necessary to control this fill mode bit.

189
00:18:34,020 --> 00:18:40,680
Now we have to do is connect the fill mode bet to our pump into our valve.

190
00:18:40,710 --> 00:18:44,060
So when do we want our pump to come on.

191
00:18:44,070 --> 00:18:51,820
We want our pump to come on during film mode which means when B-3 0 6 is true.

192
00:18:52,200 --> 00:18:59,460
So let's use an exercise see instruction and tie it to be 3 0 6.

193
00:18:59,460 --> 00:19:04,380
So now our pump will come on any time we're in film mode.

194
00:19:05,100 --> 00:19:12,690
As for our valve we want that to work in drain mode which means this fill mode bit needs to be false

195
00:19:12,690 --> 00:19:13,500
.

196
00:19:13,680 --> 00:19:15,910
That's as easy as an X.

197
00:19:15,980 --> 00:19:20,710
O command which is the exact opposite of what we used unrung 3.

198
00:19:20,910 --> 00:19:28,500
We're going to address it to the very same bit and we're done.

199
00:19:28,530 --> 00:19:34,060
So now when our film mode bit equals one which means it's closed.

200
00:19:34,080 --> 00:19:42,660
That's why we're using an excise c command our pump comes on and when our Filmore bit equals zero that

201
00:19:42,660 --> 00:19:50,610
means it's in drain mode then our valve comes on and by on we mean that's going to actuate into the

202
00:19:50,610 --> 00:19:57,930
open position and we want the pump and the valve to work opposite each other and that's perfect because

203
00:19:57,930 --> 00:20:05,730
we're using the same bit to control them both in opposite polarity which means they'll never be actuated

204
00:20:05,730 --> 00:20:12,220
or energized at the same time and you'll never have both of them off at the same time.

205
00:20:12,270 --> 00:20:17,620
One will always be going the other one will always be at rest.

206
00:20:17,760 --> 00:20:24,020
So that program should make sense to you at this point if it doesn't.

207
00:20:24,030 --> 00:20:27,080
Please watch this lecture again.

208
00:20:27,150 --> 00:20:28,820
Look at the logic.

209
00:20:28,830 --> 00:20:31,550
Work through it in your head without my voice.

210
00:20:31,550 --> 00:20:34,890
Just pause the video work through the logic.

211
00:20:34,890 --> 00:20:41,820
Once all of this makes sense to you start up the next lecture and we're going to transition this program

212
00:20:41,820 --> 00:20:45,300
from digital controls to analog controls.

213
00:20:45,300 --> 00:20:48,690
So this was a bit of a more complicated lecture.

214
00:20:48,690 --> 00:20:54,930
I understand that the next one is going to be somewhat of a break because we're not really going to

215
00:20:54,930 --> 00:20:58,350
be originating a whole program from scratch.

216
00:20:58,350 --> 00:21:04,830
We're going to be modifying an existing program and in the life of a programmer.

217
00:21:05,160 --> 00:21:08,990
That's something you have to do from time to time.

218
00:21:09,030 --> 00:21:10,840
It will be determined in the field.

219
00:21:10,860 --> 00:21:17,430
There are means of control isn't satisfactory for the process and they want to retrofit an existing

220
00:21:17,430 --> 00:21:24,840
design which means you're digging into a year old program or a three year old program that you maybe

221
00:21:24,840 --> 00:21:33,180
didn't even write and you're changing digital controls for analogs you're adding redundant controls

222
00:21:33,540 --> 00:21:35,700
you're changing the way things work.

223
00:21:36,000 --> 00:21:38,970
And I pay a lot of my bills.

224
00:21:39,000 --> 00:21:42,690
Retrofitting old programs that I didn't write


