Reg-Sv: Light Dimming Regulation
Reg-Sv: Light Dimming Regulation
Reg-Sv: Light Dimming Regulation
July, 1999.
Calculation
Comfortable programming supposes we use 1 byte for
delay. In best case, 256 different dimming levels will
be available. Processors clock is 4MHz. It is
internally divided by 4. What is the value of
prescalling coefficient? 64. If we adopt 64 we can
get maximal dimming for nmax=(10ms/64s)157 (157
different dimming levels). In case of prescalling with
32, we get nmax312, (we need two bytes for
representing 312 different values of dimming). Finally,
it remains the case of prescalling with 128 n max79.
The best resolution we can get with one byte is 157
and prescalling coefficient is 64.
For estimated value of prescalling coefficient, we
must find the time minimum of triggering time delay.
Triggering the triac when amplitude of AC voltage is
too low, makes triggering insecure. Value for secure
triggering is taken as 20V.
min
1
20V
arcsin
311V 4
2 50
64 s
Reg-sv-1.1E 8/1
Initialization
2.
3.
4.
slow
down
speed
of
adding varistor
adding filter
CAUTION
HIGH VOLTAGE
CON1
3
2
1
1.
2.
Electrical schematics
S2
Literature
C1
phase
zero
light bulbe
47R0.5W
100n240Vac
VDD
D1
R2
1N4007
D2
ZD1
R1
220V AC
120K
47uF/16V
EC1
1N4007
C4
100n
5.1V
gnd
RA1
TRI1
TIC206M
RA2
R8 R7
1M5 1M5
C
VDD
gnd
VDD
S1
taster switch
R3
33k
R6
220
C2
22p
Q1
For testing
U1
16
4
17
18
1
2
3
6
gnd
C1
22p
R4
20k
C3
22n
gnd
4Mhz
OSC1/CLKIN
MCLR
RA0
RA1
RA2
RA3
RA4/T0CKI
RB0/INT
OSC2/CLKOUT
RB1
RB2
RB3
RB4
RB5
RB6
RB7
15
7
8
9
10
11
12
13
RB1
R5
1k
LD1
LED
PIC16F84-04I/P(18)
R10 R9
4M7 4M7
VDD gnd
Projekat
Regulator svetla
Projektovao
Datum
ANEL, Vrsac
28-Oct-1999
Fajl
D:\cuvanje\PROTEL\SCH\SEME\dim\dim.Sch
1
Reg-sv-1.1E 8/3
Init
STISAK_KASNJENJE
VREDNOST_MAX .200
VREDNOST_MIN .4
.50
ORG 0000h
; Reset vector.
bcf
clrf
clrf
goto
; hardware initialization
; turn off interrupt
;
;
INTCON,GIE
STATUS
PORTB
InitNext
ORG 0004h
goto
; Interrupt vector.
Main_init
;**************************************************************************
;
Main program
;**************************************************************************
Main_init
movlw
movwf
movlw
movwf
movlw
movwf
0x03
PORTB
VREDNOST_MAX
Vrednost
0xff
Smer
;test call
;
goto
Tastaturamain
test
Reg-sv-1.1E 8/4
Main_drugi
call
Tastaturamain
btfsc PORTA,2
goto
Main_drugi
;initialization of second half-period
bcf
PORTB,1
clrf
TMR0
Drugapetlja
btfsc PORTA,2
goto
Main_prvi
movf
Vrednost,W
subwf TMR0,W
btfss STATUS,C
goto
Drugapetlja
;turn on
bsf
call
PORTB,1
Ukljuci
Drugapetljacekaj
btfss PORTA,2
goto
Drugapetljacekaj
bcf
PORTB,1
goto
Main_prvi
Ukljuci
;software compensation starts here
movlw .150
subwf Vrednost,W
;compensation of histerezis
btfsc STATUS,C
return
;software compensation ends here, this 4 lines can be removed
movlw b'00001111'
movwf PORTB
movlw b'00000000'
bsf
STATUS,RP0
movwf TRISB
bcf
STATUS,RP0
nop
nop
Reg-sv-1.1E 8/5
b'00000001'
STATUS,RP0
TRISB
STATUS,RP0
;**************************************************************************
;
;
Sub-program for taster switch
;
;
;**************************************************************************
Tastaturamain
movf
PORTA,W
andlw b'00000001' ;filter for zero bit
movwf Sad
;puts in Sad and after that puts in Pre
andwf Pre,W
;this is for taster switch debouncing
movwf Stanje
;
movf
Sad,W
movwf Pre
;if two successive reading of RA0 are logical 1
btfss Juce,0
;taster-switch is pushed, then variable Stanje gets
goto
Tastkraj
;value 1;
btfss Stanje,0
goto
Tastprekinutpritisak
;check push button is released
;The new and previous reading of pushbutton switch are 1, pushbutton is pressed
movlw STISAK_KASNJENJE
subwf Stisak,W
;pushbutton is not released
btfss STATUS,C
;checks how long it was kept pushed
goto
Tastparanput ;even and odd, to slow down counting
;light on
decf
Stisak,F
movlw 0xff
xorwf Speedcontrol,F
movf
Speedcontrol,F
btfss STATUS,Z
goto
Tastparanput
;odd pass, only for slow down
btfss Smer,0
;check the positive direction
goto
Tastnegativansmer
;negative direction
;positive direction
movlw VREDNOST_MAX
subwf Vrednost,W
btfss STATUS,Z
goto
Tastnijemaxdim
;count off, change direction
clrf
Smer
decf
Vrednost,F
Tastnijemaxdim
incf
Vrednost,F
Tastparanput
incf
Stisak,F
Tastkraj
movf
Stanje,W
movwf Juce
Tastend
return
Tastnegativansmer
movlw VREDNOST_MIN
subwf Vrednost,W
Reg-sv-1.1E 8/6
;**************************************************************************
;
initialization
;**************************************************************************
InitNext
MoreMem
clrf
bsf
movlw
movwf
movlw
movwf
movlw
movwf
bcf
clrf
movlw
movwf
PORTA
STATUS,RP0
b'00000001'
TRISB
b'00011111'
TRISA
b'10000101'
OPTION_REG
STATUS,RP0
TMR0
b'00000000'
INTCON
movlw
movwf
clrf
incf
movlw
xorwf
btfss
goto
0ch
FSR
INDF
FSR,F
4fh
FSR,W
STATUS,Z
MoreMem
goto
Main_init
;
;
; RB1-RB7,are outputs, RB0 input
;
; RA0-RA4 are inputs.
; Configure OPTION register
;
;
; TMR0 = 0.
; Configure INTCON register
; 7-GIE, 6-EEIE, 5-T0IE, 4-INTE
; 3-RBIE, 2-TOIF, 1-INTF, RBIF
;
; clear RAM
;
;
;
;
;
Reg-sv-1.1E 8/7
Dimprom.asm
; date: 28.02.1999.
cblock 0x1c
Vrednost
Speedcontrol
Stisak
Stanje
Juce
Smer
Sad
Pre
endc
Reg-sv-1.1E 8/8