EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: ctesla75 on July 09, 2015, 12:04:07 pm

Title: relay indicator partially lit
Post by: ctesla75 on July 09, 2015, 12:04:07 pm
Hi All ,
         i recently posted a question about a relay circuit operated by a pic18f24k22 latching on (but would not latch if a diode was connected to base of transistor)..The general consensus was that the program was at fault i was going to reprogram in C and try again but was pressed for time (and had to learn C first)and decided to build as is with diode, and reprogram later and remove diodes. the circuit works ok but the led that indicates if the relay is on is always dimly lit on all four leds , it will fully illuminate when that relay is triggered. i tried a 1 to 10k to ground from transistor base but it only makes a slight difference . Can the veroboard itself act like an antena and put a voltage across the transistor it makes no difference if the pic is erased so im guessing its a  hardware  issue.

thanks ctesla75
p.s. thanks to all who replied to last post it gave me a lot to look up and learn and still looking up
Title: Re: relay indicator partially lit
Post by: MarkF on July 09, 2015, 12:48:11 pm
I was following your other post because I was interested in the latching problem with the outputs.

I would be interested what happens if you disconnect one of your relay circuits from the PIC and connect it directly to +5V to see if it's a current limit of the PIC.  With your other 5 LEDs, they may have some effect on the PIC.  Just guessing here.

In the long run, I would get rid of your whole relay driver and use a ULN2003A or a ULN2803A.  The outputs are open collector and will drive the relay directly.  You use these for all your LEDs and isolate the PIC.  It wouldn't really identify the problem.  Just cover it up.
Title: Re: relay indicator partially lit
Post by: Andy Watson on July 09, 2015, 01:17:46 pm
the circuit works ok but the led that indicates if the relay is on is always dimly lit on all four leds ,
Considering this odd behaviour, and the behaviour exhibited in your previous thread, I have to ask: Are you sure that Q1-4 are what you think they are and are you sure that you have the correct pin-out for them? Could you have interchanged the emitter and collector?
Title: Re: relay indicator partially lit
Post by: ctesla75 on July 09, 2015, 01:22:59 pm
hi mark.
              I have just tried removing the pic as it was socketed, after powering up the led's are completely off.and operate ok whem 5v applied to diode ,however i noticed that the leds flicker lightlty when my finger touches the diodes .i should mention only the leds connected across relay flicker the ones going directly to the i/o dont flicker. The transistors are old stock but are just bc547 marked as c547 and i checked the datasheet after the failure as i suspected wiring it in backwards but it was ok.
Title: Re: relay indicator partially lit
Post by: ctesla75 on July 09, 2015, 01:38:21 pm
i have just measured the voltage at the micro because the pikit standalone programmer reported 7.8v and that is what i am now getting the 7805 is also hot .i may have accidently shorted something while trying to trigger transistor as it was previously 5v.
Title: Re: relay indicator partially lit
Post by: Andy Watson on July 09, 2015, 01:41:41 pm
i have just measured the voltage at the micro because the pikit standalone programmer reported 7.8v and that is what i am now getting the 7805 is also hot .i may have accidently shorted something while trying to trigger transistor as it was previously 5v.
Is there really no smoothing capacitor between the bridge rectifier and the regulator ?
Title: Re: relay indicator partially lit
Post by: ctesla75 on July 09, 2015, 01:55:56 pm
no i didnt use a capacitor before the regulator still a lot to learn i guess  i  thought one after the regulator was all that is needed what is the rule on cap size,i thought it was 1000uf per amp is this correct
Title: Re: relay indicator partially lit
Post by: Andy Watson on July 09, 2015, 02:20:30 pm
Difficult to say without more details. You need to know how much (ripple) voltage you can afford to lose each half-cycle (t) and what current (i) is required. As a first approximation C = i * t / Vripple. This will give you a base line for the minimum value - aim for bigger. There's some more detail here:
http://www.electronics-tutorials.ws/diode/diode_6.html (http://www.electronics-tutorials.ws/diode/diode_6.html)

7.8V on the other side of the regulator ? I think you will find several things are now broken. :( When you get it fixed-up it would be a good idea to add a small capacitor (around 1uF) either side of, and close to the regulator.

Title: Re: relay indicator partially lit
Post by: ctesla75 on July 09, 2015, 02:25:40 pm
yes i think the micro might also be gone will pull it apart and add capsx replace regulator and transistors just to be on the safe side
Title: Re: relay indicator partially lit
Post by: MarkF on July 09, 2015, 04:52:01 pm
no i didnt use a capacitor before the regulator still a lot to learn i guess  i  thought one after the regulator was all that is needed what is the rule on cap size,i thought it was 1000uf per amp is this correct

I totally missed that.  If that's a 12 Vrms transformer, you will have a 17 Vpeak ripple going into the regulator without the smoothing capacitor and it will drop out at 60 Hz.  The rectified waveform drops to zero volts without the capacitor.  This may be causing the PIC to continually reset.  The smoothing capacitor before the regulator is the most important one.  It must keep the ripple at least 2V above the regulator output voltage to keep it from dropping out of regulation.  Look up the minimum dropout voltage in the spec for the regulator.
Title: Re: relay indicator partially lit
Post by: picandmix on July 09, 2015, 08:23:38 pm
Sounds like you are in the classic evil circle where you have no idea where the faults are and parts just keep falling apart, like your regulator running hot.

Surely its time you took a more basic approach and properly  tested things out one by one ?

First, as said, you need to replace the 5v regulator as it could well be paritially damaged and fit a something between 470uf to 2200uf across is inputs.
Place a 100nf across the regulators input to 0v and its output as well, fitted as close to the regulator pins as possible.

Also place 100nf close across the Pics pos and neg pins. 
How long are the wires from the regulator to the Pic ? if more than a few inches /10cm then the two wires should be tightly twisted together.

Assuming you have a volt meter, then check what voltages you are getting, it should be a good 5.0 v and the 12v might show up to 16v dc if no other load is attatched.

Rather than using a micro to drive your relays, have you tested just the relay section  on its own, like the jpg you showed in you earlier post.

If you connect your relay to the 12v and then connect the 1k base resistor to +5v and 0v  it should all turn on  and off crisply  - does it ?

Also exactly what relays are you using, the model number would help us confirm its suitable; and what is the size / type of your mains transformer, eg output voltage and current rating ?

If all that test ok then leaving the relays and led disconnected you want to program up you micro so it just turns a port on and off every 5 seconds, allowing you to test it works correctly with your volt meter.

If you cannot get the Pic  to work and supspect its your program code then I could test and send over some proven  .hex code from my 25k22 which is the same family as your 24k22.

If is does  work ok, then you can start connecting your leds and relays one by one and testing it works correctly.

That chip is well able to drive 4 small leds ( under 20ma each) and drive the 4 transistors for the relay.



Two questions, your original post stated the Pi18f23K20, now its the 18F24K22, is that correct ?
also the chips you have are they marked  18F2  or 18LF2  ?


Edit   - attatched are two .hex files to flash all pins on  PortA and Port B every 1.5seconds.
They work fine on my hardware.
Title: Re: relay indicator partially lit
Post by: ctesla75 on July 10, 2015, 11:51:25 am
it looks like the smoothing capacitor is what was causing the leds to flicker ,i replaced regulators and all transistors ,added a 1000uf cap on input and all other caps as suggested by picandmix and flickering stopped., i was testing things out slowly for example i build up to regulator stage test voltages then put in ic socket wire it up test socket voltages and before inserting pic i manually trigger relay,i did not at first notice leds flickering due to bright sunlight and fluorescent lighting, my lack of knowledge was my greatest problem.the relay turns off and on properly even bypassing diodes without the pic but latches if the diode is jumpered out of the circuit with the pic,although the pic is now damaged and maybe it was damaged to begin with because of the capacitor or maybe it was resetting i will get a new chip and try again.i changed from the 18f24k22 to 18f25k22 just to see if the original was faulty and thats what i had in stock.the transformer is powertran m7252a 10va 6v 0 6v  used as 12v. and the relay is a 12v i have attached the data. thanks for the suggestions hopefully new chip wont latch
Title: Re: relay indicator partially lit
Post by: picandmix on July 10, 2015, 01:50:01 pm
Am assuming you have just done those tests with your program code - yes ?

As a final test to prove if your chips are defective, why not try programming up that K22 PORT B .hex code, that should just turn your relays and leds on and off every 1.5 seconds

You did not mention if your chips are the F or LF type  ; just that your original post refered to them as "3v3 chips"  but you now show a 5v regulator ?  The F type runs up to 5V ok, but the LF only runs up to 3v6, so a 5v regulator would blow it.

I have my dev board here, if you want to post your 24K22 .hex file I could test out your code and see if it operates the my 12v realys ok ..
Title: Re: relay indicator partially lit
Post by: picandmix on July 10, 2015, 02:21:32 pm
Have just wired up your exact relay and led circuit and it works fine with that code I sent from either port A or port B.

Would be interesting to try your .hex code; at least it would let you know where your problems are...
Title: Re: relay indicator partially lit
Post by: ctesla75 on July 11, 2015, 03:13:55 am
thanks for the offer to try my code i am using 18f chips not 18Lf i mistakenLy thought the 18f was 3.3v only so thats why i originally used a 3.3v regulator, i am fairly sure the chip is at least partially blown because one whole port doesn't work anymore and it worked at least poorly before but now not at all .i can manually use the ports without the micro and its ok (e.g. trigger relay).I Have attached the code ,one part of the schematic is incorrect the led going ra4 shoujld be going to ra5 ,but its not important as that part works ok
Title: Re: relay indicator partially lit
Post by: picandmix on July 11, 2015, 08:42:07 am
Ok, will try you code out in a little while, but looking at the jpeg of your Config statements there seem to be some potential problems.

1.  You are using the internal oscillator, don't know that frequency you have set it to ?  ,but it will be running 4 times faster because you have got the PPL option enabled, this means any program code timings will also be 4 times faster, so set it to Off.

2. The MLCR bit  is set ON which means to run properly you need to pull that pin up with an external 10k resistor or control it via your programmer  -  so set it to OFF
Without out this you chip runs very hit and miss.

3. The Watchdog Timer is set on, unless you are deliberately using this function set it to OFF,  otherwise it repeatedly resets your program back to the beginning every second or so.
With this enabled your program will probably not run at all or very strangely.

4. PORTB A/D enable wants to be off , so it used digital

I may be able to correct the config lines on my system to then test your code.


Might seem like you are having a lot of problems and errors, don't worry, we have all been there !  :)
Title: Re: relay indicator partially lit
Post by: picandmix on July 11, 2015, 10:35:43 am
Don't know the logic of your program, partic what the Select switch does; however it does seem to run and do some things when used with my Config data.

When powered on, all relay outputs are off, but leds 2 and 3 are on.

When switch4 (Rc3) is taken high, relay 4  output flashes on /off about every second.

When switch2 (rc1) is high  , relay 2 flashes about every 1/2 second.

Seems like its running in a reasonably stable state, so think you problems may be those Config settings.

eg if you have the PLL on, so things are running 4 times faster , then relay 2 with be 'flashed' every 1/8 th of a second which is too fast for a relay to operate correctly.

However doubt it would get that far if the Watchdog is on and uncontrolled by your code


edit  - do not know if you have tried those two .hex files of mine, but they have the Config code in there already, so if you program it with your Pickit programmer (?)  ( pk1 , 2 or 3 ?) using its stand alone program v2.61 etc then it will automatically load them.

Title: Re: relay indicator partially lit
Post by: ctesla75 on July 12, 2015, 12:33:37 am
hi picandmix
the selct switch rb5, is a momentary pushbutton and selects a different led on the ra port each time it is pressed .all rc* switches are momentary also switching relay or off.when I attached the hex files i used my 25k22 and just changed the chip and recompiled,so it resetted some of my config setings, i had mclr set off and watchdog disabled, however pll was enabled and i had tried port a/d in both enabled and disabled, but this is while i had no input filter capacitor.Unfortunately the local electronics store doesn't stock the chip i need so i will order some replacements from element14 and hopefully have them in a day or two,then i can try your code and also retry mine with the hardware and software changes , thanks for the help so far its invaluable to someone trying to learn