Ron Beaufort
Lifetime Supporting Member
while the dust is settling ...
following up on a question from Tripper in post #26:
fishenguy made a start to answering that question in his post #27 ...
but (as frequently happens with PLCs) there’s more to the story than that ... now that fishenguy’s problems have been solved, let’s learn some more from the project he’s just shared with us ...
first things first - and yes this is “picky” ... in the quote from fishenguy (just above) the word “bit” should be omitted ... he just meant to say “using a regular CTU INSTRUCTION or COUNTER” ... the word “bit” (a box that can hold a one or a zero) doesn’t fit the statement - but (in context) we all know what he meant ...
now then ... Tripper has a perfectly valid question ... and the idea that he brought up is exactly what I was thinking about when I asked this question back in my post #20:
if fishenguy had answered “yes” to that question, then we would have followed up on the differences in operation between setting the preset of the HSC to 36 or to 37 ... the truth is that some people SAY one thing - even when they MEAN something else ... let’s look at what fishenguy said in his original post #1:
now that’s pretty specific ... to translate that directly into ladder logic, we end up with Rung #1 in my post #2 ... quit thinking about “switches” and “coils” and “resets” for a few seconds - and look at the ladder logic rung as being another (foreign) language ... in simplest terms that rung says this:
this is exactly the way that I would teach a student to “translate” this particular rung in a programming class ...
and that is PRECISELY what fishenguy asked for in his first post ... and so - it might not have been what he WANTED - but I definitely gave him what he ASKED FOR ... (happily it turns out that yes, it WAS what he wanted) ...
now let’s dig deeper ... what EXACTLY happens when the RAC (HSC Reset Accumulator) instruction “does its thing?” ... the easiest way to find out the details is to look in the online Help file for the MicroLogix (not SLC) controllers ... but for our purposes, the main thing that we’re interested in this: the RAC does NOT “reset” the CU bit back to a zero status ... that’s important ... to understand why, I suggest that you program a second counter (C5:1) to run in parallel with the High Speed Counter (C5:0) ... let it look at the same prox switch for its input signal and let it count up to a Preset of 36 ...
preview: as long as we manually trip the prox switch slow enough for the "regular" counter to keep up, then both counters should work identically ... right? ...
now let’s see what happened just before the screen shot was taken ... the input (prox switch) had just made its 36th transition from FALSE to TRUE ... so both counters (C5:0 and C5:1) became DONE ... so both rung #1 and rung #3 were executed with TRUE logic ... on rung #1 the RAC “reset” its HSC counter (C5:0) and did NOT change the status of the counter’s CU bit ... so this counter’s Accumulator stayed (correctly) at a value of 0 ...
so far so good ...
on rung #3 the RES “reset” its “normal” counter (C5:1) and it DID change the status of the counter’s CU bit ... and that’s why this counter now (incorrectly) shows an Accumulator value of 1 ... most programmers call this a “false count” situation ... it results when an RES instruction “resets” a counter and THE COUNTER’S INPUT IS STILL ON ...
you can read much more about this situation - and how to (usually) correct it by programming a “one shot” type instruction where I’ve marked location “A” in the figure above ... click here for a post that should cover the subject adequately ... it would be a good idea for fishenguy to read that one - it will go a long way toward explaining why that “false count” occurred when he used the CTU and RES combination - but not when he used the HSC and RAC combination ...
continued in next post ...
following up on a question from Tripper in post #26:
doesn't the preset need to be 37 if he needs to count 36 (resetting on 37)?
fishenguy made a start to answering that question in his post #27 ...
Tripper, when I first wrote the program using a regular CTU bit, I did have to set it to 37 because the counter would count up to 36 then reset to one. The high speed counter (HSC) resets to 0 after it reaches the preset.
but (as frequently happens with PLCs) there’s more to the story than that ... now that fishenguy’s problems have been solved, let’s learn some more from the project he’s just shared with us ...
first things first - and yes this is “picky” ... in the quote from fishenguy (just above) the word “bit” should be omitted ... he just meant to say “using a regular CTU INSTRUCTION or COUNTER” ... the word “bit” (a box that can hold a one or a zero) doesn’t fit the statement - but (in context) we all know what he meant ...
now then ... Tripper has a perfectly valid question ... and the idea that he brought up is exactly what I was thinking about when I asked this question back in my post #20:
is there a possibility that the "miscount" is happening at the precise instant that the counter's accumulator is being reset? ...
if fishenguy had answered “yes” to that question, then we would have followed up on the differences in operation between setting the preset of the HSC to 36 or to 37 ... the truth is that some people SAY one thing - even when they MEAN something else ... let’s look at what fishenguy said in his original post #1:
... latch a binary bit after counting 36 teeth. At the same time it has to reset ...
now that’s pretty specific ... to translate that directly into ladder logic, we end up with Rung #1 in my post #2 ... quit thinking about “switches” and “coils” and “resets” for a few seconds - and look at the ladder logic rung as being another (foreign) language ... in simplest terms that rung says this:
IF - the High Speed Counter is DONE - THEN - GO WRITE a ONE into bit B3/0 - and RESET the High Speed Counter ... but ... IF - the High Speed Counter is NOT done - THEN - DO NOTHING to bit B3/0 - and DO NOTHING to the High Speed Counter ...
this is exactly the way that I would teach a student to “translate” this particular rung in a programming class ...
and that is PRECISELY what fishenguy asked for in his first post ... and so - it might not have been what he WANTED - but I definitely gave him what he ASKED FOR ... (happily it turns out that yes, it WAS what he wanted) ...
now let’s dig deeper ... what EXACTLY happens when the RAC (HSC Reset Accumulator) instruction “does its thing?” ... the easiest way to find out the details is to look in the online Help file for the MicroLogix (not SLC) controllers ... but for our purposes, the main thing that we’re interested in this: the RAC does NOT “reset” the CU bit back to a zero status ... that’s important ... to understand why, I suggest that you program a second counter (C5:1) to run in parallel with the High Speed Counter (C5:0) ... let it look at the same prox switch for its input signal and let it count up to a Preset of 36 ...
preview: as long as we manually trip the prox switch slow enough for the "regular" counter to keep up, then both counters should work identically ... right? ...
now let’s see what happened just before the screen shot was taken ... the input (prox switch) had just made its 36th transition from FALSE to TRUE ... so both counters (C5:0 and C5:1) became DONE ... so both rung #1 and rung #3 were executed with TRUE logic ... on rung #1 the RAC “reset” its HSC counter (C5:0) and did NOT change the status of the counter’s CU bit ... so this counter’s Accumulator stayed (correctly) at a value of 0 ...
so far so good ...
on rung #3 the RES “reset” its “normal” counter (C5:1) and it DID change the status of the counter’s CU bit ... and that’s why this counter now (incorrectly) shows an Accumulator value of 1 ... most programmers call this a “false count” situation ... it results when an RES instruction “resets” a counter and THE COUNTER’S INPUT IS STILL ON ...
you can read much more about this situation - and how to (usually) correct it by programming a “one shot” type instruction where I’ve marked location “A” in the figure above ... click here for a post that should cover the subject adequately ... it would be a good idea for fishenguy to read that one - it will go a long way toward explaining why that “false count” occurred when he used the CTU and RES combination - but not when he used the HSC and RAC combination ...
continued in next post ...
Last edited: