PIC controller resets when connected to 12V solenoid valve.

Discussion in 'Embedded Systems and Microcontrollers' started by pr123, Sep 9, 2015.

  1. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    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.
     
  2. ScottWang

    Moderator

    Aug 23, 2012
    4,856
    767
    Could you attach the circuit?
     
  3. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    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.
     
  4. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,652
    767
    What about the power supply? Maybe it cannot cope with the required power when you switch the load on.
     
  5. pr123

    Thread Starter Member

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

    Moderator

    Aug 23, 2012
    4,856
    767
  7. jayanthd

    Member

    Jul 4, 2015
    274
    29
    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.
     
  8. ScottWang

    Moderator

    Aug 23, 2012
    4,856
    767
    Di you see the circuit, the uln2803 was used to drive relay, and used the contacts of relay to connect the salve.
     
  9. jayanthd

    Member

    Jul 4, 2015
    274
    29
    Ok. Maybe I missed it.

    @pr123

    Please zip and post the complete project files (code + proteus). mention Compiler used and what crystal frequency you are using.
     
  10. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    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.
     
  11. RolandP

    New Member

    Sep 5, 2015
    2
    0
    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?
     
  12. jayanthd

    Member

    Jul 4, 2015
    274
    29
    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: Sep 9, 2015
  13. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    This is my code..
     
  14. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    This is the schematic
     
  15. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    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.
     
  16. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    yes i have a while(1) loop!
     
  17. jayanthd

    Member

    Jul 4, 2015
    274
    29
    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: Sep 9, 2015
  18. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    i dont know anything about Brown Out Reset ..Im new to programming
     
  19. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    Im not able to upload the mikroc file
     
  20. pr123

    Thread Starter Member

    Mar 13, 2015
    30
    0
    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
     
Loading...