You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old March 6th, 2012, 09:27 AM   #1
tomm22948
Member
United States

tomm22948 is offline
 
Join Date: Mar 2012
Location: ohio
Posts: 2
devise a clock using timers and counters

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
  Reply With Quote
Old March 6th, 2012, 10:29 AM   #2
RussB
Lifetime Supporting Member
United States

RussB is offline
 
RussB's Avatar
 
Join Date: Oct 2003
Location: Michigan
Posts: 2,914
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
__________________
LEARN something today so you can TEACH something tomorrow.
DETAIL in your question promotes DETAIL in my answer.
Dominus Vobiscum <))>(
"Where is the wisdom that we have lost in knowledge?" T.S. Elliot


  Reply With Quote
Old March 7th, 2012, 06:05 AM   #3
uptown47
Lifetime Supporting Member
United Kingdom

uptown47 is offline
 
Join Date: Feb 2008
Location: Over there, next to those boxes
Posts: 1,142
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 by uptown47; March 7th, 2012 at 06:07 AM.
  Reply With Quote
Old March 8th, 2012, 01:27 AM   #4
Calistodwt
Member
South Africa

Calistodwt is offline
 
Calistodwt's Avatar
 
Join Date: May 2003
Location: George, South Africa
Posts: 187
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
  Reply With Quote
Old March 8th, 2012, 01:50 AM   #5
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: The land of the woke and the home of the broke
Posts: 8,153
It is no wonder so many PLC students are so screwed up

Quote:
Originally Posted by tomm22948 View Post
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.
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old March 8th, 2012, 02:57 AM   #6
uptown47
Lifetime Supporting Member
United Kingdom

uptown47 is offline
 
Join Date: Feb 2008
Location: Over there, next to those boxes
Posts: 1,142
Quote:
Originally Posted by Peter Nachtwey View Post
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... )

  Reply With Quote
Old March 8th, 2012, 08:48 AM   #7
Calistodwt
Member
South Africa

Calistodwt is offline
 
Calistodwt's Avatar
 
Join Date: May 2003
Location: George, South Africa
Posts: 187
The real time clock would certainly be the best reference to use but then not all PLC's have a real time clock.
  Reply With Quote
Old March 8th, 2012, 10:20 AM   #8
Lancie1
Lifetime Supporting Member
United States

Lancie1 is offline
 
Lancie1's Avatar
 
Join Date: Jul 2003
Location: Alabama
Posts: 9,999
Tom, Here is a start. I am sure that you can see how to add the Hour and Day counters.
Attached Images
File Type: jpg 24-HOUR CLOCK FROM 1 TIMER & 4 COUNTERS.jpg (35.0 KB, 225 views)
  Reply With Quote
Old March 8th, 2012, 10:32 AM   #9
OkiePC
Lifetime Supporting Member
United States

OkiePC is offline
 
OkiePC's Avatar
 
Join Date: Mar 2005
Location: ENE of Nowhere Oklahoma
Posts: 11,461
Quote:
Originally Posted by Peter Nachtwey View Post
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?
__________________
You've been taken, but you don't know it yet.
  Reply With Quote
Old March 8th, 2012, 10:59 AM   #10
Clay B.
Lifetime Supporting Member
United States

Clay B. is offline
 
Clay B.'s Avatar
 
Join Date: Jun 2005
Location: Concord,NC
Posts: 1,304
Quote:
Originally Posted by Peter Nachtwey View Post
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.
  Reply With Quote
Old March 8th, 2012, 11:07 AM   #11
dcooper33
Lifetime Supporting Member + Moderator
United States

dcooper33 is offline
 
dcooper33's Avatar
 
Join Date: Jun 2011
Location: Rogers, AR
Posts: 717
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
__________________
I'll walk a mile in your shoes. Now I'm a mile away, and I got your shoes.
  Reply With Quote
Old March 9th, 2012, 11:19 AM   #12
tomm22948
Member
United States

tomm22948 is offline
 
Join Date: Mar 2012
Location: ohio
Posts: 2
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
  Reply With Quote
Old March 9th, 2012, 11:33 AM   #13
OkiePC
Lifetime Supporting Member
United States

OkiePC is offline
 
OkiePC's Avatar
 
Join Date: Mar 2005
Location: ENE of Nowhere Oklahoma
Posts: 11,461
Quote:
Originally Posted by tomm22948 View Post
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
__________________
You've been taken, but you don't know it yet.

Last edited by OkiePC; March 9th, 2012 at 11:35 AM.
  Reply With Quote
Old March 9th, 2012, 04:08 PM   #14
Doug-P
Member
United States

Doug-P is offline
 
Doug-P's Avatar
 
Join Date: Jun 2003
Location: Pa
Posts: 1,248
Quote:
Originally Posted by tomm22948 View Post
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
__________________
Let's eat Grandma!

Let's eat, Grandma!

Words are very important, but punctuation saves lives...
  Reply With Quote
Old March 9th, 2012, 04:18 PM   #15
Lancie1
Lifetime Supporting Member
United States

Lancie1 is offline
 
Lancie1's Avatar
 
Join Date: Jul 2003
Location: Alabama
Posts: 9,999
Quote:
..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?

Quote:
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.

Quote:
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 by Lancie1; March 9th, 2012 at 04:47 PM.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Timers, Counters, Comparing, a simple program_need advice neokeelo LIVE PLC Questions And Answers 12 February 24th, 2009 09:33 PM
TOYOPUC Timers & Counters richxie LIVE PLC Questions And Answers 3 January 27th, 2007 09:56 PM
s7 300 timers and counters sparkysliderz LIVE PLC Questions And Answers 11 June 13th, 2005 08:18 AM
reseting counters and timers in rs 5000 darrenj LIVE PLC Questions And Answers 4 February 23rd, 2005 06:29 PM
Using Timers & Counters in WinCC Rusty_K LIVE PLC Questions And Answers 0 April 26th, 2004 12:06 PM


All times are GMT -4. The time now is 09:59 PM.


.