Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

Urgent: Help With PCA timing please!!

Status
Not open for further replies.

rallysteve

Newbie level 6
Joined
Apr 24, 2012
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,417
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

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
 

Okay, I have managed to sort the Assembly program to operate pins 1.3 and 1.4 seperately using Modules 0 and 1 after a set delay after the external interrupt 0 has triggered. However the maximum delay I can now trigger is using 0FFh as both CCAPxL and CCAPxH gives a delay of 23.7mS between External Interrupt and PCA flag. I cant work out how to calculate the timing properly. I can alter the mode so that the PCA clock input is 1/12 of the oscillator frequency but to get large enough delays I will have to multiply my 00 to FF range, resulting in larger than 8 bit numbers and I am not sure how I can do this with Keil. Can anyone offer any advice please? My revisised code is shown below:
Code:
$NOMOD51
$INCLUDE (REG_C51.INC)
 SB_1	DATA		11H
 SB_2	DATA		12H

 ORG	0000H
SJMP	SETUP

 ORG	0003H
 SJMP	TRIGGER

 ORG	0033H
SJMP 	PCA_INT0



SETUP:		
/* Sets up PCA and Interrupts */
			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


							

MAIN:
/* Main Program Lives Here */		
			mov		A,00H	  	
			mov		P1,A		; Clear All P1 Pins
		
			JMP		MAIN


TRIGGER:
/* Interrupt Triggered by negitive pulse of Zero Crossing Detector (100Hz @ 50Hz Mains) */
			PUSH	PSW
			MOV		CCAPM0,#04DH ; Set Module 0 to High Speed Mode, Fosc x 1/4
			MOV		CCAPM1,#04DH ; Set Module 1 to High Speed Mode, Fosc x 1/4			
			MOV		CCAP0L,#0FFH ; Set number of counts before Module 0 triggers Flag (CCF0)
			MOV		CCAP0H,#0FFH
			MOV		CCAP1L,#0FFH ; Set number of counts before Module 1 triggers Flag (CCF1)
			MOV		CCAP1H,#0FFH
			MOV		CL,#00H		 ; Reset Low Counter
			MOV		CH,#00H	   	 ; Reset High Counter
		
			SETB	CR			 ; Set Timer to Run
			POP		PSW
			RETI

PCA_INT0:
/* Triggers When Interrupt Flag is Set */	
		 	JNB		CCF0,NNOT		; Jump if Flag 0 Not Set
			MOV		CCAPM0,#00H		; Disable Module 0
			CLR		CCF0			; Clear Module 0 Flag
NNOT:		JNB		CCF1,JUMP	    ; Jump if Flag 1 Not Set
			MOV		CCAPM1,#00H		; Disable Module 1
			CLR		CCF1			; Clear Module 1 Not Set
JUMP:
			RETI					; Return from interrupt

		
END

Thanks
Steve
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top