43
4.1.1 Pulse Width Modulation to Reduce Relay Power
Typically relays need far less current to hold them closed than is needed to initially close
them. For example, if the driver is switched to a 75% duty cycle using pulse width modu-
lation after the initial period when the relay armature is picked, the holding current will be
approximately 75% of the full duty-cycle current and the power consumption will be
about 56% as great.
The pulse width modulation rate may be from 5 kHz to 20 kHz. If a periodic interrupt is
established that interrupts every 50 s, then a 50% duty cycle could be set up for a 100 s
period. A 25%, 50% or 75% duty cycle could operate on a 200 s period. A 250 s period
would allow duty cycles of 20%, 40%, 60% or 80%. The code for such an interrupt routine
might appear as follows.
push af
; 10
push hl
push de
ld hl,(ptr)
; 11 get pointer to location in array
ld a,(maskand)
; 9 get mask
and a,(hl)
; 5 get current output
ld e,a
; 2
ld a,(maskor)
; 9
or a,e
; 2
ioi ld (port),a ; 13 store in port
inc hl
; 2 point to next
ld a,(hl)
; 5 check for end of array
or a,a
; 2
jr nz,step2
; 2
ld hl,(beginptr); 11 reset hl to start of array
step2:
ld (ptr),hl
; 13 save hl
pop de
;7
pop hl
pop af
reti
; 7 return from interrupt
; 153 clocks total worst case - 7.5 us at 20 MHz
This routine would take approximately 15% of the processor’s compute time assuming
50 s between interrupts. This routine could be speeded up, but at the expense becoming
more complicated. Instead of "and" and "or" masks, a higher level routine could modify
the array directly, and the end of the array could be detected by testing a bit pattern in HL.
The higher level routine would have to suppress the interrupt while changing the bit pat-
tern in the array, or otherwise prevent erratic outputs while the array is being changed. If
the relay emits a whistle at the period of the modulation, the acoustic energy can be spread
out over the spectrum by periodically missing an "off" pulse, creating a phase shift of
180°. A faster routine that executes in two-thirds the time is shown below.