555 countdown timer design question

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • Curious.George
    replied
    Re: 555 countdown timer design question

    Originally posted by Curious.George
    [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!

    Leave a comment:


  • Curious.George
    replied
    Re: 555 countdown timer design question

    Originally posted by Dannyx
    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).

    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, 01:25 PM. Reason: typos -- no doubt there are more!

    Leave a comment:


  • stj
    replied
    Re: 555 countdown timer design question

    Originally posted by Curious.George
    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.

    Leave a comment:


  • Dannyx
    replied
    Re: 555 countdown timer design question

    Originally posted by Curious.George
    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 ?

    Leave a comment:


  • eccerr0r
    replied
    Re: 555 countdown timer design question

    Originally posted by Curious.George
    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...

    Leave a comment:


  • Curious.George
    replied
    Re: 555 countdown timer design question

    Originally posted by eccerr0r
    And another reason why microcontrollers are preferred, if you're using a crystal oscillator, it can be accurate down to parts per million, and even using the onboard oscillators in some even newer microcontrollers they have errors of only 1% or so. Using 5% resistors and +80-20% electrolytics, know knows what your real time constant will be
    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.

    Leave a comment:


  • Curious.George
    replied
    Re: 555 countdown timer design question

    Originally posted by Dannyx
    WAY overkill for what this thing needs to do
    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.

    Leave a comment:


  • Dannyx
    replied
    Re: 555 countdown timer design question

    Originally posted by stj
    the shortest distance is the first pair.
    if that makes sense.

    and the first "if" and last "else" are the second pair.
    Ok, but I believe the very first IF, the one that checks the button being pressed, doesn't have an else, since it doesn't expect to do something else if the button ISN'T pressed.

    Leave a comment:


  • stj
    replied
    Re: 555 countdown timer design question

    the shortest distance is the first pair.
    if that makes sense.

    and the first "if" and last "else" are the second pair.

    Leave a comment:


  • Dannyx
    replied
    Re: 555 countdown timer design question

    Started messing around with the code and adapting it to my needs, but I'm only able to follow up to a point. Just a quick question: whenever an IF.....ELSE statement occurs, I'm having trouble following which "else" belongs to which "if", for instance here:

    if (digitalRead(button) == HIGH) {if (buttonActive == false) {buttonActive = true; buttonTimer = millis();}

    if ((millis() - buttonTimer > longPressTime) && (longPressActive == false)) {
    longPressActive = true;
    relayState = !relayState;
    digitalWrite(relayOUT, relayState);} }

    else {if (buttonActive == true) {if (longPressActive == true) {longPressActive = false;}

    else {LED2State = !LED2State; digitalWrite(LED2, LED2State);} buttonActive = false; } } }

    The two elseS at the bottom: which one belongs to which of the IF statements above...if that makes any sense ? Sorry for posting a wall of text

    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.

    Leave a comment:


  • Dannyx
    replied
    Re: 555 countdown timer design question

    Space is at a premium and I'm trying to keep the whole project as small as possible, even if it meant a more complicated setup...there's actually something satisfying about having a functional mess of wires on your worktop

    Leave a comment:


  • stj
    replied
    Re: 555 countdown timer design question

    the real question is why you got this:
    https://www.ebay.co.uk/itm/181894982202

    instead of this:
    https://www.ebay.co.uk/itm/191773759569
    ?????
    it's worth the extra 60c for the onboard programmer!

    Leave a comment:


  • Dannyx
    replied
    Re: 555 countdown timer design question

    Ok, works perfectly now: that cap between pin 20 and the reset pin did the trick. Big shoutout to STJ for the help...here's the setup: the gray piece of wire stuck into the ZIF socket corresponding to pin 20 of the CH341 on the bottom goes to the cap and then the other end of the cap has another piece of wire stuck into the breadboard on the RST pin. A CD ROM audio cable came in very handy for fashioning a "programming cable" because I could just insert it straight into the TX/RX male headers on the CH341 without having to run individual jumpers and make a mess of wires everywhere
    Attached Files

    Leave a comment:


  • Dannyx
    replied
    Re: 555 countdown timer design question

    Originally posted by stj
    btw, second picture, lower left.
    5.1ohm resistor looks burned - did you try to power something big through the programmer, or short something??
    Yes it does look like sh!t, I agree....never even noticed now that you mention it. No, I don't believe it got overloaded in any way and the resistor checks fine on my meter, so it's not faulty, plus the programmer works.

    So I should place the cap between pin 20 and the reset pin ? Dumb question again, but what does the cap actually do ? Why not a piece of wire for instance ? Is a ceramic capacitor with 104 on it the right one ? I suck at these, I told you that
    Last edited by Dannyx; 12-07-2017, 03:46 AM.

    Leave a comment:


  • stj
    replied
    Re: 555 countdown timer design question

    btw, second picture, lower left.
    5.1ohm resistor looks burned - did you try to power something big through the programmer, or short something??

    Leave a comment:


  • stj
    replied
    Re: 555 countdown timer design question

    you need to connect the 100n cap between your programmer pin20 which usefully appears to connect to the green socket, to the reset pin on the arduino.

    Leave a comment:


  • Dannyx
    replied
    Re: 555 countdown timer design question

    It is a CH341A and here are some pics up close...damn I need a macro lens for my DSLR >_>
    Attached Files

    Leave a comment:


  • stj
    replied
    Re: 555 countdown timer design question

    no answers till i know what chip it uses - some dont have the extra signals

    Leave a comment:


  • Dannyx
    replied
    Re: 555 countdown timer design question

    Originally posted by stj
    on the serial adapter it goes to one of the handshake lines.
    your adapter is a bit lacking so you may need to solder to the chip pin.

    what's the exact part number of the chip on that adapter?
    I'll have a look...soldering won't be a problem, but can I continue to use it like normal like I have been so far even with that "cap hack" in place ? I don't want to "commit" the programmer solely for programming the arduino. I understand where you're going with this and I'm sure it'll eventually work, but I don't claim I 100% know what to do

    Leave a comment:


  • stj
    replied
    Re: 555 countdown timer design question

    on the serial adapter it goes to one of the handshake lines.
    your adapter is a bit lacking so you may need to solder to the chip pin.

    what's the exact part number of the chip on that adapter?
    Attached Files

    Leave a comment:

Related Topics

Collapse

  • DeanWy
    WD Sentinel DS5100 (NAS) boot issues
    by DeanWy
    Hi all,

    I have a Western Digital Sentinel DS5100 NAS system which has stopped working. It has dual BIOS. I bought the system second hand with an already broken primary BIOS (it rebooted multiple times until second BIOS was used).

    It worked until recently. The system was idle in Windows Server 2012 and a BSOD occurred, I think it was 'critical process died'. Thereafter it didn't boot, it just sat there with no video output and fan speed at 100% (there's a proprietary Windows driver by WD which controls the fan, outside of that it always runs at 100%).

    There...
    07-30-2024, 04:13 AM
  • beogeek
    820-2915-A Wont power on with battery connected
    by beogeek
    Ok so this doing my head in and hopefully someone more knowledgeable will be able to assist.

    I've got a MacBook Pro 820-2915-A it will power on without the battery connected, but when the battery is connected it will do a 2,3-second fan spin when pressing the power button and then nothing.

    After measuring and probing around I found that R7051 was bad, reading high instead of 2.2Ω so I replaced it. Still the same issue, I have the green light on the charger but it won't power on or charge the battery.

    So to cut the long story short I've replaced U7000,...
    02-26-2022, 01:29 AM
  • survivalbloke
    Acer Predator Helios 300 - will not power up if battery is CONNECTED
    by survivalbloke
    This was a no power initially. Thanks to your help, I discovered it was the first mosfet, so I replaced. Now, the device will power up only if the battery is NOT connected. As soon as I connect the battery, it shuts off. If I connected the battery while the device is off, it simply will not respond to the power button. I replaced the battery, and while I suppose the new battery could be faulty, I'm assuming it is not. I'm having the same behavior with the new battery. I measure .2v at the charging coil. Manually applying power to the + and - at the battery header, there is no charging happening....
    06-25-2025, 12:20 PM
  • muhuruu
    PS5 too many USB devices connected
    by muhuruu
    Hello. I have a problem with a PS5 console that I bought to learn electronics repair. The auction description indicated that the console had been dropped. The HDMI port and USB ports were damaged. The HDMI port was replaced by the previous owner, and after his repair, the console worked for 2 days and then became dead. After receiving the console, I replaced all the USB ports. After replacing them, the console started to turn on. On the logo screen, it displays "too many USB devices connected". My further attempts to fix the error involved replacing the Southbridge, 4 TPS2001D chips,...
    05-19-2025, 07:14 AM
  • versionlab
    Weird problem, laptop stays on when connected to another pc
    by versionlab
    Hi, I want to ask for advice about an interesting issue I've been having with a sony vaio laptop.

    Client came and said that "a desklamp touched the back of the lid while laptop was operating normally and it caused the office's circuit breaker to trip. Laptop had never turned on since".

    After taking the laptop apart (checked dc adapter everythin ok), I found a faulty MOSFET on the motherboard which I replaced. Laptop managed to turn on. However, while booting it shut down. Nothing else seemed faulty and thermals were ok. Shutting down was coming at random...
    10-26-2022, 03:43 AM
  • Loading...
  • No more items.
Working...