View previous topic :: View next topic |
Author |
Message |
Praful
Joined: 18 Jun 2012 Posts: 23
|
MCU reset on spike |
Posted: Sun May 05, 2013 2:57 am |
|
|
Dear All Masters,
This is my first time to post a code. Please help me for solving my problem of Resetting of MCU when it handles 230v with help of relay.
I used even optical isolator MCT2E to operate a 12v relay and then 12v relay operates 230v relay to on/off load.
My compiler ver. 4.108
my code shown below
Code: |
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#use delay(clock=8000000)
int sec,min;
#define LED PIN_C0
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PsP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
output_low(LED);
while(true)
{
Delay_ms(1000);
sec++;
if(sec>=59){min++;sec=0;}
if(min>=30){min=0;output_toggle(LED);}
}
} |
|
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sun May 05, 2013 5:21 am |
|
|
ur code seeing like timer code ! _________________ sahu |
|
|
Praful
Joined: 18 Jun 2012 Posts: 23
|
|
Posted: Sun May 05, 2013 5:54 am |
|
|
Yes, its just a testing code to on and off the load after 30minutes. BUT it dosen't happened. Because MCU resets every relay operation many times I changed the PCB layout also. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sun May 05, 2013 11:12 am |
|
|
Wrong part of the forum... _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Praful
Joined: 18 Jun 2012 Posts: 23
|
|
Posted: Sun May 05, 2013 12:02 pm |
|
|
What is wrong with this part of fourum........ |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Sun May 05, 2013 12:45 pm |
|
|
The CODE section on the forum is to post working code which you wish to share with other users.
++++++++++++++++++
Moved to General Discussion forum.
- Forum Moderator
++++++++++++++++++ |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Sun May 05, 2013 1:56 pm |
|
|
First a minor error
setup_spi(SPI_SS_DISABLED);
Should be setup_spi(FALSE);
You are turning the SPI on, and telling it not ro use slave select...
Then on the relay.
How is the coil trapped/snubbed?.
When you switch _off_ a circuit that is driving an inductor, the magnetic energy in the coil has to go 'somewhere'. The normal behaviour is for the voltage across the coil to rise until it finds somewhere to go. This is how the little circuits in flashguns develop 500v, from typically a 3v battery. This voltage is fed into the capacitor to charge it.
If you have a coil without some form of circuitry to trap this energy, the result _will_ be a massive spike, that will find it's way into the driving circuitry....
You must have a circuit to trap this. Reverse diode, or a diode feeding into a rail with a discharge resistor. Something.
Other thing is that when you switch a relay, there can always be a tendency for the contacts to arc. Result a really nasty radio spike, than can also cause problems. This also kills the relay eventually. Answer to this is to snub the contacts. Resistor in series with a small bidirectional capacitor across the relay contacts. You can also buy proprietary 'snubbers'. Remember the voltage ratings needed for all parts here, and the failure modes of resistors/capacitors (this is the 'point' about 'Class Y' capacitors....).
Best Wishes |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon May 06, 2013 5:33 am |
|
|
It sounds like this would be better handled on a hardware forum like this one: http://www.edaboard.com/forum.php#hardware-pcb-design
If you replace the optoisolator with a visible LED you can verify that all the software works. If the software works the problem is beyond the scope of this forum which concerns the CCS compiler and some general C questions.
However here are a couple of points for hardware troubleshooting:
1) If the visible LED mentioned above works but adding the relay coil with no voltage on the relay contacts creates the problem, then you need to look at the 12V wiring and your coil snubber circuit as Ttelmah mentions.
2) If the problem begins when you apply 230V to the relay contacts, then you need to look at the 230V wiring and any inductive or capacitive coupling from the 230V wiring to the low voltage wiring. If the relay drives another coil like a solenoid or a motor you may need a snubber on that coil as well.
3) When your PIC resets have it send out the result of restart_cause() which will tell you why the PIC reset. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|