Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

problem using PIC 18f4520 with 5v relays

Status
Not open for further replies.

student1986

New Member
Hi,
I'm working on my senior project with PIC18F4520. The PIC should generate a sequence signal to be displayed on 12 DC lights. PIC 18F4520, PORT B in the PIC is connected to 3X8 decoders, the output from the decoder is connected to HEX inverters, then it is connected to BJTs(SN2222), and output from BJTs is connected to one terminal of the 5 v relays coil, and then to the DC lights. ALSO I have connected diode (n4001) in across the coil of the 5v relay.... Now, If I connected only three light, it works with the correct sequence, but when I connected another 3 lights one sequence will disappear, and if I connected another 3 lights 2 sequences will disappear and only the first sequence will appear all the time..

I tried my code only with LEDS instead of relays and lights to see the output, and the output was correct, so the problem happened when I connected the relays..


Can any one help please.
Thanx
 
Last edited:
Post a schematic

If you want to get an accurate answer then a schematic is needed.
sounds like your power supply is short on power??
 
I took screen shot from the ISIS schematic, but also there is a terminal in the relays wich has 12v to operate the DC lights.
 

Attachments

  • pro.doc
    128 KB · Views: 262
It might be nice if we could actually see the part of the schematic that has the relays on it.
 
I have already attached my schematic on .doc file, I took 2 screen shots

but do u want me to take a photo of my real ciruit ?
 
It's hard to follow your circuit as you don't indicate where wires cross as opposed to join. However, if I'm reading it correctly you have a relay from +5V to the emitter of an NPN transistor! If I'm reading this right then your transistors are upside down.

Mike.
 
Sirs,

it gave me the correct sequence 3 times, but then all the lights switched off and after some delay it works agian and so on..

what can I do ?

thanks
 
Last edited:
It sounds like noise is causing a reset due to insufficient decoupling capacitors.

However, I can't see how your code is working as you aren't clearing the interrupt flag.

Code:
void MyHighInt(void)
{	
int myarry[4]={0x22,0x66,0x88,0x99};
   TRISB = 0x00;           // PORTB is output
   cnt++;                  // Increment value of cnt on every interrupt 			 
   if (cnt == 2000) {
      PORTB=myarry[count]; // Toggle PORTB LEDs
      count = count+1;
      cnt = 0;             // Reset cnt
   }
   if(count==4)
       count = 0;
}


Mike.
 
sir this is my new code & I still have the same problem



#include <p18f4520.h>
#include <timers.h>
#include <delays.h>

#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
//#pragma config BOR = OFF
#pragma config MCLRE = ON
unsigned int cnt=0;
unsigned int count=0;

void MyHighInt(void); // prototypes for the interrupt
#pragma interrupt MyHighInt // MyHighInt is an interrupt
#pragma code high_vector=0x08 // high_vector is at 0x0008
void high_vector(void) // the high prioity vector
{
_asm GOTO MyHighInt _endasm // goto high software
}
#pragma code // start code here
void MyHighInt(void)
{

int myarry[4]={0x22,0x66,0x88,0x99};
TRISB = 0x00; // PORTB is output
INTCONbits.TMR0IF=0;


PORTB=myarry[count]; // Toggle PORTB LEDs
count = count+1;


if(count==4)
count = 0;
}
// main program
void main (void)
{


INTCON2bits.TMR0IP=0;
INTCONbits.TMR0IF=0;
INTCONbits.TMR0IE=1;
T0CONbits.TMR0ON=1;

OpenTimer0 (TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_256);
WriteTimer0( 0 );
RCONbits.IPEN = 1; // IPEN = 1 to enable priority interrupts
INTCONbits.PEIE=1;
INTCONbits.GIEH = 1; // enable high priority interrupt

while(1);



}
 
Last edited:
it gives 3 times the correct sequence and then all the lights will turn off, after some delay it works again but with shorter time.. I do not know whats the problem..

please help
 
This looks like a hardware problem.

Do you have MCLR tied high via a resistor?
Does your power supply shut down through overheating?
Etc.

Mike.
 
yes sir I have my MCLR on and tied by resistor(10K ohm)

but, I did not understand what do u mean by "power supply shut down through overheating"

I tried tp put 330 ohm resistor directly before the base of each NBN transistor and it works with me now.. but I'm worried, because it may not be this is the solution of the problem, but until now the sequence is correct and works infinaitly, I do not know if this is the reson of why my circuit woks corectly now!! because I do not want this problem to happened again, only 16 days is left for submition the project :-(

what d u think ?
 
Last edited:
what d u think ?

Mainly I think "why all the extra chips?", why not feed the driver transistors directly from the PIC? (via current limiting resistors of course).

Or is this another bizzarre 'updated' assignment where some lazy teacher has crossed out 'Z80' (or something similar) and written 'PIC' in it's place, making a complete mockery of the original assignment.

Otherwise, I would mark such a project very low, as a very poor example of design.
 
acutally no we can not feed the transistor directly from the pic, since I need the decoder and inverters, thats why!!

this is not an assignment, this is only small part of my senior project, and I need both the decoders and invertors to be in the design..

If I do not need the decoders & invertors for a purpose ,so why do u think that I put them ???

by the way, the code is mine and the design as well and it is not an assignment !!!
 
Last edited:
So the inverters and the decoders are nothing to do with the section of circuit you've shown? - presumably they are somehow involved in another part of it?, with connections you've not yet shown.

As for their purpose in been there, your posts so far show no reason for them, which is why I was wondering?.
 
I have posted my schematic circuit based on a request, and I was sure that the problem was in the hard ware since I tried to connect LEDs directly to the output of the inverter and it works with me, the problem happened when I used the relays with DC lights, 12 relays is too much, but I have no other options, but I’m still worry because I do not want the problem to happen again with me, because I need to do other modifications on the code and add a serial connections with max232 to the hard ware as well to achieve the goal of the project..
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top