PIC controller resets when connected to 12V solenoid valve.

Thread Starter

pr123

Joined Mar 13, 2015
30
Hi,

I'm working on building a circuit using PIC16F877A to control switching of a 12V solenoid Valve.
The problem is when i run the program without the load the relay switches on/off continuously as desired but when the valve is connected , program runs one cycle without switching the valve and ends. Please help me out.

Im using ULN2803 to drive the relay. Diode is connected across relay. But this did not help.
 

Thread Starter

pr123

Joined Mar 13, 2015
30
Could you attach the circuit?
Hi,

This is the circuit i have built on a PCB . I have not shown diodes in the ckt and some values are different from that used in ckt, following are the actual values used:

1) Between Vss and Vdd i have 0.1UF then i also added 10uF .
2) R1 and R2 FOR MCLR ARE BOTH 10K ohm
3) I have a diode IN4007 across the relays.
 

Attachments

Thread Starter

pr123

Joined Mar 13, 2015
30
power supply is 12V 2 A, my relay takes about 90mA and solenoid around 750mA so its easily within 1 A
 

ScottWang

Joined Aug 23, 2012
7,409

jayanthd

Joined Jul 4, 2015
945
How are you driving Solenoid ? Using 4A darlington ? 4A Power Mosfet ? ULN2803 ?

If ULN2803 is used to drive the solenoid then it will not work as it can only sink 500 mA per channel and your solenoid draws more current.

You can however short 3 or 4 inputs of ULN and short 3 or 4 outputs of ULN and connect the input to PIC and outputs to solenoid and try.
 

ScottWang

Joined Aug 23, 2012
7,409
How are you driving Solenoid ? Using 4A darlington ? 4A Power Mosfet ? ULN2803 ?

If ULN2803 is used to drive the solenoid then it will not work as it can only sink 500 mA per channel and your solenoid draws more current.

You can however short 3 or 4 inputs of ULN and short 3 or 4 outputs of ULN and connect the input to PIC and outputs to solenoid and try.
Di you see the circuit, the uln2803 was used to drive relay, and used the contacts of relay to connect the salve.
 

Thread Starter

pr123

Joined Mar 13, 2015
30
Hi, i'm using PIC's pin no 18 i.e PORTC RC3 as output. This pin18 is connected to pin1 of ULN2803 the output pin 18 of uln drives a 12V 10A rated relay (which takes only 30mA i checked). This relay drives my solenoid valve.
The problem does not come when i drive only relay but as soon as i connect the load to it, PIC's pin 18 shows 0 does not give any output and hence valve doesnt switch on.
 

RolandP

Joined Sep 5, 2015
3
It could be one of the PIC's resets (Brown-out reset specifically). My guess is that the solenoid valve draws too much power and affects the power supply. What are your config bits?
 

jayanthd

Joined Jul 4, 2015
945
What is the load you are switching using solenoid ? Why don't you post your code and mention the compiler and other things asked.

Do you have a while(1) loop in your code and do the main processing in it. Please post the code and also the config settings.
 
Last edited:

Thread Starter

pr123

Joined Mar 13, 2015
30
the resistor values mentioned in schematic are different , i have used two 10K ohm resistors and a 0.1uF capacitor at MCLR pin of PIC
a diode across the relay which is driven by ULN2803.

I am driving solenoid through a relay. for driving this relay im using uln2803.
 

jayanthd

Joined Jul 4, 2015
945
You still didn't attach the Proteus file. You have to use WinZip and zip the file and attach it here. Other zip formats are not allowed.

I see there are no debounce delays for the buttons and that might be one problem. I see that you have a lot of similar piece of code for each button press except the delays are different. I could not understand what you are trying to do ? You turn ON and OFF the Relay (RC3 pin) sometimes two to three times a second. Maybe this is also a problem.

In each button press code you have a while(s1 == 1) loop and it executes until RB0/INT0 detects a low to high. When low to high is detected s1 is cleared in ISR and the while(s1 == 1) loops break.

Will you explain what you are trying to do by turning ON / OFF the relay / solenoid twice or thrice a second ?

You are using mikroC PRO PIC Compiler and PIC16F. Do you know that memory bank switching code is not generated by mikroC PRO PIC Compiler for PIC16F devices and if you have a lot of strings in the code then you will get a warning that IRP_bit must be set manually to access xyz variable in the Compilers message window.

I asked you to zip and post the complete mikroC PRO PIC project files because I also have to see the config settings set in the IDE.

Are you using free version of Compiler or licensed version ? If you are not using licensed version then it might be generating wrong .hex file.

In ISR you set TRISD = 1; why ? Switches are connected to PORTD. why you make some pins output ? Once ISR is executed the only switch connected to RD0 is detected as you set TRISD = 1 in ISR. So, if you press other buttons connect to PORTD after the ISR is executed once then it will not be detected.


Before while(1) loop TRISD is set to 1. How do you detect button press connected to other RDx pins ?

You set TRISB = 1 and use INT0 pin to detect low to high but you don't set INTE_bit. How will the low to high edge detected ?
 
Last edited:

Thread Starter

pr123

Joined Mar 13, 2015
30
when i try to upload i see only hex files not my mikroc file nor the proteus that is why i sent text file of my code
 
Top