CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

MCU reset on spike

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Praful



Joined: 18 Jun 2012
Posts: 23

View user's profile Send private message

MCU reset on spike
PostPosted: Sun May 05, 2013 2:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun May 05, 2013 5:21 am     Reply with quote

ur code seeing like timer code !
_________________
sahu
Praful



Joined: 18 Jun 2012
Posts: 23

View user's profile Send private message

PostPosted: Sun May 05, 2013 5:54 am     Reply with quote

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. Rolling Eyes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sun May 05, 2013 11:12 am     Reply with quote

Wrong part of the forum...
_________________
CCS PCM 5.078 & CCS PCH 5.093
Praful



Joined: 18 Jun 2012
Posts: 23

View user's profile Send private message

PostPosted: Sun May 05, 2013 12:02 pm     Reply with quote

What is wrong with this part of fourum........ Question
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Sun May 05, 2013 12:45 pm     Reply with quote

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: 19538

View user's profile Send private message

PostPosted: Sun May 05, 2013 1:56 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 06, 2013 5:33 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group