Do I need a PAUSE in here?

wapo54001

Senior Member
I want to use a 14M2 at default clock to control input and output switching of an audio preamp using latching relays.

Each relay (250R coil) needs 3.75V @ 20ma for 3ms to switch state, and I use a 120uF capacitor between the relay and ground to absorb and then release the voltage from pins switching between high and low to set the relays as needed.

Each 14M2 pin delivers 25ma and, for belt and suspenders security, I am using two pins of the chip to drive each latching relay. In order to avoid connecting an input to an output, I will always first make both pins an input, then make both pins either high or low depending upon how I want the relay to switch.

My question is, do I need to insert a pause between switching both pins to inputs and then switching both to outputs either high or low or can I assume the “input” commands will have completed before the “output” commands execute? When switching to "input" the relays don't move so relay timing is not an issue, only Picaxe timing. If I need a pause, then how long must the pause be? I have no clue.

During normal operation this is not going to be an issue. However, I want virtually instantaneous switching of relays when power is removed either intentionally or accidentally to avoid serious consequences at the power amp and speakers. I will have significant power stored in capacitors for the 14M2 but I want the switching job done ASAP in this circumstance.
 

AllyCat

Senior Member
Hi,

The actual PIC(axe) output pins will switch in a small fraction of a microsecond. However, the 14M2's base PIC has a different Port.pin mapping to the PICaxe (with Ports A, B and C being mapped to B and C) so there might be a "stagger" of a few microseconds between certain pins, when using the PINSx = command. But those delays are trivial compared with the Basic Interpreter delay which may approach 1 ms per instruction (still quite a short time), so I don't see any need to introduce any PAUSEs or even PAUSEUSs to your program.

When I first read your description, I missed the part about "Latching Relays", so wrote the following text. However, it shouldn't apply in your case, but having written it, it might be of information for somebody else driving "conventional" (single coil) relays:

I want virtually instantaneous switching of relays when power is removed either intentionally or accidentally to avoid serious consequences at the power amp and speakers. I will have significant power stored in capacitors for the 14M2 but I want the switching job done ASAP in this circumstance.
Remember that Relay Coils have significant Inductance so you should have a "commutation" diode across each coil. But even if you don't, the PIC's internal "Electrostatic Protection" Diodes (between every Output pin and Vdd and Ground) should perform the same function. The characteristic of inductance is that it resists the (instantaneous) change in any current flow, by generating a voltage which "fights" the change (in a similar way to a capacitor delivering a current to fight any voltage change). That may slightly slow the activation of the relay, but the main issue is when a relay is released. When the driver transistor switches off, the inductance attempts to generate a high voltage to maintain the current flow, hence the need for the commutation diode (to avoid destroying the transistor). The problem is that the diode allows the relay current to continue flowing, which extends the release time (maybe considerably). A traditional way of creating a "slow release" relay is to short-circuit the coil. :(

One solution with an external transistor is to connect an R-C or R-Diode network across the relay coil to allow the voltage to rise nearer to whatever the transistor can tolerate (thus reducing the di/dt fall time), but that's not possible (i.e. safe) with a logic IC output pin. Another solution might be to activate the relay to achieve protection, but probably the most suitable method is to provide each relay coil with its own R-C decoupling. Then, at power-up, each capacitor charges via its (significant) resistance, but the relay is not activated (by the PICaxe) until the capacitor is expected to be fully charged. The capacitor stores enough charge for the relay to operate quickly, but then the voltage falls to a level only sufficient to maintain the "holding" current. Thus the relay should release more quickly when the drive (current) is removed.


Cheers, Alan.
 

wapo54001

Senior Member
Hi,

The actual PIC(axe) output pins will switch in a small fraction of a microsecond. However, the 14M2's base PIC has a different Port.pin mapping to the PICaxe (with Ports A, B and C being mapped to B and C) so there might be a "stagger" of a few microseconds between certain pins, when using the PINSx = command. But those delays are trivial compared with the Basic Interpreter delay which may approach 1 ms per instruction (still quite a short time), so I don't see any need to introduce any PAUSEs or even PAUSEUSs to your program.

Cheers, Alan.
Alan, as always you offer really precise information and good advice. Once again, thank you!
 

inglewoodpete

Senior Member
Remember that Relay Coils have significant Inductance so you should have a "commutation" diode across each coil. But even if you don't, the PIC's internal "Electrostatic Protection" Diodes (between every Output pin and Vdd and Ground) should perform the same function.
Dumping back-emf from an inductor's collapsing magnetic field into a microcontroller pin's ESD diode is asking for trouble. The diode is built into the silicon of the microcontroller and the "dumped" energy goes straight to the chip's internal power rail. From my experience, this will cause sporadic (and pretty regular!) rebooting of the microcontroller. For reliable operation, you need to calm this spike at its source: the relay (inductor).

FYI, the PIC16F1825/14M2's clamp (internal protection) diodes are specified as Imax=20mA, which is a lot of energy for the chip's internal circuitry to swallow.
 

AllyCat

Senior Member
Hi,

Yes, I was really trying to indicate that the release time of the Relay could not be reduced by simply removing the (external) commutation diode. Also, in the context of the OP's second paragraph, which indicated a 3 ms, 20 mA pulse through 250 ohms into 120 uF (i.e. a 30 ms time constant), the internal diode is arguably "safe" (or at least within specification), but I would NOT recommend it (particularly in an "Educational" environment).

The 20 mA "Absolute Limit" current rating of those diodes is often discussed (and/or confused with the PIC's output FET rating of 25 mA for M2 chips), but it's largely meaningless, because no "time" parameter is quoted (so can we assume it's a "continuous" rating?). For example the Human Body Model indicates that 2kV (or maybe more) may be discharged through 1500 ohms from 100 pF into the pin. That's a transient of more than 1 Amp, but fortunately only for a fraction of a microsecond.

Furthermore, if we assume that a "traditional" 100 nF capacitor is connected across the PICaxe's Supply-Ground pins, then the 2 kV pulse could boost the supply rail by about 2 volts, and the higher electrostatic voltages might exceed the "normal" maximum ratings. But what happens when the PIC(axe) is first removed from its packaging: There is no supply decoupling capacitor, so how high (a voltage) might the supply rail go? I don't know the answer, but guess that there must be some form of "Zener Diode" across the rails inside the package? I was fascinated that the Reverse Base-Emitter Breakdown of BiPolar Transistors and ICs acts as quite a decent Zener Diode, normally in the range 6 - 9 volts, with an excellent "knee" down to the microAmp level.

Cheers, Alan.
 
Top