Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Relay chattering problem at system start-up

Status
Not open for further replies.

sush

Member level 4
Joined
Aug 24, 2005
Messages
78
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,946
hi,

I'm almost new to micro-controllers. I made this small project to switch on&off a
relay using 89c51, and Push-button. I've installed both switch and relay on port0.
and also added pullup resistors. The system is working fine, but, my problem is,
whenever i switch on the system the relay switches on and off for a fraction of a
second, how can i eliminate this one time chattering of relay? i tried adding a
condensor at the base of transistor, the chattering stopd but when i need to push
the switch to on the system the relay takes some time to switch on. I'm sending both diagram and code, please help!!!

every help would be appriciated, Thanks.

Code:
;***************************************************************************

#INCLUDE "8051EQU.INC"          ;include predefined constants
;
;**************************************************************************

; RESET                         ;reset routine

   .ORG   0H                    ;locate routine at 00H
    AJMP   START                ;jump to START 
;
;**************************************************************************
;
; INTERRUPTS  (not used)        ;place interrupt routines at appropriate
                                ;memory locations
   .ORG   03H                   ;external interrupt 0
    RETI
   .ORG   0BH                   ;timer 0 interrupt
    RETI
   .ORG   13H                   ;external interrupt 1
    RETI
   .ORG   1BH                   ;timer 1 interrupt
    RETI
   .ORG   23H                   ;serial port interrupt
    RETI
   .ORG   25H                   ;locate beginning of rest of program
;
;**************************************************************************
;
INITIALIZE:                     ;set up control registers
;
    MOV   TCON,#00H
    MOV   TMOD,#00H
    MOV   PSW,#00H             
    MOV   IE,#00H               ;disable interrupts
    RET
;
;**************************************************************************

;**************************************************************************
;
START:                         
   	ACALL INITIALIZE           
LOOP:                          
	JB P0.1, LOOP
HERE:
	JNB P0.1, HERE		;WAIT FOR KEY RELEASE
	CPL P0.2
   	AJMP LOOP
.END
 

IanP

Advanced Member level 5
Joined
Oct 5, 2004
Messages
7,942
Helped
2,309
Reputation
4,620
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,459
Re: Relay problem

You may have switch bounce problems ..
Try to add delays to both loops:

Loop:
JB P0.1, Loop
CALL Delay (≈50-100ms)
JB P0.1, Loop

Here:
JNB P0.1, Here
CALL Delay (≈50-100ms)
JNB P0.1, Here

CPL P0.2
SJMP Loop


Also, connect 100µF+100nF bypass capacitors between +5V and 0V, add 10nF-100nF capacitor betwwen P0.1 and GND .. and try again ..


Regards,
IanP

PS, if you need a DELAY subroutine here is an example:

Firstly replace:
MOV TMOD,#11H ;both timers in 16-bit mode
MOV TCON,#00H ;stop both timers
in INITIALIZE ..

;------------------------------------------------------------------------
; 0.1 SECOND DELAY ROUTINE AT 12 MHz SPPED
; {TR0(50ms) + TR1(50ms)} x R7(01) = 0.1 secOND delay
;------------------------------------------------------------------------
DELAY:
MOV R7,#COUNT ;load R7 for loop repeat counter

DLOOP:
MOV TL0,#LOW(FIFTY) ;load low byte for 50ms
MOV TH0,#HIGH(FIFTY);load high byte
MOV TL1,#LOW(FIFTY) ;load low byte for 50ms
MOV TH1,#HIGH(FIFTY);load high byte

SETB TR0 ;start timer TR0 for 50 milli seconds
JNB TF0,$ ;wait until TRO flag is set
CLR TR0 ;stop timer TR0
CLR TF0 ;clear TR0 flag bit

SETB TR1 ;start timer TR0 for 50 milli seconds
JNB TF1,$ ;wait until TRO flag is set
CLR TR1 ;stop timer TR0
CLR TR0 ;clear TR0 flag bit
DJNZ R7,DLOOP ;decrement and check R7 for loop repeat

RET
 

sush

Member level 4
Joined
Aug 24, 2005
Messages
78
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,946
Relay problem

I really appritiate the efforts u took to reply to my question. First of all there's no problem of key debounce. my problem is, when i switch on the system (micro-controller) the relay activates for a second and then switches off, help me for that.

and also i tried adding a 100uf+100nF capacitor, i even tried adding 10uf tantalum
capacitor, a 100nf very near to pin 40 of 89c51......but none of them worked out.
 

IanP

Advanced Member level 5
Joined
Oct 5, 2004
Messages
7,942
Helped
2,309
Reputation
4,620
Reaction score
531
Trophy points
1,393
Location
West Coast
Activity points
66,459
Re: Relay problem

Bear in mind that on power-on (reset) all ports are loaded with "FFh" what means that the relay will be energized as soon as you apply power to the micro ..
As the very first instruction of your code try:

CLR P0.2 ..

Regards,
IanP
 

penrico

Full Member level 5
Joined
Aug 28, 2001
Messages
286
Helped
27
Reputation
54
Reaction score
8
Trophy points
1,298
Location
Argentina
Activity points
2,395
Re: Relay problem

I don't check if it's a software problem. But, you use a BC547 transistor, and you don't say anything about what kind of relay you used. BC546/BC547/BC548 transistors gain (hfe) are dependents of how much current drops from collector to emiter. First, base resistor must be lower 1K or less. I recomend that change the transistor to a BC337 is more stable the gain at high currents (up to 800mA).

:arrow:
 

artem

Advanced Member level 4
Joined
May 22, 2003
Messages
1,350
Helped
126
Reputation
252
Reaction score
32
Trophy points
1,328
Location
Turkey
Activity points
13,461
Relay problem

I dont know PIC , in other mciros ports are tristate at POR. If said is true (port are set to 0xff at PORT) problem can be solved as :
- discard circuitity connected to P0.2
- use PNP BJT transistor as - emitter connected to +5V
collector to relay , base to P0.2 through 4.7 K. Another end of relay connected to ground with parallel diode (katod to ground )
- changes in software as - output logical 0 to switch relay ON in program


if ports are set to tristate at POR you should :
- cut 10 kOhm connected between P0.2 and +5V
- connect 10 kOhm to BC547's base and other end of resistor to ground.

Also , your reset delay is too long - t~ 100 msec . Dont know what is recommended for PIC but you could decrease capacitor value to acceptable reset delay .
 

sabu

Junior Member level 3
Joined
Sep 20, 2005
Messages
31
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,517
Relay problem

it is the problem with higgh voltage appearing at the port of 8051.it is better to compliment ur out put logic.
try it,
wth gluck sabu
 

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
451
Helped
25
Reputation
50
Reaction score
9
Trophy points
1,298
Activity points
3,605
Re: Relay problem

Check the attachment. This is the perfect result for you. i fully agree to what "artem" said. Right "Ianp" ???
 

Pont de Pedra

Junior Member level 3
Joined
Dec 7, 2005
Messages
27
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,283
Location
CATALUNYA
Activity points
1,561
Re: Relay problem

Hi sush:

Where is your decoupling capacitor?

Hope this helps.
 

sush

Member level 4
Joined
Aug 24, 2005
Messages
78
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,946
Relay problem

Thanks Pont de Pedra for replying. i tried that. small value capacitor didn't helped and if i use higher value there comes up a delay in switch on/off of relay.
 

Pont de Pedra

Junior Member level 3
Joined
Dec 7, 2005
Messages
27
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,283
Location
CATALUNYA
Activity points
1,561
Re: Relay problem

I mean a 100nF (for instance) between ground and Vcc close to the uControler pins.
That is (in DIL package) pin 20(-) and pin 40 (+), not in the output pins.

Regardds.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top