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.

Need a scheme ideea for driving a relay with PWM

Status
Not open for further replies.

nimik

New Member
I have a school project in wich I have to use a pic, and emulate PWM to actuate a relay(or many relays one for each output port).
The ideea is to reduce power consumption in such a board design(a circuit with many relays), because of the different current needed to lift the relay, and to mantain a relay actuated.
Because I have to emulate the PWM output, I want to use a PIC16F84(and not a PIC wich already has PWM output), since I used one before in another project.
I want to design a circuit, and because I am a beginer, I am not shure it's that simple to just connect the outputs directly to the relays and not use any additional transistor for amplification.
The relay's are left for me to choose, and I would choose those with small input voltage and current, so that I can drive them directly from the PIC.
Thank you all for suggestions!
 
Setup a timer ISR that reads a byte (for that port) that tells if the relay (via a bit) if it is to be on or off. If on, with a second byte, use that same bit to toggle (track) the pin on and off. You will need a counter byte as well to time the PWM.

Or better, just make a loop (no ISR) and do the same with a set of delays in the loop.

Hope that helps.
 
I can not follow you..

First I think I need a schematic for the connections and a block scheme for the circuit. I found this file and I thought I could use it for generating the PWM waveform.

PWM.asm

; FILE: PWM.asm
; AUTH: Keith Sevcik
; DATE: 5/21/03
; DESC: This program generates a PWM waveform.
; NOTE: Tested on PIC16F84-04/P

;----------------------------------------------------------------------
; cpu equates (memory map)

list p=16f84
radix hex

;----------------------------------------------------------------------

portb equ 0x06 ; port b equate
duty equ 0x0c ; length of duty cycle
temp equ 0x0d ; length of duty cycle

;---------------------------------------------------------------------

c equ 0 ; status bit to check after subtraction

;---------------------------------------------------------------------

org 0x000

movlw 0x00 ; load W with 0x00 make port B output
tris portb ; copy W tristate to port B outputs
movlw 0x00 ; fill w with zeroes
movwf portb ; set port b outputs to low
rstrt movlw d'0'
movwf portb
movlw d'157' ; Duty cycle length
movwf duty
b0loop movf duty,w
movwf temp
bsf portb,0
pwma nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
decfsz temp
goto pwma
movlw d'255'
movwf temp
movf duty,w
subwf temp,f
bcf portb,0
pwmb nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
decfsz temp
goto pwmb
goto rstrt

;----------------------------------------------------------------------

end

;----------------------------------------------------------------------
; at burn time, select:
; memory uprotected
; watchdog timer disabled
; standard crystal (4 MHz)
; power-up timer on
 
And this...

From the code I can see it uses PORTB 0 as PWM output. In my theory if the relay doesn't need much current for actuation I wold do this:
circuit-jpg.11816


Excuse me I just did that drawing in paint. It's just for the ideea.
 

Attachments

  • circuit.JPG
    circuit.JPG
    14.2 KB · Views: 1,213
nimik said:
I have a school project in wich I have to use a pic, and emulate PWM to actuate a relay(or many relays one for each output port.
The ideea is to reduce power consumption in such a board design(a circuit with many relays), because of the different current needed to lift the relay, and to mantain a relay actuated.

nimik:

I don´t get it. PWM for a relay?
A simple resistor would do the job (a particualr one for every kind of relay coil current)

Might it better be for some load like a Triac?
 
Yes, you need a schematic first. Get that and we can go from there.

What kind of relay is that? The pic will probably not handle a coil directly. Maybe drive a transistor and make sure you have current limiting on it and a diode across the coil.
 
He wants to activate the relay with full power then back off the power to hold the relay energized at a lower current.
A microcontroller making PWM is a little more efficient than using a coupling capacitor to provide full power in parallel with a resistor that reduces the current.
 
Yes audioguru. that's exactly what I need...by using a resistor the power is still lost thorough heat dissipation in the resistor...I just need to reduce the overall power consumption of the whole circuit.
Now I am in the phase of designing the schematic for the circuit. Probably the asm for the pic is ok so I don't have to worry right now about generating the PWM. I don't know if I can drive the coils of the relays directly from the pic. I probably need some transistors or something...
 
Last edited:
Look at the spec's on the datasheet for the microcontroller. The max output current is 25ma per output and the voltage drops with that much current. You need a transistor to drive each relay.
 
I think using PWM to reduce over all power consumption of a DC relay may be more difficult than just reducing the coil voltage after the relay is energized.
 
I am suposed to use PWM...

By varying the duty cycle of the PWM I can obtain the same effect as droping the voltage...
 
nimik said:
I found this file and I thought I could use it for generating the PWM waveform.

I've tried that code on a number of occasions, maybe it's just me, but I can't get it to work.
I'd advise checking that you can get it working before you go building a circuit for it.
 
audioguru said:
He wants to activate the relay with full power then back off the power to hold the relay energized at a lower current.


Well if that´s the case, the coil characteristics must be known
The oscillator period must be least an order of magnitude less than the relaxation time constant <the time-dependent response of a system to well-defined external stimuli> (L/R) of the relay coil.

A switching transistor could be connected in series with the actuator coil. A voltage sensing circuit is connected to one input of the microprocessor, which produces a pulse-width modulated actuator output to gate the switching transistor. The microprocessor is suitably programmed so as to produce a pulse width modulated signal actuator signal whose duty cycle is a function of applied voltage. The RMS current through the relay coil is sufficient to ensure good actuation, but does not overstress the coil. The relay is selected to have its rated actuation voltage at or below a lower end of the expected range of applied voltages

It´s feasible to use coils with different rated series resistances , so long as the rated coil voltages are the same and care is taken with respect to the relaxation times of the different relay coils.

The rated relay voltage is what the relay manufacturers specify as voltage to drive the relay coil with if the coil were driven from a dc source. Most manufacturers also specify the series resistance of the coil. This is the resistance of the copper wire and determines the steady state coil ON current. The relay inductance is not typically specified in the manufacturer’s short-form datasheet, so the engineer will need an LCR bridge to measure it or request the information from the relay manufacturer.
 
I can choose any relay I want, it's not a given model. That's why maybe if I could find those that have an input voltage <5 and low current need, I could connect them directly to the port of the PIC. And one more thing I did not think about is the Z (impedance) of the coil since in my project I am not using DC current and from what I know a coil has different resistance at different frequency. Thank you Luis for noticing that. Thanks to all of you helping me!
 
Aren't we forgetting that the relay coil, as an inductor, will dump its field energy through the diode across it (assuming there is one), thus dissipating the energy there instead of through a resistor?

If there isn't a diode to dump that energy, my guess is that the coil inductance will stabilise current flow to a reasonably constant value, which will have exactly the same effect as using a resistance to control current - in this case the switching device (transistor) will drop a constant voltage also, and dissipate the exact same power that a current limiting resistor would.

I reckon that you can't significantly reduce power loss in a relay by using PWM, due to its high inductance.
 
However - you might be able to harness that field-breakdown energy with a second winding on the relay core, or some clever buck-style energy pump/reservoir circuit instead of a simple diode across the coil.
 
nimik said:
By varying the duty cycle of the PWM I can obtain the same effect as droping the voltage...
That may be true. But a typical DC coil relay will operate in about 15 milliseconds and release in about 10 milliseconds.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top