fire station clock revival - Page 1
Forum section: electronics / projects

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 04:00:18 pm
content: A friend of my dad's has asked me to knock up a circuit for him that generates a pulse every 30 seconds to tick the mechanism over. now there is some help on the back in the form of a label that states that the clock coil should be fed between 170 and 270 mA. But I have no idea how long the tick should take.I'm currently running on 100mS, it's giving a healthy clonk every 30 seconds-ish (it will take hours if not days of running to notice any drift, luckily the instruction time of a pic at 32.768 KHz divides into 30s with a whole number so in theory I can get it bang on). The coil resistance is about 14 ohms that for 270mA dictates 3V but as I'm driving from 4.5-4.8V and the voltage at 170mA is 2.38 I guess i can use "PWM theory" and half my pulse time from the ideal at the voltage that it would otherwise run at.I'm hoping to make it battery powered for him with 3 batteries, with 100mS pulse that is 0.8mA per hour of ticks just for the clock. I don't know the capacity of AA batteries but that is 40ish days per A.Has anyone ever played with this sort of stuff before ?(oh and if you want one - the driver circuit that is I may be marketing it - who knows who else has "acquired" an old fire station clock).The idea was that the clocks of which there were many in the same station were all connected in series and a single battery supplied the pulse power that was pulsed by a pendant operated switch. I guess this was in the days when timing circuitry was very expensive so it made sense for the timing to be central

author: grumpydoc
author_rank: Super Contributor
timestamp: February 02, 2013, 04:23:58 pm
content: QuoteWell, more that you want all the clocks on the station to show exactly the same time, synchronous clocks were also common in factories for the same reason.

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 04:29:03 pm
content: true, these days we have sufficient accuracy and size to have multiple independent clocks with built in time keeping and know that they will stay dead accurate and "synchronized".Now I'm trying to work out how long my code takes to execute as on 8192 instructions per second that's just over 122uS per instruction so i need to have a partial delay period in my timing sequence to allow for the code execution time and the time spent doing a 40mS output pulse (I've decided to lower it)

author: Jon Chandler
author_rank: Frequent Contributor
timestamp: February 02, 2013, 04:47:40 pm
content: The same system was also used in schools to keep all the clocks synchronized.Wikipedia-Master Clock

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 02, 2013, 06:34:19 pm
content: Quote from: Simon on February 02, 2013, 04:29:03 pmHmmm yeah, how about timer->interrupt->pulse?Quote from: Jon Chandler on February 02, 2013, 04:47:40 pmRailways!

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 06:52:14 pm
content: looks like i have a market that stretches a bit further than my dads friend.how would interups help ? ok might be sliker but this is just a timed pulse, no multitasking

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 02, 2013, 07:06:14 pm
content: Quote from: Simon on February 02, 2013, 06:52:14 pmIt's not really the interrupt that helps, it's the hardware timer. You just set one of the timers in the pic to count to 30 seconds, and then let it generate an interrupt. In the interrupt routine you output the pulse and after that go back to sleep. No need to count instructions, the timer takes care of the period.While you are at it, put a dipswitch in to set the timing to the most useful intervals, like 30 secs, 60 secs and whatever could be handy.

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 07:17:46 pm
content: well I've not delved too deep yet but yes I'd like to make the variants for other timings. can the pic count to 30s on a 32.768 KHz clock ?The problem I'll have with making other timings is I'll need to compensate for the fact that each 1/2 second cycle takes a certain amount of time and if I lower or increase the timing then that will alter the program run time, unless I really can count to 30S on one timer take but that is 245'760 counts which is well over the 16 bit or can it be prescaled ? it would need to be prescaled by at least 5

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 02, 2013, 07:20:29 pm
content: What pic are you using? I can have a look at the datasheet.Your clock is 32.768 Khz?

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 07:21:17 pm
content: 12F61532.768 clock crystal

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 02, 2013, 07:23:07 pm
content: I will have a look, but if you are running out of bits just count seconds and keep track of how many you counted

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 07:25:31 pm
content: yes but that is what I'm already doing although with 1/2 seconds, so that means adding program time overheads which screw up that last cycle if i want to do a changeable time delay as I'd need to keep adjusting it (not to mention testing it out)

author: lewis
author_rank: Frequent Contributor
timestamp: February 02, 2013, 07:27:48 pm
content: If you have a PIC with the ECCP (enhanced capture and compare) module built in and a separate oscillator for TMR1, you can use the 32kHz crystal to run TMR1 and get the hardware to generate the pulse when TMR1 and the ECCP period register match. (Well, the match condition actually generates an interrupt so your interrupt routine consists of generating the 100ms pulse on whatever output pin). This way you don't have to worry about the instruction execution time at all. It enables you to make changes to your code later on without having to recalculate the instruction time again. You don't actually need the separate TMR1 oscillator, use the 32kHz crystal as the PIC's main oscillator and feed TMR1 with it if your PIC is not doing anything else that requires a faster clock.If you don't have the ECCP module, then interrupts are mandatory for accurate timing. If you're manually checking the T0IF or TMR1IF bit in a loop to detect an overflow, it's virtually certain that your code will not check the bit at exactly the same time as the overflow occurs. This way, timing errors accumulate, especially if you're having to prime the timer on each overflow. With interrupts, you can be sure that the interrupt occurs bang on time every time. You still have to know the exact duration of the interrupt routine, but code changes become much easier and the timing is more reliable. But not as reliable as the ECCP module - definitely use it.PIC12F1822 is a very good low cost 8-pin device, it's got everything in the world on it, and it's on par cost-wise with a 12F615. If you're being really tight, a 10F204 will do it, but do use the TMR0 interrupts to increment/decrement your timing registers, and don't prime the timer on overflow.It sounds like you're not actually using the timers at all - manually incrementing or decrementing registers with INCFSZ or DECFSZ instructions can get pretty good accuracy, but it's a hell of a lot of work. Also, one minor change to the code will bugger up the whole thing. And you MUST do it in assembler.ECCP module - that's the way to go mate...I designed an analogue clock movement for a local clockmaker years ago, it used a big stepper motor to drive the hands (his clocks are anywhere between 2-20 feet in diameter). It used the Rugby (now Anthorn) MSF transmission to set the time automatically, the clocks go on the side of buildings where setting them twice a year is impractical. In the event of a lost MSF signal, the clock had to keep accurate time all by itself indefinitely, and the ECCP module was essential. It was about 30 pages of assembler - that was before I knew C.

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 07:33:13 pm
content: hm good points, I should learn interups I guess, yes I see now the counter just runs to when it hits the value it tripes the pulse and resets good plan.I guess I need to look through my compilers guide, although I was planning on starting to use AVR's rather than invest more time in pics (getting fed up with the snobbery)

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 02, 2013, 07:35:32 pm
content: Well. looks like Lewis beat me to it. The 12F615 has the ECCP on timer 1, and it also has a prescaler of maximum 8. So you could set it to a 10 seconds period but it would be easier to just let the timer count 1 second and then increment a register till you have what you need, then output the pulse and set the register back to zero.

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 07:41:07 pm
content: hm looks like i have a lot of learning, I might head over the AVR forum and start looking at the tutorials, in fact I recently read a very, very good tutorial on using timers that will probably do exactly what I want and I have some ATtiny13A's around so no difference to me (other than no one has done tutorials for pic's that are of the same quality as the ones done for AVR).I only started using this pic setup as I have a current 2 minute (no precision) timer circuit and program done for work that I was adapting (not trying to start a pic/avr war - promise)

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 02, 2013, 07:48:04 pm
content: It's only because you mentioned the pic in your first post that I continued on that, and the whole timer idea is just general common sense, it does not depend on what processor you use (as long as it has a timer of course) And yes, it is basically a lot of reading, then programming, then more reading, debugging, throwing stuff around, then more programming... What you learn from that you can use in your next projects, no matter if it is pic, avr, arm...

author: lewis
author_rank: Frequent Contributor
timestamp: February 02, 2013, 08:18:32 pm
content: If you decide to stay with the PIC there is an EXCELLENT, and I really mean EXCELLENT, set of tutorials here:http://www.gooligum.com.au/tutorials.html(scroll down a bit, they're free).Without meaning to hijack the thread, if anyone knows of something similar for AVR (or ARM!) I'd like to know, really want to broaden my MCU horizons.

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 08:39:05 pm
content: go to AVRfreaks.net and onto the forum, there is a tutorials category with many excellent tutorials by various members

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 08:41:44 pm
content: The problem I find with many tutorials is that the authors assume you know so much to the point of making you wonder why you should need their tutorial if you knew so much. I often find more advanced things explained and no basics, pic tut's are very good at this

author: IanB
author_rank: Super Contributor
timestamp: February 02, 2013, 08:51:34 pm
content: Quote from: Simon on February 02, 2013, 04:00:18 pmYou might get away with that, but the clock movement is mechanical and "slow" in electronic terms. If you make the pulse current deviate too far away from the specification it may not work reliably.Since you have a specified current between 170 and 270 mA I would suggest configuring a simple constant current source at about 220 mA and using that to feed the clock output.

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 09:11:52 pm
content: The current requirement will have been a min to make sure it ticked and a max to make sure it was not overheated (leading me to assume decent pulse times), many clocks could be strung in series and I guess there were only so many standard batteries voltages available, I figure the voltage was to be between 2.4 and 3.8 volts (based on 14 ohm coil resistance), I plan on using 3 AA batteries (3.6-4.8V) and a slightly shorter pulse than what would have been or to use a resistor, as long as enough magnetic energy is generated in the coil to attract the arm it will work, the return motion is done by mechanics, all the electric does is attract an arm to the electromagnet and that pulls on a cog, another sprung arm does the rest

author: IanB
author_rank: Super Contributor
timestamp: February 02, 2013, 10:15:18 pm
content: Yes, but it takes a certain amount of time for the magnetic field to build up in the coil and the arm to be attracted. If you make the pulse too short it may not work. I guess as long as it works when you test it you will be fine.

author: Simon
author_rank: Unknown
timestamp: February 02, 2013, 10:27:01 pm
content: well the arm is quite close and with 100mS I get a healthy clunk plus I'll be running a slightly higher voltage. I don't know much about electromagnetic's but as you say experimentation will provide me with the solution. I guess if i can get an MCU to tick every 30s I can pick and choose my pulse length at will.

author: grumpydoc
author_rank: Super Contributor
timestamp: February 02, 2013, 11:10:51 pm
content: Why do you need a microcontroller for this anyway? An oscillator built from a 32.768Khz crystal divided down by 2^14 (a 4060) will give 2Hz, divide this by 60 with a couple of 4017's and you have a 1/30Hz square wave.

author: JackOfVA
author_rank: Unknown
timestamp: February 03, 2013, 12:08:29 am
content: The telephone line synchronization mechanism is almost certainly a higher voltage / current limited arrangement and would be emulated with a constant current driver mechanism, instead of a low voltage supply where the voltage is set to deliver the rated current based on the coil resistance.The reason for this is the current rise time. In a simple series resistor inductor arrangement, the time constant t = L/R where L is the inductance and R is the resistance. The time constant determines how fast the current rises in the series circuit when applied from a 0 point. As R increases, t decreases and hence the current builds up faster which is almost certainly a good thing in a mechanical device of this type.If L = 1H, to put a number to the equation, and R=17 ohms, one time constant = 1/17= 58ms. At one time constant, the current is 63% of the steady state value.In a typical telephone line system, the DC supply is -48V (in the US, at least. Some EU countries were -54V if I remember correctly.) To limit the current to the rated value, an additional series resistor is used. Plus, of course, the series resistance of the telephone line itself.Taking our example with 14 ohms coil resistance and 220 mA to take the mid-point of the 170-270 mA values, the total resistance required with -48V DC source is R=48/0.220 = 218 ohms. This resistance would be the sum of the coil resistance, the phone line resistance and a current limiting resistor at the telephone central office.But look what happens to the time constant; t = 1/218 = 4.5 ms, more about 12 times faster. Hence, the magnetic solenoid pull will happen much faster.There are other reasons telephone line circuits are configured this way, including limiting short circuit current, and at least in the US, 220 mA would be considered definitely on the high side for maximum sourced current over a normal pair.All this being said, it is possible to emulate this high voltage driving circuit with a lower voltage and a constant current driver device. The constant current driver can be as simple as a 3-pin fixed voltage regulator -- most data sheets for the 78xx series regulators include a circuit demonstrating how to make a constant current regulator.

author: Simon
author_rank: Unknown
timestamp: February 03, 2013, 08:39:53 am
content: surely the rise time will go down if there is less resistance in the circuit as that will just burn up current and limit it to the magnetic circuit. I could put a series resistor in to limit inrush current a bit and compensate for the slightly higher voltage, or I can just use 2 AA's instead but I'm not sure the mosfet will fire as that's putting the gate voltage a bit low, or I can tap off the second battery and use the 3rd only for the MCU.I want to avoid any regulators as the quiescent current will kill off the battery life, with impulses of 100mS or less that gives me just over a month on 1A of battery.Yes I could use counters etc but I'm not well versed on "discrete digital" and I'd like to have some practice on MCU's plus it will make it more flexible when I want to change the timings

author: SeanB
author_rank: Super Contributor
timestamp: February 03, 2013, 09:46:39 am
content: IBM made the original system ( before they did computers they did time clocks) and used a 6V battery made from large carbon cells ( the old PO local battery cells that were used in party line phones) along with a series resistor in each clock to keep the current corract. All clocks are in parallel, with a resistor for each one. You just do the same, and do not use a catch diode, but use a 24V zener across the transistor ( 400mW will do) to protect it, you need a fast collapse of the current in the coil. 100mS drive to the coil is fine, they normally had a pulse up to 1S as drive, but do work with smaller ones. Just add a series resistor with it to get the correct current with a 5V drive.

author: MartinX
author_rank: Regular Contributor
timestamp: February 03, 2013, 09:59:28 am
content: When I saw this I thought exactly what grumpydoc said in his post and I thought of exactly the same circuits, and I would add one 4538 in the end so you could adjust the output pulse length to whatever the clock needed.There is no way you could calculate what the clock needs just knowing the data of the coil, the mechanical movement involved needs more investigation. The best way to decide witch pulse length to use is to drive the clock with a pulse generator and a transistor, use the lowest battery voltage you are aiming for and see how short the pulse is when it stops working, then while looking at the mechanism working increase the pulse length until you are satisfied the clock works reliably, if you have no real data telling you what the clock needs this is the best you can do I think.

author: SeanB
author_rank: Super Contributor
timestamp: February 03, 2013, 11:13:32 am
content: Remember the master clock used a pendulum about 50cm long which took 30s to make a swing, and which drove a contact as the pawl engaged to drive the excapement. Not much more, and pulse width is not terribly critical, it just has to occur long enough that the coil reaches a steady state current. 100mS will be enough, and will not do much to the battery supply over a shorter pulse, You have a sub 1% duty cycle, and the battery will essentially have close to shelf life.

author: PA0PBZ
author_rank: Super Contributor
timestamp: February 03, 2013, 11:48:29 am
content: Quote from: SeanB on February 03, 2013, 11:13:32 amIsn't 50 cm more like 1.4 seconds?

author: SeanB
author_rank: Super Contributor
timestamp: February 03, 2013, 12:09:17 pm
content: Mechanical divider( gears) ran the contacts, gives a smaller clock and you do not need a grandfather sized cabinet for the master clock. That also ran off the electrical pulse output, and had a switch to either add pulses or stop pulsing to compensate for errors, generally they would add or subtract one or 2 units a week when correctly adjusted ( invar pendulum which has temperature compensation in it) to do fine tuning. When set up correctly all keep perfect time.

author: Simon
author_rank: Unknown
timestamp: February 03, 2013, 03:07:55 pm
content: Why should I not use a back e.m.f. diode ? I'm using a 100V mosfet so maybe I can even do away with the zenner ?, I don't know what effect the inrush current to the coil will make but with 100mS pulses it takes (using ohms law on just the resistance) 0.8mA for the coil so for every mA of battery that is 40 days, not that long really, what capacity is a standard AA battery ?

author: SeanB
author_rank: Super Contributor
timestamp: February 03, 2013, 03:15:51 pm
content: AA cell starts at 500mAH for a rechargeable cell, a typical AA alkaline is 2AH at best, so you will get a lot of operating time out of them, probably a year or more. The micro will use more in running the clock.

author: Simon
author_rank: Unknown
timestamp: February 03, 2013, 03:18:20 pm
content: I thought a micro on a clock crystal used micro-amps, the coil thought will rack up current surely

author: SeanB
author_rank: Super Contributor
timestamp: February 03, 2013, 03:32:50 pm
content: The clock takes most of the power in a sleeping microcontroller. If it is executing then the power consumed is higher. If you write the code so the micro is using a internal counter to count clock cycles and wakes on interrupt when overflow occurs then the power used will be roughly 2x the oscillator power ( cmos dividers generally use less power the slower the clock, they are basically acting as a switched capacitor filter simulating a resistor across the power rails) while sleeping. That will be the major factor in battery life, even though it is a milliwatt draw it adds up with time.

author: Simon
author_rank: Unknown
timestamp: February 03, 2013, 03:35:23 pm
content: So I should keep the micro asleep as long as possible and the counter trip can wake it and produce the pulse - providing i use an interrupt.

author: SeanB
author_rank: Super Contributor
timestamp: February 03, 2013, 04:00:27 pm
content: Yes. Unclocked and depowered silicon uses a lot less power than powered and switching silicon.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: February 03, 2013, 04:06:02 pm
content: It's all those transitions from 0 to 1 and 1 to 0 that use the power.The slower the clock, the less transitions, the less power.

author: Simon
author_rank: Unknown
timestamp: February 03, 2013, 04:07:56 pm
content: that was the idea of a 32 KHz clock ?

author: vk6zgo
author_rank: Super Contributor
timestamp: February 03, 2013, 04:26:56 pm
content: Quote from: Simon on February 02, 2013, 04:00:18 pmAre you sure about the pulse every 30 seconds?It seems counter intuitive to do this,as you then have to use a spring mechanism or similar to run the clock during the other 29 seconds.The Pulsynetic clocks they had at my old Radio Station produced one pulse per second,which drove the slave clocks directly.The Master clock was a "Grandfather" type,where,if the pendulum swing dropped below a set distance,it operated an electromagnet to give the pendulum a "push"

author: IanB
author_rank: Super Contributor
timestamp: February 03, 2013, 04:32:43 pm
content: Quote from: vk6zgo on February 03, 2013, 04:26:56 pmThe clock doesn't have to run for the other 29 seconds. It just sits there doing nothing. Each pulse advances the minute hand by half a division (and there is no second hand).I've never seen or heard a master/slave clock in the UK with a 1 second pulse. If you listened to them in a quiet room they went "clonk" every now and then and you saw the minute hand step forwards.

author: Simon
author_rank: Unknown
timestamp: February 03, 2013, 04:34:44 pm
content: yes, this is purely mechanical and the steps of the mechanism are in 30 seconds so it just needs a pulse to advance it, and yes it is one hell of a clonk compared to a modern clock, you'd not want that going off every second

author: SeanB
author_rank: Super Contributor
timestamp: February 03, 2013, 04:40:42 pm
content: http://www-03.ibm.com/ibm/history/exhibits/cc/cc_room.htmlA lot of info there......

author: Simon
author_rank: Unknown
timestamp: February 03, 2013, 04:43:55 pm
content: This one was made by "Gents of Leicester"

author: vk6zgo
author_rank: Super Contributor
timestamp: February 04, 2013, 09:07:52 am
content: Quote from: IanB on February 03, 2013, 04:32:43 pmYeah,thinking about it,you are right,it didn't have a second hand----ignore my comment.I must have confused it with the ordinary electric clock at the other end of the transmitter hall.The Grandfather clock made an even bigger "clonk" when it reset the pendulum.