Connect with us

Another microcontroller problem

Discussion in 'Electronic Design' started by PT, Oct 15, 2003.

Scroll to continue with content
  1. PT

    PT Guest

    Hi,
    I am using a PICAXE-08 micocontroller for a timer. Power supply voltage is
    12VAC, 60VA capacity (switching transformer), then rectified then regulated.
    Regulator circuit consists of a 5V LM340 with a 1000 mf and a 0.01mf cap on
    both incoming and outgoing side. A change from +5V to 0V on input pin of PIC
    causes timer to start. Output pin of PIC drives via a 10K resistor an NPN
    transistor which in turn energises a 12V DC relay. Relay has diode across
    coil for EMF suppression. Supply to PIC is regulated 5V. Supply to relay is
    from the rectified side of the bridge rectifier. Load is a 20W lamp running
    off the 12VAC supply.

    Sorry I can't do the shorthand style drawing and the *.bmp drawing was about
    1MB. which I wouldn't put here and putting it on a site would still be a
    bother. But the circuit is simple stuff.

    My problem.
    When the PIC times out (over 1 hour) the relay deenergises and should stay
    that way however for some reason it reenergises within 1 second and then
    continues for another hour (if I let it). This is caused by false triggering
    of the input.

    The input pin is grounded by a 10K resistor and a leg off to a reed switch
    contact which then connects to the 5V rail. The software instructs the PIC
    to wait until the reed switch closes (maybe hours later) then opens again to
    cause the timer sequence to begin. However it doesn't and starts right away.

    One solution that works well was to put a 0.01MF cap across the input pin to
    +5V rail, ie. parallel with the reed switch which would be still open.

    The question:
    Why did the cap make the difference? and what is happening?

    Thanks for any replies,
    Paul.
     
  2. Ben Pope

    Ben Pope Guest


    debounce of the reed switch?

    Ben
     
  3. You're getting contact bounce on your mechanical switch.
    The cap is absorbing (filtering) the bounce, and, in my opinion
    you are getting lucky that it's working for you. It may work 99.9%
    of the time but will fail as soon as your demonstrating to your manager
    or a customer :) It may also fail more frequently with time as your
    switch wears and the bounce oscillation frequency changes. I strongly
    suggest you put a proper de-bounce curcuit in place between the relay
    and uC input.



    --
    sincerely,

    Russell Powell

    Artisan Components
    SR. FAE - U.S. Central

    469-438-6589
     
  4. Byron A Jeff

    Byron A Jeff Guest

    -Hi,
    -I am using a PICAXE-08 micocontroller for a timer. Power supply voltage is
    -12VAC, 60VA capacity (switching transformer), then rectified then regulated.
    -Regulator circuit consists of a 5V LM340 with a 1000 mf and a 0.01mf cap on
    -both incoming and outgoing side. A change from +5V to 0V on input pin of PIC
    -causes timer to start. Output pin of PIC drives via a 10K resistor an NPN
    -transistor which in turn energises a 12V DC relay. Relay has diode across
    -coil for EMF suppression. Supply to PIC is regulated 5V. Supply to relay is
    -from the rectified side of the bridge rectifier. Load is a 20W lamp running
    -off the 12VAC supply.

    What a clear description! Cool!

    And they don't cost too much either. $4 is only a bit more than double the
    cost of the raw chip.

    BTW on your relay suppression Tyco has a great app note on the subject:

    http://relays.tycoelectronics.com/app_pdfs/13c3264.pdf

    Which says that for best performance, a regular diode should be coupled back
    to back with a zener. Protects the electronics without major impact on the
    relay armature release characteristics.

    -
    -Sorry I can't do the shorthand style drawing and the *.bmp drawing was about
    -1MB. which I wouldn't put here and putting it on a site would still be a
    -bother. But the circuit is simple stuff.
    -
    -My problem.
    -When the PIC times out (over 1 hour) the relay deenergises and should stay
    -that way however for some reason it reenergises within 1 second and then
    -continues for another hour (if I let it). This is caused by false triggering
    -of the input.

    Probably the release of the relay armature is generating enough noise to
    cause it to retrigger. Do you have any debounce hardware/software on your
    trigger input? Also is there any need for an instant retrigger directly after
    the relay deenergizes.

    -
    -The input pin is grounded by a 10K resistor and a leg off to a reed switch
    -contact which then connects to the 5V rail. The software instructs the PIC
    -to wait until the reed switch closes (maybe hours later) then opens again to
    -cause the timer sequence to begin. However it doesn't and starts right away.
    -
    -One solution that works well was to put a 0.01MF cap across the input pin to
    -+5V rail, ie. parallel with the reed switch which would be still open.

    That would help with the hardware debounce. I usually do it in software unless
    I know that the 1st trigger is going to cause a long term event, like this
    example.

    But in this case. especially with a reed trigger input, I'd probably look into
    a software debounce routine for triggering.

    -
    -The question:
    -Why did the cap make the difference?

    Possibly. It depends on how long the transient that triggers is.

    -and what is happening?

    Some transient of the power relay is causing a retrigger.

    Here's how you can test: simply put a dead period after deenergizing the
    power relay. Say 3 seconds
    for the same of argument. So the debounce would be:

    1) wait for input to go high.
    2) Trigger the relay and delay
    3) Deenergize the relay
    4) Wait 3 seconds.

    This delay routine will force the system to settle. Now you can test (I'd
    advise setting the relay energize period to 10 seconds or so while testing).
    Now when the power relay deenergizes, even if it triggers the input, the
    delay will cause those fluctuations to be ignored. So it should remain
    deenergized.

    Now there is a second possibility: deenergizing the relay causes the PICAXE
    to reset. This is the problem that I have with my homemade thermostat when
    the AC/FAN power relays kick out. If this is the case it'll fail because the
    dead period after deenergizing doesn't run because the PICAXE resets. Then
    fluctuations on the trigger after the reset will cause it to reenergize.

    The hardware solution to that is to kill the transients with decoupling caps
    on both the power supply and the trigger input, as you specified above.

    The software solution is to let the PICAXE reset, and have a 3 second delay
    before checking the trigger after a reset. That way even if it resets then
    none of the transients will trigger the input.

    I have a similar circuit to yours in my basement to turn on the basement
    lights when the basement door opens. I do have a slight debounce delay.
    It never retriggers.

    Just some thoughts.

    BAJ
     
  5. Byron A Jeff

    Byron A Jeff Guest

    I'm not sure that's the fact here. Even if the reed were bouncing, it wouldn't
    matter under normal circumstances because the event is for an hour, which
    is well past the bounce time of the reed.

    The question is why is deenergizing the power relay causing a trigger?
    Again I doubt that it's a mechanical trigger that's causing the problem.
    Bounce is important when the event interval is short. The event interval
    here is an hour.

    Question: If you power up and let the system sit, does it trigger by itself?

    Or simply do it in software. Trivial:

    1) Wait for event.
    2) Delay awhile.
    3) Make sure that event is still active. Otherwise go to 1.

    No need for hardware at all. The only question is the reaction delay between
    the trigger first activated and the causation of the action.

    Now that I rethink it I'd probably do two small things:

    1) Go ahead and throw a small cap on the trigger input. It'll get rid of
    noise transients while not impacting greatly the trigger time.

    2) Add a dead period delay of a few seconds after the power relay deactivates.

    Both together should solve the problem.

    BAJ
     
  6. PT

    PT Guest

    Thanks, I would like to say as well the reed switch is on a door to a space,
    if the door is left open for over 1 hour the light in the space will turn
    off. It will only turn on again when the door is closed and opened again.
    The reed switch bounce is being taken care of by placing a 100ms delay in
    the program. As the door is still open there is no reed switch bounce
    causing this problem. My suspicion is related to the discharge from the
    relay coil, but not sure how.

    Paul.
     
  7. Michael

    Michael Guest

    I agree it's either resetting or re-triggering due to noise,

    It's not a good idea to run long wires from your +5V rail and and a
    port line without any sort of protection. Put a slow RC time constant
    on your port line, I would put a 100nF from port to ground, a 100k
    pullup from port to +5, a 1k from the port to the reed switch, other
    end of reed switch to ground.

    The spark on the relay contacts may be causing the reset.
    Sometimes if I have trouble keeping a device from resetting, I write
    a certain number combination to ram before I do whatever causes the
    noise (in this case a relay transition), then I wait 100mS or so after
    the event, then clear the number combination. Then on reset I can
    check the ram location to see if the reset was caused by the event,
    and if it was I jump back into my 100mS delay loop without
    re-initialising anything.

    I could use one of these on my toilet fan, takes at least an hour to
    clear the fumes in my houshold.
     
  8. PT

    PT Guest

    Hi Byron,
    Thanks for the thoughts and I checked out the app note. I played around
    again with this circuit, pulled out the 0.01mf cap across the input pin and
    tried your suggestion - but to no avail. I must say that it did keep the
    relay from energising but only until the delay timed out then wham.
    However, you mentioned the word "transients" and it started playing in my
    mind. So, I swapped the switching transformer for an old fashion wire wound
    and presto - problem no more and still with the cap off. Can't use this
    transformer though - high standby power drain, when compared to a switching
    transformer. Interesting, that these transients are getting through because
    I am using MKT caps on the regulator.
    Maybe if someone is still reading this thread and knows the best way to
    quieten down those nasty transients.

    PICAXE chips have actually been designed as an educational tool and that's
    why they have kept them at an astonishingly low price. Also easy to program,
    easy to connect - 3 wires using serial com port and compiler is built in.

    Paul.
     
  9. I read in sci.electronics.design that Michael <>
    It's rotating the wrong way.

    Or maybe you have a Northern Hemisphere model. (;-)
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-