Badcaps.net Forum
Go Back   Badcaps Forums > Electronics Theory and Troubleshooting > General Electronics Technical Discussion
Register FAQ Calendar Search Today's Posts Mark Forums Read

 
Thread Tools Display Modes
Old 12-08-2017, 01:26 AM   #141
eccerr0r
Solder Sloth
 
eccerr0r's Avatar
 
Join Date: Nov 2012
City & State: CO
My Country: USA
Line Voltage: 120VAC 60Hz
I'm a: Hobbyist Tech
Posts: 2,346
Default Re: 555 countdown timer design question

Quote:
Originally Posted by Curious.George View Post
You don't need a crystal (adds cost). Use the AC mains as your timebase. Crudely rectify it and count 50 cycles for each second of delay that you want. In this way, you don't care how "fast" the processor clock happens to be.
Why would you use AC mains cycle counting if you're using a microcontroller, if you clock it at 50Hz/60Hz it'd only run 50-60 instructions per second and it would basically be unusably slow. If you're using a crystal with a microcontroller, you might well as use that.

If you mean using it with discrete electronics, you have to keep 6 bits of state per second, which means your discrete counter will balloon in logic size.

All unless you're using a FPGA or something, it doesn't make sense to use AC for time counting. Or if you're using a synchronous motor...
eccerr0r is offline   Reply With Quote
Old 12-08-2017, 01:49 AM   #142
Dannyx
Badcaps Veteran
 
Dannyx's Avatar
 
Join Date: Aug 2016
City & State: Constanta
My Country: Romania
Line Voltage: 230VAC 50Hz
I'm a: Hardcore Geek
Posts: 910
Default Re: 555 countdown timer design question

Quote:
Originally Posted by Curious.George View Post
But you've really not indicated exactly what it must do.

What does "60 seconds" mean? 60 +/- 0.5 sec? 60.0000 sec? "About a minute"?

Will it always be "60" or will you later decide that you'd like it to be 70? Or 120?

Getting reliable, repeatable long delays from an RC delay is tricky. What are teh tolerances on your components? Operating temperature range? etc. Do you plan on "select at test" -- or, worse, adding a trim pot? -- to tweek the delay to the desired accuracy?

While a < $1 MCU might seem like overkill, it can give you the benefit of a highly repeatable and alterable design. What if you want to inhibit the light from being retriggered within 37 seconds of extinguishing? What if you want to start your 60 second interval when a button is released instead of when it is initially depressed (or vice versa)? Or, if you want to adjust the duration of the period based on how long the button is held depressed? etc.
Let me explain: you press the button, the light stays on for 60 seconds (a minute if you prefer). You press AND hold the button (for say a second), the light stays on permanently. If the light is already on, regardless of which of the above states, pressing the button will turn it off. Simple right ?
__________________
Wattevah...
Dannyx is offline   Reply With Quote
Old 12-08-2017, 01:50 AM   #143
stj
Great Sage 齊天大聖
 
stj's Avatar
 
Join Date: Dec 2009
City & State: Europe
My Country: some shithole run by Israeli agents
I'm a: Professional Tech
Posts: 16,839
Default Re: 555 countdown timer design question

Quote:
Originally Posted by Curious.George View Post
You don't need a crystal (adds cost). Use the AC mains as your timebase. Crudely rectify it and count 50 cycles for each second of delay that you want. In this way, you don't care how "fast" the processor clock happens to be.
this is not just a timer, it's a remote controlled timeswitch with override facility.
stj is offline   Reply With Quote
Old 12-08-2017, 01:24 PM   #144
Curious.George
Member
 
Join Date: Nov 2011
Posts: 52
Default Re: 555 countdown timer design question

Quote:
Originally Posted by Dannyx View Post
Started messing around with the code and adapting it to my needs, but I'm only able to follow up to a point.
IME, your best bet for this sort of problem is to model it as a FSM (see below). Otherwise, you'll end up with spaghetti code and wonder why it only works properly in some cases (i.e., states).

Quote:
My idea is the following: If the press is longer than "longPressTime", the code does one thing (turn on the light permanently) and if it's shorter, the Else should take over and do something else (in my case activate the 60s timer which I haven't implemented yet because I don't know where to drop it), so my guess is that the second Else belongs to the IF statement which checks the press time.
Consider (pseudo-code with clumsy formatting):

State IDLE
On _ShortPress Goto TIMING Executing StartInterval()
On _LongPress Goto LATCHED Executing LampOn()
Orelse IDLE Executing Consume()
State TIMING
On _TimeOut Goto TIMED Executing EndInterval()
On _ShortPress Goto TIMED Executing EndInterval()
On _LongPress Goto LATCHED Executing LampOn()
Orelse IDLE Executing Consume()
State TIMED
On _Precharged Goto IDLE Executing Reset()
On ...
Orelse IDLE Executing Consume()
State LATCHED[/INDENT]
On _ShortPress Goto TIMED Executing EndInterval()
On _LongPress Goto LATCHED Executing LampOn()
Orelse IDLE Executing Consume()

StartInterval()
LampOn()
spawn(MarkTime)
EndInterval()
LampOff()
kill(MarkTime)
spawn(PrechargeDelay)
LampOn()
output(Lamp = On)
LampOff()
output(Lamp = Off)
MarkTime()
Wait(60 seconds)
Signal(_TimeOut)
PrechargeDelay()
Wait(3 seconds)
Signal(_Precharged)

A separate FSM watches the switch, debounces it and conditionally synthesizes _ShortPress and _LongPress events.

Note that none of these routines need be aware of how they are being used.

The FSM illustrated operates in three basic states:
  • when the machine is IDLE, a long (button) press moves it to the LATCHED state and turns on the lamp in the transition
  • a short press, while IDLE, moves the machine to the TIMING state, turning the lamp on, in the transition, and starting a job that will monitor an "on timer" for the machine
  • while TIMING, this _TimeOut event will cause the machine to advance to the TIMED state, turning off the lamp in the transition
  • if a short press is encountered prior to the _TimeOut event, the machine will skip ahead to the TIMED state regardless of the time remaining on the timer
  • if a long press is detected while TIMING, the machine moves to the LATCHED state in a manner similar to encountering a long press while IDLE (i.e., turn the lamp on, unconditionally)
  • entry into the TIMED state by either of these transitions (via EndInterval()) starts a job that monitors a "precharge" timer. This puts a limit on how quickly the cycle will be allowed to restart. When the _Precharged event is signaled, the machine moves to the IDLE state where everything can repeat.
  • encountering a short press -- and only a short press -- in the LATCHED state causes the lamp to be extinguished as the machine advances to the TIMED state, simulating the expiration of a timed interval

(some of this behavior has been added just to illustrate how you can add more complicated behaviors without seriously mangling "spaghetti code")

[Apologies if there are any glaring errors as I didn't print this out to review it prior to publication]

Last edited by Curious.George; 12-08-2017 at 01:25 PM.. Reason: typos -- no doubt there are more!
Curious.George is offline   Reply With Quote
Old 12-08-2017, 03:45 PM   #145
Curious.George
Member
 
Join Date: Nov 2011
Posts: 52
Default Re: 555 countdown timer design question

Quote:
Originally Posted by Curious.George View Post
[Apologies if there are any glaring errors as I didn't print this out to review it prior to publication]
All of the Orelse clauses should select the "current state" as their target (instead of IDLE) I'd relied on cut-and-paste too much!
Curious.George is offline   Reply With Quote
Old 12-08-2017, 08:24 PM   #146
eccerr0r
Solder Sloth
 
eccerr0r's Avatar
 
Join Date: Nov 2012
City & State: CO
My Country: USA
Line Voltage: 120VAC 60Hz
I'm a: Hobbyist Tech
Posts: 2,346
Default Re: 555 countdown timer design question

dang, i feel like finishing my code... but so many options already on the table, or rather, post...

Yeah I ended up using a state machine model, alas I made a wrong assumption on capabilities of the target chip when I was mapping to actual code so I stopped trying. I was targeting straight gcc, not arduino, so I don't get nice cooked timing and button macros...
eccerr0r is offline   Reply With Quote
Old 12-08-2017, 11:39 PM   #147
Curious.George
Member
 
Join Date: Nov 2011
Posts: 52
Default Re: 555 countdown timer design question

Quote:
Originally Posted by eccerr0r View Post
Why would you use AC mains cycle counting if you're using a microcontroller, if you clock it at 50Hz/60Hz it'd only run 50-60 instructions per second and it would basically be unusably slow. If you're using a crystal with a microcontroller, you might well as use that.
Crystals are notoriously poor in terms of stability (initial, temperature, etc.). Wristwatches have good stability because they are temperature controlled applications (98.6 degrees)

You don't clock the MCU with the AC mains. Rather, you use the AC mains as a reference input. You can then poll it (at some frequency greater than ~100Hz) to recover the actual mains frequency or use it as an edge-triggered interrupt (if MCU has such a facility).

watchLFC() {
if (ACmainsInput == lastACmainsInput) return
lastACmainsInput = !lastACmainsInput
if (lastACmainsInput == HIGH) signal(LineFrequencyClock)
return
}

Now, you have a derived frequency source that, over the long run, will track the frequency of the AC mains. There will be some phase jitter due to the lack of perfect synchronization in the sampling routine, above -- which can be minimized by increasing the sampling frequency.

If you know the nominal line frequency that the device will be operating at (e.g., OP was 50Hz), then you can put a number on your results; e.g., every 50 LFC events translates to 1 second.

If you have to support dual 50/60Hz application, then you can use a grossly imprecise knowledge of your XTAL (which may be ceramic resonator, RC, etc. on low end MCU's) to make a decision as to the apparent line frequency (i.e., count CPU cycles for one or two LFC events and if less than some threshold, decide that the higher line frequency is the case; else the lower)

I use this approach in most of my timekeeping software with a cascaded control loop to exploit the short term stability of the XTAL to compensate for short term variations in the AC mains (in the US, the line frequency is really only stable over long periods of time -- like many hours -- and can have short term deviations)
Curious.George is offline   Reply With Quote
Old 12-08-2017, 11:46 PM   #148
Curious.George
Member
 
Join Date: Nov 2011
Posts: 52
Default Re: 555 countdown timer design question

Quote:
Originally Posted by Dannyx View Post
Let me explain: you press the button, the light stays on for 60 seconds (a minute if you prefer). You press AND hold the button (for say a second), the light stays on permanently. If the light is already on, regardless of which of the above states, pressing the button will turn it off. Simple right ?
And that's exactly what my sample code does -- except I have decided that the press to turn it off (if it is in "latched on" mode) must be of short duration. This is an arbitrary restriction -- but one that I feel makes sense.

Light has come on because you pressed the button "briefly". You have no way of knowing that this is the case -- you will only know, for sure, in ~60 seconds (if the light goes OFF, then the circuit must have thought you only pressed it briefly... whether that was your intention, or not; if it stays ON, then you must have pressed it "longer").

If you want to force the light to STAY on, even though you initially only wanted it to turn on for 60 seconds, I'm suggesting you should be forced to press it for a long duration -- just like you would have when it was OFF.

To turn it OFF while it is already on, I expect a short press. I.e., the duration of the press while ON indicates whether you want it to LATCH on or toggle back off, now.
Curious.George is offline   Reply With Quote
Old 12-08-2017, 11:50 PM   #149
Curious.George
Member
 
Join Date: Nov 2011
Posts: 52
Default Re: 555 countdown timer design question

Quote:
Originally Posted by stj View Post
this is not just a timer, it's a remote controlled timeswitch with override facility.
Doesn't matter. The reference for the timekeeping portion of the algorithm is the issue addressed by the line frequency clock. You can use the LFC to drive a time-of-day clock, a timer, or set the blink rate of some XMAS lights. The point is that it is already there and isn't going to vary with temperature, etc.
Curious.George is offline   Reply With Quote
Old Yesterday, 01:12 AM   #150
eccerr0r
Solder Sloth
 
eccerr0r's Avatar
 
Join Date: Nov 2012
City & State: CO
My Country: USA
Line Voltage: 120VAC 60Hz
I'm a: Hobbyist Tech
Posts: 2,346
Default Re: 555 countdown timer design question

Crystals are specced to number of PPM, which is extremely accurate for over long periods of time. Most of the time the crystal inaccuracy is because of either selecting cheap crystals, bad circuit design like omitting or having too much capacitance on wires, damage by bad soldering, or even badly written software. Otherwise good crystals are very accurate if it's designed carefully.

Also note people do not necessarily wear their watches 24/7, would accuracy be lost when removed? Usually crystals also are specced for PPM per temperature change too, which also is very low. I have a watch that has kept time for several years without being worn or being reset, thanks to a very accurate clock crystal. It finally lost time due to a bad CR2016, they sure do not last forever.

On the other hand, if you're using the onchip clock source inside newer microcontrollers, these however can be off by a few percent, these are nowhere near as accurate as actual crystals.

You also need to consider that there has been consideration to cheapen the cost of energy by no longer enforcing 50/60Hz AC mains frequency from power plants as fewer and fewer time elements are dependent on AC power and instead reliant on internet, WWVB, or even a crystal to keep parts count down so the same circuit can be used when on battery power. How many people still use synchronous motor clocks anymore? (How many people can still tell time on 2-hand clocks?)

But this is all moot, the accuracy (and precision) of this light timer has no problem being within even 5%.
eccerr0r is offline   Reply With Quote
Old Yesterday, 02:38 AM   #151
Curious.George
Member
 
Join Date: Nov 2011
Posts: 52
Default Re: 555 countdown timer design question

Quote:
Originally Posted by eccerr0r View Post
Crystals are specced to number of PPM, which is extremely accurate for over long periods of time.
You are conflating accuracy and stability. They are not the same.

Quote:
Most of the time the crystal inaccuracy is because of either selecting cheap crystals, bad circuit design like omitting or having too much capacitance on wires, damage by bad soldering, or even badly written software. Otherwise good crystals are very accurate if it's designed carefully.
I thought the goal here was cheap? I didn't realize the OP could afford a TCXO for his light timer...

Quote:
Also note people do not necessarily wear their watches 24/7, would accuracy be lost when removed?
Accuracy != stability. And, watches, even when not being worn, seldom experience a wide range of temperature variations. By contrast, the light on my back porch experiences almost 100 degrees of variation over the course of four seasons (easily 50 degrees on any given day). The indoor temperature of my home seldom varies by more than 10 degrees (F) and is usually within 25 degrees of my wrist's temperature.

Quote:
Usually crystals also are specced for PPM per temperature change too, which also is very low. I have a watch that has kept time for several years without being worn or being reset, thanks to a very accurate clock crystal. It finally lost time due to a bad CR2016, they sure do not last forever.
Watch makers have invested a fair bit of effort into optimizing their 32768Hz XTALS by carefully controlling things like cut angle. And, it's unlikely that you've kept your watch stored out in the (unheated) garage for all that time. Wanna bet its been at 98.6 or ~75 degrees for most of its life?

Also note that ceramic resonators (less expensive than an XTAL) are typically thousands of ppm. XTALs (i.e., not "oscillator modules") also exhibit sensitivity to things like humidity, poor PCB cleaning, etc. And, folks often "pull" the XTAL off it's fundamental by poor choice of support components/bias/etc. I've seen cases where designs reliably (yet undesireably!) operated in an overtone mode -- evident because all of the timing was (way!) off.

Quote:
You also need to consider that there has been consideration to cheapen the cost of energy by no longer enforcing 50/60Hz AC mains frequency from power plants as fewer and fewer time elements are dependent on AC power and instead reliant on internet, WWVB, or even a crystal to keep parts count down so the same circuit can be used when on battery power. How many people still use synchronous motor clocks anymore? (How many people can still tell time on 2-hand clocks?)
Is the LIGHT that is being controlled also powered by batteries?

Quote:
But this is all moot, the accuracy (and precision) of this light timer has no problem being within even 5%.
Then your arguments against the stability of the AC mains falls away.

Yet, your reliance on the internal oscillator necessitates having a timer that can be (at least partially) dedicated to timekeeping. And, if that resource is shared with some other activity, its a prime spot for bugs to creep into the codebase when the timekeeping needs conflict with the "other" use of the timer.

And, you don't have to rely on the developer updating some manifest constant in the codebase when/if the parts list is changed in manufacturing (to use a different device or "timing component")

I find having a LFC in my designs almost always adds value (at the very least, it gives me advanced warning of a loss of power so I don't find my FLASH being corrupted due to an outage that happens as I'm updating it).
Curious.George is offline   Reply With Quote
Old Yesterday, 05:17 AM   #152
Dannyx
Badcaps Veteran
 
Dannyx's Avatar
 
Join Date: Aug 2016
City & State: Constanta
My Country: Romania
Line Voltage: 230VAC 50Hz
I'm a: Hardcore Geek
Posts: 910
Default Re: 555 countdown timer design question

It's most pleasing when a post spawns entire lectures on others devices and components and you get the chance to learn like a bit of crash-course - really informative stuff !
Dannyx is offline   Reply With Quote
Old Yesterday, 05:54 AM   #153
stj
Great Sage 齊天大聖
 
stj's Avatar
 
Join Date: Dec 2009
City & State: Europe
My Country: some shithole run by Israeli agents
I'm a: Professional Tech
Posts: 16,839
Default Re: 555 countdown timer design question

timing is not important, it's just to turn on a lamp long enough to go down/up a flight of stairs - we arent making a bomb or an alarm clock!
stj is offline   Reply With Quote
Old Yesterday, 11:01 AM   #154
Curious.George
Member
 
Join Date: Nov 2011
Posts: 52
Default Re: 555 countdown timer design question

Quote:
Originally Posted by stj View Post
timing is not important, it's just to turn on a lamp long enough to go down/up a flight of stairs - we arent making a bomb or an alarm clock!
ROTFLMFAO! Timing is the very essence of this application!

If the design goal is:

Quote:
Let me explain: you press the button, the light stays on for some amount of time You press AND hold the button (for say some other amount of time), the light stays on permanently. If the light is already on, regardless of which of the above states, pressing the button will turn it off. Simple right ?
Then I can satisfy it in a matter of seconds -- by handing you a CARDBOARD box with a black circle drawn on the top labeled "button". You can freely "press" it and the light (which I've opted not to include in the design because I've found it superfluous) will come on -- after some amount of time (that I've decided should be 2 minutes longer than the user's actual lifetime).

And, I guarantee that the second activation of that button will extinguish the lamp (that doesn't exist) -- sooner or later!

Time appears:
- in the switch debouncing algorithm (cuz that button most likely doesn't come on/off cleanly but, rather, makes several make/break cycles as it is actuating and/or releasing)
- in the discrimination of "short press" vs. "long press"
- in the determination of the "illumination period"

It could also, potentially, come into play in a "stuck button" detector (i.e., a button that appears to be shorted) or in an "open button" detector (e.g., if you expect the button to be pressed every day or so and haven't seen it pressed in weeks!) .

If you opt to add some "effects" to the lighting or extinguishing of the light (e.g., bringing it up to full intensity, slowly, and similarly dimming it back to extinguished), then it would play into the timing of those effects as well as the control of the firing angle of the SCR driving the lamp.
Curious.George is offline   Reply With Quote
Old Yesterday, 11:17 AM   #155
Curious.George
Member
 
Join Date: Nov 2011
Posts: 52
Default Re: 555 countdown timer design question

Quote:
Originally Posted by Dannyx View Post
It's most pleasing when a post spawns entire lectures on others devices and components and you get the chance to learn like a bit of crash-course - really informative stuff !
You can often get lots of "added value" from what appear to be trivial changes to a design approach.

For example, the line frequency clock can provide:
  • an indication that power is available
Products that support battery-backed operation often need to know when they are relying on their (fixed!) battery reserves and when primary power is available (e.g., to control charging circuits).
  • an indication of the nominal mains frequency
are we operating with 50Hz mains or 60? This can be used to adjust display refresh rates (e.g., to minimize "beating" in the display against the flicker of the ambient lights)
  • an indication of the actual, instantaneous mains frequency
this can be used to frequency lock sampling algorithms to improve noise rejection ("AC hum") in high impedance acquisition circuits
  • an early warning indication of impending power failure
so the software doesn't undertake an operation that could have costly consequences if interrupted (like updating FLASH); or, so the software can undertake an operation that has been previously deferred for efficiency/economy/durability (like storing parameters in nonvolatile memory that has a fixed number of write cycles before "wear out")
  • keeping time and time-related actions
already discussed
  • monitoring mains voltage
measuring the duty cycle of the LFC signal can (depending on design) give you an idea as to the actual peak voltage of the AC mains (higher duty cycle correlates with higher peak voltage as you're "slicing" the AC waveform and finding it "wider" at a particular fixed point)
  • mains phase information
the LFC can tell you when the zero-crossing occurs and enable you to control (or sense) relative to that actual point in time (think: SCR gate control for dimmers)
  • other characteristics of the mains
E.g., if the mains voltage (see above) and frequency (see above) are highly variable, you might decide you are operating in an unreliable environment. Or, that other "nasty" loads are present on the same branch circuit that potentially compromise some aspect of your operation. (for example, a UPS being fed by a flakey branch circuit will be perpetually switching in and out thinking that the mains are in the process of failing)
  • ???

Until you think about what you can do with a particular approach (instead of limiting it to your initial goal -- or, prematurely ruling it out!), you won't know what opportunities a particular design approach can provide!
Curious.George is offline   Reply With Quote
Old Yesterday, 02:38 PM   #156
eccerr0r
Solder Sloth
 
eccerr0r's Avatar
 
Join Date: Nov 2012
City & State: CO
My Country: USA
Line Voltage: 120VAC 60Hz
I'm a: Hobbyist Tech
Posts: 2,346
Default Re: 555 countdown timer design question

You still seem to be picking at details that do not affect all designs.
Quote:
Originally Posted by Curious.George View Post
You are conflating accuracy and stability. They are not the same.
Crystals are also very stable. It's not like we're working with RC oscillators.
Quote:
I thought the goal here was cheap? I didn't realize the OP could afford a TCXO for his light timer...
Crystals are cheap and you need one for the microcontroller anyway, not like you can omit it, so use what you already have available. For line frequency, you have additional costs detailed later.
Quote:
And, watches, even when not being worn, seldom experience a wide range of temperature variations. By contrast, the light on my back porch experiences almost 100 degrees of variation over the course of four seasons (easily 50 degrees on any given day). The indoor temperature of my home seldom varies by more than 10 degrees (F) and is usually within 25 degrees of my wrist's temperature.
You're missing the point here. When someone wears a watch, the watch is very warm. When the watch isn't worn, it stays cold. If there is a temperature dependence, having it one way or another will exasperate the problem.
Quote:
Also note that ceramic resonators (less expensive than an XTAL) are typically thousands of ppm. XTALs (i.e., not "oscillator modules") also exhibit sensitivity to things like humidity, poor PCB cleaning, etc. And, folks often "pull" the XTAL off it's fundamental by poor choice of support components/bias/etc. I've seen cases where designs reliably (yet undesireably!) operated in an overtone mode -- evident because all of the timing was (way!) off.
These are all poor design and assembly techniques, nothing wrong with a crystal that was selected and designed properly.
Quote:
Yet, your reliance on the internal oscillator necessitates having a timer that can be (at least partially) dedicated to timekeeping. And, if that resource is shared with some other activity, its a prime spot for bugs to creep into the codebase when the timekeeping needs conflict with the "other" use of the timer.
Again you need to pay attention to your code. Even if you use line frequency you still have to be careful you don't miss an interrupt for whatever reason if your code is busy doing something else.
Quote:
And, you don't have to rely on the developer updating some manifest constant in the codebase when/if the parts list is changed in manufacturing (to use a different device or "timing component")
What if someone travels abroad and uses it in a country that doesn't have the same line frequency? You have the same problem and still need to change the design to take it into account. Not only that, a crystal based time element doesn't care if you're in a 50 or 60Hz environment.
Quote:
I find having a LFC in my designs almost always adds value (at the very least, it gives me advanced warning of a loss of power so I don't find my FLASH being corrupted due to an outage that happens as I'm updating it).
It's up to you if you require your timing circuits to be tethered to the wall, but crystals are accurate and stable enough for most purposes to even be run on battery power. (Also note that most power providers don't guarantee cycle for cycle time accuracy, only that there will be about 4320000 or 5184000 cycles per day depending on locale.) You also require another input pin to the microcontroller which may be at a premium. If having to be connected to the wall is bad enough, you may also need to add in isolation to ensure protection from shock hazard which will also increase the BOM.

Ultimately these are all still design tradeoffs. If one needs to detect power loss anyway, then you might well use the data from the wall.
eccerr0r is offline   Reply With Quote
Old Yesterday, 08:47 PM   #157
Curious.George
Member
 
Join Date: Nov 2011
Posts: 52
Default Re: 555 countdown timer design question

Quote:
Originally Posted by eccerr0r View Post
You still seem to be picking at details that do not affect all designs.
I'm not trying to address "all designs". Rather, I'm explaining an approach that gives you capabilities and economies that are simply not available with crystals/resonators/xtal oscillators.

I design embedded systems so all of my designs have to "do" something (i.e., they don't just "add numbers" for display on a monitor or process files on a disk). Time plays a crucial role in almost all of the acquisition and control subassemblies -- especially when you're pinching pennies (e.g., give me a 24 bit A/DC for less than a dollar in tiny quantities)

Quote:
Crystals are cheap and you need one for the microcontroller anyway, not like you can omit it, so use what you already have available. For line frequency, you have additional costs detailed later.
Ah, but you don't need one for the MCU! You can use the crappy internal oscillator or even an RC. You only need to ensure that the MCU executes instructions fast enough for your application. You don't care if two units coming off the assembly line operate at two different frequencies; just so long as they both run fast enough for the application and within the operating specifications of the circuit you've designed.

Quote:
You're missing the point here. When someone wears a watch, the watch is very warm. When the watch isn't worn, it stays cold. If there is a temperature dependence, having it one way or another will exasperate the problem.
No, when the watch is NOT being worn, it stays "room temperature". Room temperature is usually only 20-30 degrees difference from body temperature. I don't know anyone who takes off their watch and leaves it outside in a snowbank while they go into their room-temperature home!

By contrast, a "timed light" might be sited outdoors or in a location that isn't intended to be inhabited 24/7/365. It may experience temperature ranges of 50 degrees each day and 100 degrees (or more) over the variation in seasons.

Quote:
Again you need to pay attention to your code. Even if you use line frequency you still have to be careful you don't miss an interrupt for whatever reason if your code is busy doing something else.
Does using a crystal absolve you of this responsibility?

Quote:
What if someone travels abroad and uses it in a country that doesn't have the same line frequency? You have the same problem and still need to change the design to take it into account. Not only that, a crystal based time element doesn't care if you're in a 50 or 60Hz environment.
Ah, my designs are already operating internationally and none have a "please select your country of operation" setting. By looking at the actual line frequency, I can ensure the code adapts to it without requesting that information from the user (how do you set the refresh frequency of your displays to minimize beat against local lighting without knowledge of the mains frequency?)

I can use the actual, instantaneous line frequency to adjust sampling algorithms in sensitive front ends to minimize "AC hum" biasing the data I'm dynamically collecting from my sensors -- without having to design quieter front ends, add shielding, ask the user for the current mains frequency (and hope it doesn't change from cycle to cycle). I have medical instruments that operate reliably in third world countries where primary power may be supplied by a genset -- so there are only nominal frequencies to design against; you have to respond to the actual frequency you're encountering now.

If something is dependant on line frequency, then the software is smart enough to compensate -- or, not depend on it!

Quote:
It's up to you if you require your timing circuits to be tethered to the wall, but crystals are accurate and stable enough for most purposes to even be run on battery power. (Also note that most power providers don't guarantee cycle for cycle time accuracy, only that there will be about 4320000 or 5184000 cycles per day depending on locale.)
How is that a problem? Counting is easy! Knowing the instantaneous mains frequency has proven so much of an asset, over the years, that I add facilities to systems that don't have direct access to the mains so that they can get this information (in real time) from something that does.

My "time of day" algorithm uses the AC mains over the long term to determine the frequency of the XTAL and the XTAL, in the short term, to specify short time periods -- as well as estimate the passage of time in the absence of power (e.g., if an RTC claims a certain amount of time has elapsed, the software, when the CPU is once again available, can scale that elapsed time based on its knowledge of what the RTC's XTAL frequency was observed (over the course of days, weeks, months, ...) to be.

Quote:
You also require another input pin to the microcontroller which may be at a premium.
Of course! Hence making sure that I can get a lot of added value from that signal: power available, nominal line frequency, actual line frequency, zero crossings, peak mains voltage, etc.

I'd rather "look ahead" of the power supply to see what will be happening to my "regulated power" in the near future than wait until that power starts to sag (or, worse, have to build in extra hold time so I can scurry to get my last minute housekeeping done as the supply starts to fail (any such sense would require a pin -- unless you rely on the brownout detector in some MCU's)

All an XTAL gives you is a sense of "time".

Quote:
If having to be connected to the wall is bad enough, you may also need to add in isolation to ensure protection from shock hazard which will also increase the BOM.
If you're powered from the mains, then you're already isolated. You can almost always gain access to the AC mains on the isolated side by carefully considering the design of the power supply. But, you have to approach each product holistically and not as a bunch of "isolated" subsystems that interact on narrow interfaces.

[I have products where the MCU actually acts as the switchmode power supply controller in the power supply that sources its power!]

Quote:
Ultimately these are all still design tradeoffs.
Of course! Engineering is the art of making value-preserving tradeoffs. Unfortunately, too often, folks opt for the "obvious" approaches and accept their shortcomings without question -- when other approaches can afford more capabilities.

E.g., if the OP decides he wants the light to dim up/down, he'll have to redesign his hardware if he's not made the AC mains signal observable. In my approach, it's just a software mod to drive the triac's gate at a particular time, relative to the mains' zero-crossing.
Curious.George is offline   Reply With Quote
Reply

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



Badcaps.net Technical Forums 2003 - 2017
Powered by vBulletin ®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
All times are GMT -6. The time now is 10:07 PM.

Did you find this forum helpful?