Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/22/08 10:12
Read: times


 
#157656 - 8052 based Controller for 1KW MOSFET POWER AMP
Hi Everyone,

My name is Ravi and I am hoping to build a Controller to provide functionality like IR,TEMPERATURE CONTROL OF HEATSINK, MONITORING FOR DC COMPONENT IN OUTPUTS, FAN CONTROL and remote control for switching ON/OFF my 500W MOSFET POWER AMP (which is also built by me)....
Some background ....

I have already a working P89C51RD2 based SBC with a modified MCS BASIC interpretter( with the ISP suitably wired so that I can readily develop code-using Flash Magic)

I have subsequently interfaced it to a 16X2 LCD display and have the driver written and working. I have 64K CODE and 32K Data spaces on my board.Clock @ 11.059200MHz

Now I am struggling with the remote control portion and cant seem to get it working... I am using a TSOP1738 module and have it connected to the INT0 pin(12) and I am trying to understand the operation...
Can any body guide me a proper way in which to know if I am decoding the RC5 correctly? I have lifted code from Juergen Putzger that i found on the net...am including it for you here

..;  ---------==========----------==========---------=========---------

;         Interrupt Driven Receiving Routine for RC5 code

; written by Juergen Putzger (juergen.putzger@physik.uni-regensburg.de)

;  ---------==========----------==========---------=========---------





INPUT   	EQU     P3.2    ; Port3,Bit2 is used as input. The demodulated signal 

                       		; with active low level is connected to this pin     

LF      	EQU     0AH     ; Linefeed     

CR     		EQU     0DH     ; Carriage return

SPC     	EQU     20H     ; Space

RB0     	EQU     000H    ; Select Register Bank 0

RB1     	EQU     008H    ; Select Register Bank 1  ...poke to PSW to use



        	DSEG            ; This is internal data memory

        	ORG     20H     ; Bit adressable memory



FLAGS:  	DS      1      

CONTROL 	BIT     FLAGS.0 ; toggles with every new keystroke

NEW     	BIT     FLAGS.1 ; Bit set when a new command has been received 

COMMAND:	DS      1       ; Received command byte

SUBAD:  	DS      1       ; Device subaddress 

BUFFER: 	DS      30      ; Buffer to store length of transmitted pulses

STACK:  	DS      1       ; Stack begins here               

		

        	CSEG            ; Code begins here
		

;---------==========----------==========---------=========---------

;              PROCESSOR INT0 vector set up by basic at 4003H

;---------==========----------==========---------=========---------

        	ORG     4003H  ; Basic Branches here for INT0 Low going pulse

         	LJMP    RECEIVE ;redirect to the receive routine

;  ---------==========----------==========---------=========---------

;Interrupt routine is entered by the first high to low transition

;at Port3-Bit2.pin(12-INT0). Stores the length of all pulses occuring
;at this pin in buffer. Analyzes the timing of the startbits to calculate

;a threshold between short and long pulses. This routine is independent 
;of CPU speed. The device address and command are 

;extracted from the bit stream. Two flags are set upon exit,

;the control bit(FLIP bit) which toggles with every new keystroke and the 

;NEW bit indicating that a new command has been received.    

;---------==========----------==========---------=========---------

		ORG	04400H

RECEIVE:

	 	PUSH   	DPH
	 	PUSH	DPL
	 	PUSH	ACC	 
	 	PUSH   	PSW           ; save current registerset

         	MOV    	PSW,#RB1

         	MOV    	R0,#BUFFER
		MOV	A,#38
		CALL	C_OUT
		MOV	A,#CR
		CALL	C_OUT
		MOV	A,#LF
		CALL	C_OUT
		MOV	A,#39
		CALL	C_OUT
REC:
	     	MOV    	A,#0

REC0:
	    	INC    	A             ; Measure duration of low-level  

         	NOP

         	NOP                  ; Delay 

         	NOP                 

         	NOP

         	JZ     	TIMEOUT       ; End of transmission if duration exeeds 256 counts

         	JNB    	INPUT,REC0 

         	MOV    	@R0,A

         	INC    	R0

         	MOV    	A,#0          

REC1:
	    	INC    	A             ; Measure duration of high-level

         	NOP

         	NOP                  ; Delay

         	NOP

         	NOP

         	JZ     	TIMEOUT       ; End of transmission if duration exceeds 256 counts

         	JB     	INPUT,REC1

         	MOV    	@R0,A

         	INC    	R0

         	JMP    	REC    

TIMEOUT:  

         	MOV    	A,BUFFER      ; calculate threshold between short and long pulses 

         	INC    	R0            ; length of first low-pulse

         	ADD    	A,BUFFER+1    ; plus length of first high-pulse 

         	CLR    	C

         	RRC    	A             ; divided by two

         	MOV    	R1,A

         	CLR    	C

         	RRC   	A             ; plus half of the time

         	ADD    	A,R1

         	MOV    	R5,A          ; yields threshold

         	MOV    	R0,#BUFFER

         	MOV    	R1,#1         ; initial value  

         	MOV    	R2,#13        ; Number of bits to decode

DECODE:
	  	MOV    	A,@R0

         	INC    	R0

         	CLR    	C

         	SUBB   	A,R5          ; compare length with threshold

         	MOV    	A,#0

         	CPL    	C             ; short=1

         	RLC    	A

         	JNZ    	NOSKIP

         	INC    	R0            ; if short skip over next pulse

NOSKIP:
	  	XRL    	A,R1          ; new bit is calculated by XOR with previous bit

         	MOV    	R1,A          ; Store new bit

         	RRC    	A

         	MOV    	A,R3          ; Store new Bit in R3/R4 by rotating 

         	RLC    	A

         	MOV    	R3,A

         	MOV    	A,R4

         	RLC    	A

         	MOV    	R4,A

         	DJNZ   	R2,DECODE

         	MOV    	A,R3          

         	ANL    	A,#00111111B  ; extract command from R3

         	MOV    	COMMAND,A

         	MOV    	A,R3		

         	RLC    	A   	      ; do some rotating to extract 	  

         	XCH    	A,R4

        	RLC    	A             ;device address 

	        XCH    	A,R4

         	RLC    	A       

         	XCH    	A,R4    

         	RLC    	A   

         	CLR    	CONTROL

         	JNB    	ACC.5,TZ      ; Check control bit

	        SETB   	CONTROL         

TZ:
	     	ANL    	A,#00011111B  ; mask device address

        	MOV    	SUBAD,A

;        	POP    	ACC           ; Restore old registerset

;       	POP    	PSW

        	SETB   	NEW           ; Set flag to indicate the new command

		POP	PSW
		POP	ACC
		POP	DPL	         
		POP	DPH
		RETI 

;  ---------==========----------==========---------=========---------

;Main routine.
;Program execution starts here. 
;The Main loop waits until a command has been received. 
;Then the control bit, subaddress ;and command byte 

;are printed separated by spaces. Leading zeroes are not suppressed.

;When a standby command (12) has been received, the main loop is 

;terminated and the program returns to the monitor. 

;  ---------==========----------==========---------=========---------

		



MAIN:   	 
		 PUSH  	DPH
	 	 PUSH	DPL
	 	 PUSH	ACC	
		 PUSH	PSW		 
		 MOV    TCON,#00H     	;MAKE SURE TIMERS ARE SHUT DOWN.

        	 MOV    PSW,#RB0      	;Select register bank 0

        	 MOV    SP,STACK

        	 SETB   EX0           	;Enable external Interrupt0

        	 CLR    IT0           	;triggered by a high to low transition  

        	 SETB   EA   

	         CLR    NEW

		 MOV    A,#31H
		 CALL 	C_OUT
		 MOV    A,#32H
		 CALL	C_OUT
		 MOV	A,#33H
		 CALL	C_OUT
		 MOV	A,#34H
		 CALL	C_OUT
LOOP:		 JNB    NEW,LOOP      	;Wait until a command has been received

	         MOV    A,#CR

	         CALL   C_OUT         	;Ouput carriage return and linefeed

	         MOV    A,#LF

	         CALL   C_OUT

	         MOV    A,FLAGS

	         ANL    A,#00000001B

	         CALL   BIN2BCD       	;Output control Bit  

	         MOV    A,#SPC

	         CALL   C_OUT

	         MOV    A,SUBAD

	         CALL   BIN2BCD       	;Output subaddress

	         MOV    A,#SPC

	         CALL   C_OUT

	         MOV    A,COMMAND

	         CALL   BIN2BCD       	;Output command

	         MOV    A,COMMAND

	         CLR    C

	         SUBB   A,#0CH        	;compare for standby command

	         CLR    NEW

	         JNZ    LOOP          	;go on receiving

	         CLR    EX0           	;stop receiving

	         CLR    EA            	;and 

		 POP 	PSW		;Restore the Registers
		 POP	ACC
		 POP	DPL
		 POP	DPH	        	 
	         RET       		;return to Basic


N_OUT:  	 
		 ADD    A,#30H  	;Convert BCD number to ASCII

C_OUT:  	 JNB    TI,$    	;Wait until transmission completed.

        	 CLR    TI      	;Clear interrupt flag.

        	 MOV    SBUF,A  	;Write out character to serial port.

		 RET



BIN2BCD:                		;Convert 8 bit value in Acc to 3 digit BCD 

	         MOV     B,#100          

	         DIV     AB      

	         CALL    N_OUT

	         XCH     A,B

	         MOV     B,#10

	         DIV     AB

	         CALL    N_OUT

	         XCH     A,B

	         CALL    N_OUT

	         RET

       

         	 END    




List of 3 messages in thread
TopicAuthorDate
8052 based Controller for 1KW MOSFET POWER AMP            01/01/70 00:00      
   Curious...            01/01/70 00:00      
   RC5 decoding            01/01/70 00:00      

Back to Subject List