1

I am making a solid wood clock using minimal components. So far, I thought of using 21 LEDs to make 7 segment displays (3 LEDs for each segment (overall 63 LEDs for the displays)), 6 LEDs for the 1 in the ten hours place (it's going to be a 12-hour clock), 2 LED's For the seconds indicator between the minutes and hours, 2 LED's each for PM and AM, 2 Buttons to change time, a PIC16F628A, 3 4094 Shift registers for the displays, a Crystal obtained from an old digital watch, and a couple of extra things.

The first question is: What is the frequency of the clock I obtained from the watch? And will it work well with the microcontroller? What caps should I use along with it? Is there anyway to test to see if it still works?

The Crystal doesn't have any text printed on it, it's 3mm wide and 8mm high without the leads.

The 4094's datasheet isn't exactly clear to me how to use it, BTW I'm programming using CCS, is there any easy tutorial for beginners on the 4094?

Lastly, what batteries should I use to power it, and how long will the battery last?

Thanks in advance.

stevenvh
  • 145,145
  • 21
  • 455
  • 667
Seif Shawkat
  • 301
  • 1
  • 6
  • 13

2 Answers2

4

First go here and get the datasheet for the microcontroller. Read the table of contents. It has pretty much all information you need. If you take a look at the oscillator section (14.2), you'll see wha you can use with this microcontroller. Basically (if we assume that the watch crystal is 32.768 kHz, but more on that later) you'll need to use capacitors in the 15 pF to 30 pF range for the oscillator to work and use the LP mode. Also from the same page:

Note: Higher capacitance increases the stability of the oscillator, but also increases the start-up time. These values are for design guidance only. A series resistor (RS) may be required in HS mode, as well as XT mode, to avoid overdriving crystals with low drive level specification. Since each crystal has its own characteristics, the user should consult the crystal manufac- turer for appropriate values of external components.

This brings me to my next topic. I'd recommend against using the salvaged crystal if at all possible. While the crystal may be operational, you don't have its specifications and the standard can isn't going to be easy to identify (and the assumption that the crystal is 32.768 kHz may even be wrong!). Instead I'd recommend that you get a crystal from a reputable source and to read the crystal's datasheet. It will probably have more information on the needed capacitors, crystal's accuracy and so on.

Also depending on the amount of work that the microcontroller needs to do, you may end up needing a faster clock, since PICs are a bit slow. For example each instruction needs around four cycles to complete. That gives you around 8192 assembly instructions which you need to execute before updating seconds counter. It may seem like a large number, but it can quickly be eaten up if you're going to do some more complicated programming in C. Be sure to check exactly what compiler gives you and to confirm that the execution time will be good enough. If you only want a clock, then I think that 32.768 kHz would be enough.

The battery side of the equation is also not very simple. You're going to need to precisely adjust the amount of light LEDs provide and compare that to battery capacity, since I expect LEDs to be the major consumers here. Next important point is the mass and the volume of the clock. In general, for easy work with LEDs, you'll want at least some 3 V. That gives us say two AA cells in series. Depending exactly on the circuit you build, you could go up to as much as 4 AA cells in series (but keep in mind that the maximum voltage is 6.5 V for the PIC). If your LED driving circuit is good enough, you may be able to get visible output until the batteries are completely discharged. For more capacity and if space isn't a problem, you could go for even bigger batteries such as C or D cells.

Another option would be to go with higher voltage, but that will bring voltage regulation into equation. You could connect LEDs from same segment in series and use same current for several LEDs and save a bit that way, but on the other hand you'll be wasting power on the regulation for the PIC. If you can get a high efficiency switch mode regulator to provide the needed voltage for the PIC, it would be great (and expensive or complicated), but a linear regulator could be using a bit too much power.

Basically the most important part about voltage is how you drive the LEDs and how good the look at various current levels. You may need to tweak that to get best appearance with minimal current because that will give you greatest reduction in power consumption. Next you could have fund with various sleep states of the microcontroller to make sure its power consumption is low enough. In the end, you'll most likely have to actually measure the current consumption and see check that against the battery datasheets (which are available on web sites of battery manufacturers).

About the comments...

First: I heard that If you connect the LEDs in series you don't get as much light.

Well, yes and no.

When you're making a classical LED circuit consisting of a voltage source, resistor and an LED, you should set the resistor so that the it limits the current going through the LED to a value that will correspond to light level you want. Often this will be the maximum current the LED is rated to use if you want lots of light. The simplified equation would look like this: \$ I_{dmax}=\dfrac {V_{cc}-V_{fd}}{R}\$

If you add another LED to that circuit, each of the LEDs will be less bright than the single LED was because you'll have two forward voltage drops which will decrease the total current through the circuit, so you'll have basically \$I= \dfrac {V_{cc} - 2 V_{fd}}{R} \$ (assuming that this even works in the first place). However to solve that problem you should design the circuit so that the current will be equal to \$I_{dmax}\$ even with two forward voltage drops. In this case, each of the LEDs will be as bright as the LED in the single LED was. That is usually obtained by using a resistor with lower resistance value. Do note that as a group, the two LEDs will emit more light than a single LED.

The main advantage here is that LEDs have large forward voltage drop which is somewhere between 2 and 3 V, depending on the type. You can very easily power several LEDs using a single "high" voltage battery (say 9 V) and share the current among them giving you power savings compared to the case of having each LED connected individually to the voltage source and is better than having LEDs in parallel, since this will produce more light.

Next about the case of several LEDs connected to a single resistor. Well I already asked about it here. The answers seem pretty good to me and explain the problems faced by that setup. Basically, a little bit exaggerated version of what you get is this. If you're fine with that, the circuit is (more or less) OK. If you want to get the maximum out of every LED there, then you need a different setup (and I'm assuming here that each individual LED can take those 14.75 mA). Then there's also this question too.

If you want to reduce the number of resistors, you'll be doing that by decreasing brightness, as I've mentioned. Yes, that can simplify wiring, but you're basically limiting each "segment" to lower brightness than needed. Instead of that (if the available LEDs are too bright), it would be a better idea to get LEDs which are rated for lower current consumption (you can get some which are as low as 2 mA) and save power by using them, since you're on battery.

Also is there any special reason to avoid extra resistors? They won't make a major impact on the total price of the project and if there are any special consideration not mentioned in the original question, please write them so we can provide a better answer.

AndrejaKo
  • 23,261
  • 25
  • 110
  • 186
  • I'm planning to power the LEDs like this: http://bit.ly/zFgKXT However, I don't really know how to use the 4094 shift register and what voltage it ouputs. – Seif Shawkat Mar 03 '12 at 19:23
  • @Seif Shawkat I never used that component either, but I can tell you this: The resistor setup is a **BAD** idea. The diodes aren't perfect and one diode in the segment will draw all the current, overload and die and then the circuit will move to frying the next diode in line. If you use a single resistor that will limit the current for the whole segment to a value safe for one diode, like in the simulation, you'll get uneven amount of light from the diodes. – AndrejaKo Mar 03 '12 at 20:12
  • So should I use a resistor per LED? If so, what batteries do you recommend (I think 9V will do). – Seif Shawkat Mar 03 '12 at 20:39
  • @Seif Shawkat I'd recommend that. Also I believe that you should avoid the usual 9 V batteries because of their very low capacity. Furthermore, the 9 V batteries will require voltage regulation! So you gain nothing using them and shown LED setup and loose money in the long run. Instead get a 4 AA holder and use it to make a 4 AA cell battery. You'll be able to connect the battery directly to the microcontroller (because maximum voltage is 6.5 V for its inputs) and it will be able to work until the batteries are completely discharged. – AndrejaKo Mar 04 '12 at 12:43
  • @Seif Shawkat If you want to use 9 V battery, I again recommend against using the usual prefabricated 6LR61 9 V batteries and get instead a holder for 6 AA cells. For example a typical capacity of a LR6 AA cell is 2600 mAh, while a typical capacity of 6LR61 battery is 500 mAh. Next point is to use several LEDs connected serially, for example have all LEDs in a single segment connected in series. They will share current and you'll get lower power consumption compared to having each LED with its own resistor. Unfortunately, you'll have to use a regulator for powering the PIC. – AndrejaKo Mar 04 '12 at 12:51
  • I heard that If you connect the LEDs in series you don't get as much light. However, I don't know what the problem is with just using this setup http://bit.ly/zFgKXT I have used it in many of my previous circuits and it worked flawlessly. I read more about shift registers and decided to buy a SIPO 74164 shift register as I will suit my needs. I believe if I connect one resistor to the VCC pin, I wouldn't have to use resistors for the eight outputs, please correct me if I'm wrong because I'm not really sure if that's true. – Seif Shawkat Mar 04 '12 at 18:05
  • @Seif Shawkat Added update at the end of the question. – AndrejaKo Mar 04 '12 at 20:59
  • I just wanted to know how to wire up the resistors. The LEDs I'm going to use: http://ram-e-shop.com/oscmax/catalog/product_info.php?cPath=60_61&products_id=232 So what do you recommend now, resistor per LED? Anyway why do the equations show as [Math Processing Error] ? Also do you recommend 4 AA Batteries? – Seif Shawkat Mar 04 '12 at 22:41
  • I just discovered that the source I'm buying from only has a 3 x AA Battery holder and not a 4x, that is 4.5V (47 ohm 1/4W resistor to power LEDs) Is that enough to power the pic microcontroller and the whole clock? If so, about how long will it last? – Seif Shawkat Mar 04 '12 at 23:21
  • @Seif Shawkat Equations show like that because of bugs on the site. Some time later, it will pass. I not comfortable giving you recommendations at this stage. My advice is to instead make the clock case and mount a segment both with resistor limiting current for whole segment and with each LED individually and see how each setup looks and then decide which one is better. You may also need to tweak the resistor value to provide best output for the diodes. As for running PIC, look under electrical characteristics in the datasheet. – AndrejaKo Mar 04 '12 at 23:33
  • @Seif Shawkat I think that it can run fine from 3 V to 6.5 V, but I'm not sure right now of the lower limit. It may work with even lower voltages. Another factor is going to be the LED setup. You need to tweak the resistor values so that it looks good both at the voltage you decide to call the battery dead and to survive full batteries. So test with at least 3 V on the low scale and with 5 V on the high scale if you have adjustable power supply.If you don't try the holder with two full batteries and short the remaining battery spot and see how the clock looks(do this with only one segment) – AndrejaKo Mar 04 '12 at 23:36
  • @Seif Shawkat I can't give you estimate on how long the clock will run because it depends a lot on how you actually program it to work. You can have diodes output constantly, which will give you brighter output and higher power consumption or to pulse them at some frequency in addition to use of the shift register. It also depends on how aggressive sleep of the microcontroller is. The more you sleep, the less you use. I can't say how much power the inputs of the shift register will take and that will have a big impact on power consumption. – AndrejaKo Mar 04 '12 at 23:40
  • @Seif Shawkat I keep talking about use of low power LEDs and their tweaking becasue just the 7 seg display made of individual LEDs can take up to 310 mA (based on the simulator) if they're on all the time! And your battery, if you use AAs, will have say 2600 mAh, so you have in the worst case some 8 hours of work. As you can see, we need to drastically increase that time! So what I recommend is to experiment with various segment currents and various duty cycles for segments to get as low current as possible with good amount of light. – AndrejaKo Mar 04 '12 at 23:47
  • at first I thought just to use a 5V wall adaptor, con is that – Seif Shawkat Mar 05 '12 at 05:11
  • @Seif Shawkat ??? Is there a part of the comment missing? If you want to use such a device (with appropriate current rating), you could spend very little time optimizing power consumption, since you'll usually have more than enough power available. – AndrejaKo Mar 05 '12 at 06:57
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/2699/discussion-between-seif-shawkat-and-andrejako) – Seif Shawkat Mar 05 '12 at 17:25
  • sorry, submitted the comment before I finished typing. Anyway, I mean to say that the con is whenever there is a power outage, I will have to Set the time again (unless I use an RTC and a backup battery however that will increase the cost and I dont know how to use an RTC) – Seif Shawkat Mar 05 '12 at 17:25
1

The watch crystal will be 32.768kHz, so devide by 2^15 for 1Hz