devise a clock using timers and counters

tomm22948

Member
Join Date
Mar 2012
Location
ohio
Posts
2
hello i'm new here and this is my first post. a little back ground on myself, i have been in the machine trades all of my adult life (30+ years) i'm a journeyman toolmaker and a journeyman machine repairman, unfortunatly i have became unemployed and can't find a job with my current skills, so i enrolled at a local community college to obtain a electrical certificate in hopes of furthering my career. my current teacher in my plc class has assigned us a task of programming a 12 hour clock on a slc 5/03, using timers and counters it must display am/pm it also must display hours when an input is pressed and minutes when another input is pressed this is our first assignment with timers and counters and i'am lost if i was still working i could ask some electricians for some help but i don't have that option any more, any help would be appreciated

thanks tom
 
I've never programmed one of them critters, but all PLC programming is the same.
Break the problem down into small logical steps and master them one at a time, not much different than building an engine.
Start with a timer that will give you 1 second and build the minutes from there. When that is done do the hours. etc. HTH
 
As has been stated by RussB, you need to break the problem down.

Start by making a 'flip flop' timer that will give you a bit that will pulse every second (there are other ways of making a bit pulse every second).

Put that bit on the input of a counter.

The counter is now counting seconds.

Compare the counter to 60. Is it greater than or equal to 60?

If it is bring on a temporary 'bit' that will reset the counter and also increment another counter.

This 2nd counter is now counting minutes.

Another comparator should check this counter to see if it is greater than or equal to 60. If it is then a 'bit' should be brought on that will reset it and increment a third counter.

The third counter is now counting hours.

We now need to work out whether it is am or pm.

There are probably lots of ways of doing this but seeing as we are using counters then lets have a counter that is 0 if we are 'am' and 1 if we are 'pm'.

So... compare your hour count to see if you are greater than or equal to 12. If you are AND your am/pm counter is greater than or equal to 1 then reset your am/pm counter to zero.

IF your hour count is greater than or equal to 12 AND your am/pm counter is equal to zero then increment your am/pm counter.

(You'll also reset your hour count at this point)

If someone presses the 'show hours' button then move the hours count on to the output device. If someone presses the 'show minutes' button then move the minutes count to the output device and the same for the seconds and the am/pm if needed.

Hope that helps to start you off.

When writing software just write small chunks and then test it. Write a bit more and test again. That way if it stops working you know where to look.

Start by creating something that will pulse every second....

Good luck ;-))
 
Last edited:
You could start by using a 60 seconds timer, a minutes counter and an hours counter. The timer increments the minutes counter every minute and the minute counter increments the hours timer every 60 minutes
 
It is no wonder so many PLC students are so screwed up

hello i'm new here and this is my first post. a little back ground on myself, i have been in the machine trades all of my adult life (30+ years) i'm a journeyman toolmaker and a journeyman machine repairman, unfortunatly i have became unemployed and can't find a job with my current skills, so i enrolled at a local community college to obtain a electrical certificate in hopes of furthering my career. my current teacher in my plc class has assigned us a task of programming a 12 hour clock on a slc 5/03, using timers and counters it must display am/pm it also must display hours when an input is pressed and minutes when another input is pressed this is our first assignment with timers and counters and i'am lost if i was still working i could ask some electricians for some help but i don't have that option any more, any help would be appreciated

thanks tom
I realize this is just an exercise but does anybody see what is wrong with the problem? You wouldn't use a timer for something like this. A real time clock should be used. Why? Anybody?

Start with getting a 60 second timer to work as suggested above.
 
I realize this is just an exercise but does anybody see what is wrong with the problem? You wouldn't use a timer for something like this. A real time clock should be used. Why? Anybody?

Start with getting a 60 second timer to work as suggested above.

You are spot on. But I think the point of this is just to get the student used to using timers, counters and comparators. As oppose to getting the student to study a real world problem and come up with a robust solution.

At my young son's school they are teaching them to write by getting him to write a line of "a's" then a line of "b's" then a line of "c's"... The final thing doesn't matter, it is just the 'getting there' that is giving him the practise.

(although, thinking about it, my son is 17 years old now and should have mastered this years ago... o_O )

;)
 
Tom, Here is a start. I am sure that you can see how to add the Hour and Day counters.

24-HOUR CLOCK FROM 1 TIMER & 4 COUNTERS.jpg
 
I realize this is just an exercise but does anybody see what is wrong with the problem? You wouldn't use a timer for something like this. A real time clock should be used. Why? Anybody?

Start with getting a 60 second timer to work as suggested above.

Yeah, it does show a lack of creativity on the part of the teacher.

"So, this 5/03 has a real time clock that works just fine, but lets see if we can make an inferior one the hard way..."

Right out of the gate, the students are taught to toss the power tools and get out the hammer and hand saw and generate spaghetti the hard way. It would be wise, in my opinion, to make them write programs that aren't already built in features.

How hard is it to think up a real problem that uses cascading timers/counters?
 
I realize this is just an exercise but does anybody see what is wrong with the problem? You wouldn't use a timer for something like this. A real time clock should be used. Why? Anybody?

Start with getting a 60 second timer to work as suggested above.

Well first off you are going to generate an error in your time that is equal to the length of your scan. So if you are using Counter for hours and minutes then on every transition when you reach 60 seconds you will add the scan time and every time you make an hour you will add another scan time. So at best the clock will be unpredictable. Well you will be able to predict it will be wrong so that is one thing.

I give this a 9 on the "stuff teachers make students do lame scale".

What the heck is wrong with the stop light examples anyway. You can use timers there and counters.

Anyway since your teacher has assigned this your going to need atleast a 1 second pulse timer that counts up to 60 then resets at 60
a counter that counts up 60 then resets at 60
a counter that counts up to 12 then resets at to 1 when it reaches 12
a counter that counts up to 1 then resets at 2

Your second counter runs up to 60 and when it reaches 60 it bumps your minute counter up 1

Your minute counter runs up to 60 and when it reaches 60 it bumps your hour
counter up 1

Now this is where it gets cute

Your Hour counter counts up to 12 then bumps you am/pm counter up 1
Since you will want to display 1 thru 12 you will not reset your counter until it reaches 13 then when you reset this counter you must add a 1 for the display.
Another method would be to take the value of this counter and add a 1 to it for display.

Your associate 0 for am and 1 for pm on the last counter. Hence once you reach 3 you will come around back to 0 in the scan.

Please bear in mind this is the going to be less accurate than a water clock built in the 12 century. This is just an exercise.

In the real world you would just pick up the Real Time Clock (RTC) and use its registers.

Good luck on the career change.
 
Tomm,

What Peter is talking about is cumulative scan-time error. Every time the one-second timer is done, there will be a delay equal to some value between zero and the max scan time before the Timer/DN bit increments the second counter. Same thing for all the Counter/DN bits all the way up the line. There are ways to alleviate some of this cumulative error, but the design of a "fabricated" clock is inherently prone to error.
However, for the purposes of your assignment, the methods that have been discussed and that Lancie has demonstrated will work just fine. I'm sure it's exactly what your instructor is looking for.
Timer error due to scan time discrepancies is an important thing to be aware of. Ask your instructor about it, he will be impressed.

Cheers,
Dustin
 
thanks for all the help but how do you not make a counter start at zero my clock needs to run from 1-12 how do you reset a counter starting at 1 also the am/pm thing he gives us an output as an indicator. i just don't understand the way this teacher teach's he comes in the room writes alot of notes on the board which we all copy from the board then he says lets start the next lab in your book and he leaves well we all just look at one another not having a clue so this clock is are lab#6 i have never even entered a timer or a counter in a program before so i'm very happy to have found this site at least i can ask someone that knows right now i have no one with any experience to bounce ideas off of so if my question seem kind of lame just remember i'am a rookie (very green)

thanks tom
 
this clock is [our] lab#6 i have never even entered a timer or a counter in a program before ...

Well, git after it then!

My suggestion to both help you learn and answer your main questions is to start writing short little programs or pieces of programs and watch them run. You will learn more from that than any advice you read here, especially starting out.

If you don't want to watch and wait for a whole hour to see what is going to happen, you can highlight a register while online, and simply type in a number (think of entering 59 into the minutes counter so you only have to wait one minute to see if your hour rollover logic is correct).

Think creatively. If you want the counter to skip zero, use the EQU on the counter.acc element to see if it is zero, and when it is, MOV a 1 into that accumulator. There are other methods too, like let the dang counter run naturally from 0-23, then do some math to get the hours from that and turn on the PM lamp.

Paul
 
Last edited:
i have never even entered a timer or a counter in a program before so i'm very happy to have found this site at least i can ask someone that knows right now i have no one with any experience to bounce ideas off of so if my question seem kind of lame just remember i'am a rookie (very green)

thanks tom
RSLogix has a respectable help section. Punch in 'insert' into FIND and see what comes up. I haven't done it recently but there should be items for inserting rungs and elements and comments, etc. Work out how to insert a rung then go on to inserting the elements one at a time.

Start with the simplest conditional rung - one input and one output. Just to get the hang of it you might try programming a rung with your display pushbutton turning on the am/pm output. This you can watch in RSLogix and also see a real world output respond to your input.

If you can get the am/pm thing going, swap the output for a counter (or, add another rung with the same input and a counter) and watch the counter increment each time you press the pushbutton. Add another rung, again with the same input and use a timer for the output instruction.

Add another rung using the counter DN (done) bit as the input and use it to enable a RES instruction to reset the counter above. Use a preset of four or so.

.02
 
..How do you not make a counter start at zero. My clock needs to run from 1-12.
Tom,

The usual, regular, 24 hour clock (that has been in use for a long time by a lot of people) starts at "0" Hour and runs past 23:00. When it hits 24, it shifts to 0:00 again. Why would that not work? Is the 1-to-12 stupidity based on actual instructions from your instructor?

If so, you cannot reprogram PLC built-in instructions (such as Counters), but you can work around their limitations. If you want to start at "1" (where the counter normally starts at 0), then every time it goes to 0, put in an instruction to add 1 (or MOVE 1) to the Counter Accumulated value (C5:X.ACC in RSLogix where X is the counter number).

If it were me, I would stick with "real" things, like the way clocks work, instead of going off on an imagination trip and trying to reinvent the wheel. I would set my clock to run from 0:00 Hours and Minutes to 23:59 Hours and Minutes. Using Comparison Instructions, when Hours >= 0 or <= 11, the turn on "AM" output. When Hours >= 12 or <= 23, the turn on "PM" output. Period, done, and what is the next question?

My current teacher in my plc class has assigned us a task of programming a 12 hour clock on a slc 5/03, using timers and counters.
Did he say it had to be a "12-hour clock", or did he say it had to indicate 12 hour periods of AM and PM? That is a totally different problem!

TIP: If you want help that is very specific, accurate, and zeroed in on your actual problem....then please post the actual Lab # 6 problem as written, not a second-hand version as loosely interpreted by an admitted beginner (you - who may not understand enough to correctly interpret the questions. After all, if you did correctly understand the question, you could already write the program.

If you don't want to watch and wait for a whole hour to see what is going to happen, you can highlight a register while online, and simply type in a number (think of entering 59 into the minutes counter so you only have to wait one minute to see if your hour rollover logic is correct).
As usual, Paul has a great suggestion for the final check-out. Another method I use is that for all the program versions and revisions up until the last final, I often scale my real times by some factor (say instead of 1-hour, I change that to 1 real minute, and for 10 minutes I might change that to 10 seconds. Then I run the program and get everything working, then make a final version and use Paul's method to run the final test.
 
Last edited:

Similar Topics

We recently purchased a IC693CPU352 module and it appears the internal time clock is static. I can set the time and date but once set it does not...
Replies
5
Views
148
Hello. I cannot change the SendClock settings for a PROFINET IO device. I need to slow down the CODESYS PROFINET IO controller. What am I doing...
Replies
0
Views
175
Hello everyone, I am not a programmer, but I can do some simple programming. So now I want the time to be recorded every time a pump turns on. I...
Replies
35
Views
2,590
Hello, I am trying to create an AOI that will retrive the clock datetime bits from a master plc through a generic message read instruction and...
Replies
2
Views
467
I was online a SLC5/04 yesterday and one thing I did was go to processor properties and set the date and time to get the PLC clock current. It...
Replies
4
Views
703
Back
Top Bottom