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

Relay making PIC stop

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



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

Relay making PIC stop
PostPosted: Wed Mar 28, 2007 4:54 pm     Reply with quote

Hi All, i have tried to make a light conntroller that is controled using MIDI commands. It all works very well, but when i connect anything to the relays, eg to the 240VAC side, the PIC will stop about 2 sec later. Nothing happends if i unplug the light. I have tried to use diffrent devices on the 240 side, but it does not help.

The only thing that i can tell is it must be somewhere between when the PIC recived that data, and when i try to decode it, as PIN_E0 will be on when it stops.

The relays are powered off a diffrent power supply, and are connected via a darlington array.

Can anyone see why this may be happening??

Thanks, Mark

Code:

#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOBROWNOUT
#use delay(clock=48000000)

#use rs232(baud=31250, BITS=8, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define USB_CON_SENSE_PIN    PIN_D1


#include <STDLIB>
#include <usb_cdc.h>

int1 MIDIDataIN;         
int BeatStep, i, Loutput, Qcount;
int MIDImsg;
int BeatMask[35];



#int_rda
void MIDIBeatIn()
   {
      MIDIDataIN = 1;
      output_low(PIN_E0);                                          
      MIDImsg = getc();
   }

void SettingDownload()
   {
      disable_interrupts(INT_RDA);
      
      printf(usb_cdc_putc,"200\n");

      for(i=0;i<32;i++)                           //get Beat Masks from host
         {
            BeatMask[i] = get_int_usb();
         }

      printf(usb_cdc_putc,"200\n");

      BeatStep = 0;

      enable_interrupts(INT_RDA);
   }


   
void main()
   {
      delay_ms(100);
      
      BeatStep = 0;
      MIDIDataIN = 0;
      QCount = 0;

      for(i=0;i<32;i++)
         {
            BeatMask[i] = 0;
         }

      usb_init_cs();
   
      enable_interrupts(INT_RDA);
      enable_interrupts(GLOBAL);


      while(1)
         {
            usb_task();

            if (usb_cdc_kbhit())
               {
                  switch(get_int_usb())
                     {
                        case 200:   
                           SettingDownload();
                           break;

                        case 201:   
                            for(i=0;i<32>= 24)                              //Has 24 clocks gone, meaning that is is a beat
                           {
                              printf(usb_cdc_putc,"BEAT!!\r\n");            /////Testing
                              QCount = 0;

                              loutput = BeatMask[BeatStep];
                              output_b(Loutput);
                                          
                              if(BeatStep >= 31)                                             
                                 {
                                    BeatStep = 0;
                                 }
                              else
                                 {
                                    BeatStep++;
                                 }
                           }
                     }
                     
                  output_high(PIN_E0);
               }
         }
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 28, 2007 5:08 pm     Reply with quote

Whenever I hear a problem like this, the first thing I think of is the
"back emf" diode.
http://www.ccsinfo.com/forum/viewtopic.php?t=23634&highlight=relay+diode

There's a schematic diagram showing the diode across the relay's coil,
about half-way down this thread:
http://www.winpicprog.co.uk/pic_tutorial_extras.htm

Here's another page that describes the problem. Scroll about half-way
down to the section on "Quenching diodes".
http://www.bcae1.com/relays.htm
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Wed Mar 28, 2007 5:41 pm     Reply with quote

Thanks PCM, i forgot to say that i have back emf diodes installed
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 29, 2007 7:38 am     Reply with quote

How much current does your relay's coil require for pull-in and also for hold?

How are you driving the coil? Direct from the pin (generally bad idea) or with some kind of buffer?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Mar 29, 2007 1:58 pm     Reply with quote

It sounds like the PIC works as long as nothing is connected to the contacts of the relays, but a load on the relay contacts makes the PIC stop. In that case the problem is not on the coil side of the relay. I would look at the proximity of the 240VAC wiring to the PIC, and maybe add some snubber caps to the relay contacts.
_________________
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