Thanks Mel. I Love your work.
J
I think the best you can do is to switch your relay with a transistor and keep your PIC safe.
You would need only a cheap one + 1 resistor.
Patrick
Loop:
TRISB.0=1
TRISB.7=1
Pause 1000
HIGH RelayPinA
HIGH RelayPinB
Pause 1000
Goto Loop
The only down side to this is if you use the Port B weak pull up option. There will be a small current going through the relay constantly. Mel, would ORing the two pins at once protect from one shorting the other out for an instant, or are the diodes absolutely necessary?
1. Personally I'd use a Transistor.. even one of those tiny SMD Digital Transistors with integral Base Resistors... takes next to zero board space and only one component...
2. Second choice I'd put in series Diodes on each PIC pin leg. The Relay will still pull in.
3. Pick a Relay with a higher coil Resistance and drive from one PIC pin. If I really must drive a Relay, then (obviously your application will dictate what you use), I tend to use Reed-Relays (500R coil) directly on PICs... some even have integral back-emf Diodes built-in. Anything bigger than that - see option 1. I don't like driving Relays (or any inductive loads) off the same power-rail as the PIC's supply anyway.
4. Only if absolutely nescessary just parallel the PIC pins. I don't like this option... not at all. During Power-up, the PIC can come up with I/O's in a random state... Sods Law (like Ohms Law but different) states that your pins will come up in the most unfortunate combination to ruin your day. But who am I not to help along disaster...
Hi Mel,
You are right in that I should have chosen a relay with a higher coil resistance... and for sure that is what I will do next time.
What is the default start up state of the TRIS registers? Wouldn't they have been designed to go High-Imedance for safety's sake and not pseudo random?
Surely the lab coats at Microchip thought this one through?!!
The default Startup State of the Registers is in the back of the Datasheet. Yes, TRIS in theory comes up as Inputs, BUT trust nothing and nobody in this business and always design for worst-case. That way you won't crash and burn.
Bookmarks