![]() ![]() ![]() ![]() ![]() ![]() |
||
![]() |
||
![]() ![]() ![]() ![]() This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
![]() |
![]() |
#1 |
Member
![]() ![]() 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 |
![]() |
![]() |
#2 |
Lifetime Supporting Member
|
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 |
![]() |
![]() |
#3 |
Lifetime Supporting Member
![]() ![]() 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. |
![]() |
![]() |
#4 |
Member
|
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
|
![]() |
![]() |
#5 | |
Member
|
It is no wonder so many PLC students are so screwed up
Quote:
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 |
|
![]() |
![]() |
#6 | |
Lifetime Supporting Member
![]() ![]() Join Date: Feb 2008
Location: Over there, next to those boxes
Posts: 1,142
|
Quote:
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... ![]() ![]() |
|
![]() |
![]() |
#7 |
Member
|
The real time clock would certainly be the best reference to use but then not all PLC's have a real time clock.
|
![]() |
![]() |
#8 |
Lifetime Supporting Member
|
Tom, Here is a start. I am sure that you can see how to add the Hour and Day counters.
|
![]() |
![]() |
#9 | |
Lifetime Supporting Member
|
Quote:
"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? |
|
![]() |
![]() |
#10 | |
Lifetime Supporting Member
|
Quote:
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. |
|
![]() |
![]() |
#11 |
Lifetime Supporting Member + Moderator
|
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. |
![]() |
![]() |
#12 |
Member
![]() ![]() 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 |
![]() |
![]() |
#13 | |
Lifetime Supporting Member
|
Quote:
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 by OkiePC; March 9th, 2012 at 11:35 AM. |
|
![]() |
![]() |
#14 | |
Member
|
Quote:
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... |
|
![]() |
![]() |
#15 | |||
Lifetime Supporting Member
|
Quote:
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:
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:
Last edited by Lancie1; March 9th, 2012 at 04:47 PM. |
|||
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
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 |