rallysteve
Newbie level 6
Thus us the last piece of my code I need to sort to get my project working and I just cant get my head around how to do it! I am using an Atmel 89C51ED2 with 11.0592MHz crystal.
Essentially what I am making is a light dimmer. Now I have got a zero crossing detector which sends a pulse to pin 3.2 (Interrupt 0) and then trying to create two seperate time delays from this event to trigger my two triacs (one for each light) which are connected to P1.3 and P1.4 (PCA module 0 and 1 pins). The brightness value is an 8bit Hex value ranging from 00H (fully lit) to FF(fully dimmed).
I cant seem to get my head around how to create a loop which runs this sucessfully. I have worked out that a zero crossing will occur (50Hz) every 0.01s so have divided this up into 256 segements meaning that I have to create a PCA loop which will range from 3.91x10^5s to 0.01s and alter depending on the brighness value.
I have tried to write some code below, however I just cant work out how to get it right. the values of SB_1 and SB_2 are the brighness values (00 to FF) one for either of the two lights.
Please can someone help me out with the code, this is the last bit of the project I have to write, I have worked the rest out myself.
Regards Steve
Essentially what I am making is a light dimmer. Now I have got a zero crossing detector which sends a pulse to pin 3.2 (Interrupt 0) and then trying to create two seperate time delays from this event to trigger my two triacs (one for each light) which are connected to P1.3 and P1.4 (PCA module 0 and 1 pins). The brightness value is an 8bit Hex value ranging from 00H (fully lit) to FF(fully dimmed).
I cant seem to get my head around how to create a loop which runs this sucessfully. I have worked out that a zero crossing will occur (50Hz) every 0.01s so have divided this up into 256 segements meaning that I have to create a PCA loop which will range from 3.91x10^5s to 0.01s and alter depending on the brighness value.
I have tried to write some code below, however I just cant work out how to get it right. the values of SB_1 and SB_2 are the brighness values (00 to FF) one for either of the two lights.
Please can someone help me out with the code, this is the last bit of the project I have to write, I have worked the rest out myself.
Regards Steve
Code:
$NOMOD51
$INCLUDE (REG_C51.INC)
SB_1 DATA 11H
SB_2 DATA 12H
ORG 0000H
SJMP SETUP
ORG 0003H
SJMP TRIGGER
SETUP: SETB TCON.0 ; Edge Sensitive Trigger
SETB IEN0.0 ; Enable Interrupt 0
SETB IEN0.7 ; Global Interrupt Enable
SETB EC
SETB EA
MOV CMOD,#02H ;fosc x 1/4 = 2.7648MHz
MOV CL,#00H
MOV CH,#00H
MOV CCAPM0,#04CH ; Set Module 0 to High speed mode with no interrupt
MOV CCAPM1,#04CH ; Set Module 1 to High Speed Mode with no Interrupt
MOV SB_1,00FH ; Set as values for simulation
MOV SB_2,00FH ; Set as values for simulation
MAIN:
JMP MAIN
TRIGGER: PUSH PSW
MOV CL,#00H
MOV CH,#00H
MOV CCAP0L,SB_1
MOV CCAP0H,SB_1
MOV CCAP1L,SB_2
MOV CCAP1H,SB_2
SETB CR
POP PSW
RETI
end