Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to give 120degree phase shift i've written a code

Status
Not open for further replies.

esconele

New Member
whats wrong in my code because all pins showing pulse at same time meance there is no phase shift even if i 've given that much delay and toggle next pin after that where i'm doing wrong pls tell me
Code:
	#include "p18f458.inc"
		
;------------------BIT DEFINITIONS------------------------------------

F                 EQU      0x0001
;COUNT1 EQU 200
;COUNT2 EQU 0x0003
;COUNT3 EQU 0x0004
red equ B'10101010'
green equ B'01010101'
var UDATA
COUNT1 res 1
COUNT2 res 1
COUNT3 res 1
COUNT4 res 1
temp_1 res 1
temp_2 res 1
temp_3 res 1
;------------------VECTORS--------------------------------------------

	org	0x000000		; reset vector
	bra	START
	
	org	0x000008		; high priority interrupt vector
	bra	TMR3_ISR
   
	
	org 0x000070
;--------------------PROGRAM-----------------------------------
START
	clrf LATD
  	rcall    INIT
	
;Set up priority interrupts.
	bsf	RCON,IPEN	;enable priority interrupts.

	bsf	IPR2,TMR3IP	;set Timer3 as a low priority interrupt source

	bcf	PIR2,TMR3IF	;clear the Timer3 interrupt flag

	bsf	PIE2,TMR3IE	;enable Timer3 interrupts
	bsf	INTCON,GIEH	;set the global interrupt enable bits
	bsf	INTCON,GIEL	;	"

	MOVLW 0X02
	MOVWF temp_1

	
 


	clrf	T3CON
	bsf	T3CON,TMR3ON	;turn on Timer3
	movlw	0xd0
	movwf	TMR3H		;write 0xf000 to Timer3
	clrf	TMR3L
	movlw 0x01
	movwf COUNT4 
MLOOP  
                                      
	goto	MLOOP
   
;-------------------------------SUBROUTINES---------------------------------



TMR3_ISR			;low priority isr
	
	CPFSEQ COUNT4
LP1  goto lpl
LP2 
	BTG LATD,7
	BTG LATD,6
	
	movlw 0x02
	movwf COUNT1
	movwf COUNT2
	movlw 0x01
	movwf COUNT3
	bsf	T3CON,TMR3ON	;turn on Timer3
	bcf	PIR1,TMR1IF	;Clear the Timer1 interrupt flag.
lppl
	movlw 0xff
	movwf TMR3H
	movlw 0xfe
	movwf TMR3L
T1POLLl
	btfss	PIR2,TMR3IF	;Poll TMR11 interrupt flag to wait for another
				; TMR1 overflow.
	bra	T1POLLl	
	movlw 0xff
	movwf TMR3H
	movlw 0xfe
	movwf TMR3L
	bcf	PIR2,TMR3IF	;Clear the Timer1 interrupt flag again.
	
	decfsz COUNT1,F
	bra lppl
	decfsz COUNT2,F
	bra lppl
	decfsz COUNT3,F
	bra lppl
	
	INCF COUNT4 
	MOVLW 0X02   
	

	CPFSEQ COUNT4
	
LPP1
		goto lpl
LPP2

	bsf	T3CON,TMR3ON	;turn on Timer3
	bcf	PIR2,TMR3IF	;Clear the TMR3 interrupt flag.

	movlw 0xd0
	movwf TMR3H
	movlw 0x00
	movwf TMR3L
T1POLLl1
	btfss	PIR2,TMR3IF	;Poll TMR11 interrupt flag to wait for another
				; TMR1 overflow.
	bra	T1POLLl1	
	bcf	PIR2,TMR3IF	;Clear the Timer1 interrupt flag again.
	DECF COUNT4
	GOTO LP3
LP3 
	BTG LATD,5
	BTG LATD,4
	movlw	0xd0
	movwf	TMR3H		;write 0xf000 to Timer3
	MOVLW 0X01

	clrf	TMR3L
	;GOTO LP2
	

lpl
	retfie


INIT

	movlw red
	movwf LATD
	
   	 clrf	LATC		; setup portb for outputs
	clrf	TRISC

	clrf	TRISD
  
	return

	END
 
Now that you have presented code in the proper manner, could you give some more info? Which pins have to be 120 degrees delayed w.r.t each other? Try to give as much info as possible so we don't have waste time trying to decrypt your code.

Help us to help you.
 
HOW TO GIVE 120 DEGREE PHASE SHIFT

motion said:
Now that you have presented code in the proper manner, could you give some more info? Which pins have to be 120 degrees delayed w.r.t each other? Try to give as much info as possible so we don't have waste time trying to decrypt your code.

Help us to help you.


sir,
thanks for replying me actually i want a phase shift of 120degree in between PORTD7 and PORTD5 and again 120degree phase shift in between PORTD5,and PORTC7 these pins will be high first and at the same time PORTD6,PORTD,4 and PORTC,6 will be low having 120degree phase shift in between them this will be like this

R=PORTD,7
~R=PORTD,6
y=PORTD,5
~Y=PORTD,4
B=PORTC,7
~B=PORTC,6
WITH 120DEGREE PHASE SHIFT IN BETWEEN R-Y-B AND SAME FOR ~R-~Y-~B
CAN I CALL A DELAY(FOR PHASE SHIFT) ROUTINE IN ISR ROUTINE AND AT THE SAME TIME I WANT A PULSE OF 50HZ ON EACH PIN I'M USING A CRYSTAL OF 4.9152MHZ FOR THAT DID I CALCULATED THE CORRECT VALUES AND IS IT NECESSORY TO LOAD 0X07 IN CMCON REGISTER TO INITIALIZE PORTD BECAUSE IF I GIVE LOW INPUT TO PINS PORTD,6,4 AND PORTC,6 THEN THESE PINS REMAINS LOW AT ALL TIME AND EVEN IF I TOGGLED THE PORTD,5 AND PORTC,7 PIN AFTER PHASE SHIFT DELAY THEN ALSO THESE PINS STARTS TOGGLING AT THE SAME TIME AS PORTD,7 PIN TOGGLES HWERE I'M DOING WRONG SIR
 
I haven't had time to go through you code because frankly it looks like a mess! It looks like you have a delay loop within the ISR.

Anyway as suspected, you are trying to make a 3-phase inverter, possibly a motor inverter.

The way I would approach is to use a lookup table to index through. During a periodic interrupt, you take the values from this lookup table, indexing one step at each interrupt, and output them at the corresponding pins. At the end of the table, you start from the beginning on the next interrupt. Since you want to output 50Hz square wave, you need to interrupt at 6X this rate or 300Hz.

The table values will be as follows:

Code:
 retlw b'10010100'
 retlw b'10100100'
 retlw b'10101000'
 retlw b'01101000'
 retlw b'01011000'
 retlw b'01010100'

BTW, from the table RYB are displaced by 30degress from each other. However, their R and ~Y are displaced by 120 degrees. Just tweak the table to get the desired results.

HTH
 
hello sir,
i tried whatever you told me in prev reply and it was working but there was pulses only on portd 7 5 and portc,7 pins and there was more fluctuation in pulses thatswhy i again tried this code,
this code is giving the results whatever i want but there is some dropping of pulse after each 3 or 4 second why this is hapning and is this correct code for interfacing 3-phase 50hz power supply (120degree phase shift ) with pic18f458
and how to remove that dropping fault thanks



Code:
#include "p18f458.inc" 

;------------------BIT DEFINITIONS------------------------------------ 

F EQU 0x0001 
;COUNT1 EQU 200 
;COUNT2 EQU 0x0003 
;COUNT3 EQU 0x0004 
red equ B'10101010' 
green equ B'01010101' 
var UDATA 
COUNT1 res 1 
COUNT2 res 1 
COUNT3 res 1 
COUNT4 res 1 
temp_1 res 1 
temp_2 res 1 
temp_3 res 1 
;------------------VECTORS-------------------------------------------- 

org 0x000000 ; reset vector 
bra START 

org 0x000008 ; high priority interrupt vector 
bra TMR3_ISR 


org 0x000070 
;--------------------PROGRAM----------------------------------- 
START 
rcall INIT 

;Set up priority interrupts. 
bsf RCON,IPEN ;enable priority interrupts. 

bsf IPR2,TMR3IP ;set Timer3 as a low priority interrupt source 

bcf PIR2,TMR3IF ;clear the Timer3 interrupt flag 

bsf PIE2,TMR3IE ;enable Timer3 interrupts 
bsf INTCON,GIEH ;set the global interrupt enable bits 
bsf INTCON,GIEL ; " 

MOVLW 0X02 
MOVWF temp_1 





clrf T3CON 
bsf T3CON,TMR3ON ;turn on Timer3 
movlw 0xd0 
movwf TMR3H ;write 0xf000 to Timer3 
clrf TMR3L 
movlw 0x01 
movwf COUNT4 
MLOOP 

goto MLOOP 

;-------------------------------SUBROUTINES--------------------------------- 



TMR3_ISR ;low priority isr 

CPFSEQ COUNT4 
LP1 goto lpl 
LP2 
BTG LATD,7 
BTG LATD,6 
rcall delay240 

incf COUNT4 
MOVLW 0X02 


CPFSEQ COUNT4 

LPP1 
goto lpl 
LPP2 

incf COUNT4 
GOTO LP3 
LP3 
BTG LATD,5 
BTG LATD,4 

rcall delay120 

movlw 0x03 
cpfseq COUNT4 

lp4 
  bra lpl 

lp5 
btg LATC,7 
btg LATC,6 
decf COUNT4 
decf COUNT4 

lp6 
  movlw 0xd0 
  movwf TMR3H 
clrf TMR3L 

lpl 
retfie 


INIT 
clrf LATD 
movlw red 
movwf LATD 
clrf PORTC 
clrf TRISD 
clrf LATC ; setup portb for outputs 
clrf TRISC 
bsf LATC,7 
bcf LATC,6 


return 

delay240 
timer3 delay for .763sec 
return 

delay120 
timer3 delay for .381sec 
return  


END
 
tried whatever you told me in prev reply and it was working but there was pulses only on portd 7 5 and portc,7 pins and there was more fluctuation in pulses thatswhy i again tried this code,

It's hard to tell the cause of this if you don't post the code. You should have put all phase outputs into one port.

this code is giving the results whatever i want but there is some dropping of pulse after each 3 or 4 second why this is hapning and is this correct code for interfacing 3-phase 50hz power supply (120degree phase shift ) with pic18f458
and how to remove that dropping fault thanks

This could be a watchdog timer timeout. I don't see any configuration fuse directive in your code.
 
hello sir,
here is the code which is giving me correct output only when i give support to ckt and i diasabled the watchdog timer also
Code:
#include "p18f458.inc" 

;------------------BIT DEFINITIONS------------------------------------ 

F EQU 0x0001 
;COUNT1 EQU 200 
;COUNT2 EQU 0x0003 
;COUNT3 EQU 0x0004 
red equ B'10101010' 
green equ B'01010101' 
var UDATA 
COUNT1 res 1 
COUNT2 res 1 
COUNT3 res 1 
COUNT4 res 1 
temp_1 res 1 
temp_2 res 1 
temp_3 res 1 
;------------------VECTORS-------------------------------------------- 

org 0x000000 ; reset vector 
bra START 

org 0x000008 ; high priority interrupt vector 
bra TMR3_ISR 


org 0x000070 
;--------------------PROGRAM----------------------------------- 
START 
rcall INIT 

;Set up priority interrupts. 
bsf RCON,IPEN ;enable priority interrupts. 

bsf IPR2,TMR3IP ;set Timer3 as a low priority interrupt source 

bcf PIR2,TMR3IF ;clear the Timer3 interrupt flag 

bsf PIE2,TMR3IE ;enable Timer3 interrupts 
bsf INTCON,GIEH ;set the global interrupt enable bits 
bsf INTCON,GIEL ; " 


clrf T3CON 
bsf T3CON,TMR3ON ;turn on Timer3 
movlw 0xd0 
movwf TMR3H ;write 0xf000 to Timer3 
clrf TMR3L 
movlw 0x01 
movwf COUNT4 
MLOOP 

goto MLOOP 

;-------------------------------SUBROUTINES--------------------------------- 



TMR3_ISR ;low priority isr 

CPFSEQ COUNT4 
LP1 goto lpl 
LP2 
BTG LATD,7 
BTG LATD,6 
rcall delay240 

incf COUNT4 
MOVLW 0X02 


CPFSEQ COUNT4 

LPP1 
goto lpl 
LPP2 

incf COUNT4 
GOTO LP3 
LP3 
BTG LATD,5 
BTG LATD,4 
rcall delay120 
movlw 0x03 
cpfseq COUNT4 
lp4 
  bra lpl 
lp5 
btg LATD,3 
btg LATD,2 
decf COUNT4 
decf COUNT4 
lp6 
  movlw 0xd0 
  movwf TMR3H 
clrf TMR3L 

lpl 
retfie 


INIT
clrf PORTD 
clrf LATD 
movlw red 
movwf LATD 
clrf TRISD 

return 

delay240 
movlw D'200'
movwf COUNT1
movlw D'2'
movwf COUNT2
halt1:
decfsz COUNT1,1
goto halt1
decfsz COUNT2,1
goto halt1
 movlw 0xd0 
  movwf TMR3H 
clrf TMR3L 
bsf T3CON,TMR3ON
return 

delay120 
movlw D'200'
movwf COUNT1

halt12:
decfsz COUNT1,1
goto halt12

 movlw 0xd0 
  movwf TMR3H 
clrf TMR3L 
bsf T3CON,TMR3ON
return  


END
 
i diasabled the watchdog timer also

You have to disable the watchdog timer. Because if you do not disable (enable) the watchdog timer then you have to add the instruction "clrwdt" within the program loop. Without this instruction, your PIC will reset on watchdog timeout. I scanned your code and I don't see any clrwdt instruction.
 
its working thank you

sir,
finally its working i disabled watchdog timer , enabled power up timer ,disabled brown out detect , disabled ccp2 mux , disabled low voltage prog, and finally its giving the correct results but you told that we can't call delay routine in ISR routine then is my code wrong ? and then how to phase shift delay without delay routine ?you helped me a lot and thnks a lot fot that.
 
As motion said, you need to interrupt at 6 times your frequency. 6*50Hz = 300Hz. You need to set your timer so it interrupts every 3.3mS. You then set the outputs from values that are in a table.

Alternatively, you can rotate a variable to generate the necessary outputs.

Code:
; initialise the variable to have 3 bits set.
                movlw   b'00111000'
                movwf   Phase

; in your ISR rotate the variable like this.
                rrf     Phase,F
                bcf     Phase,7
                btfsc   STATUS,C
                bsf     Phase,5

After the above shift, bit 5 will be the red phase, bit 3 will be blue and bit 1 will be yellow.

HTH

Mike.
 
thank you sir,
i tried whatever you told its working now problem is that for next 3 second i want just reverse that of first according to your sugg. pins 5 and 2 ,pins 4 and 1, pins 3 and 0 was exactely reverse can i use the same data meance can i use pin 2 values for pin 5 to get reverse of first.
pls help me thank you.
 
how to give deadband

thank you sir for replying me ,
actually when i swaped two phases like i'm using portd 5,4,3,2,1,0 pins and for that 5 is red ,3 is blue and 1 yellow and 2 is compliment of 5, 0 is of 3 and 4 is of 1 now when i want reverse motivation of motor then i want pulse of 2 on 5 and 0 on 3 and 4 on 1 and viceversa in first cycle we were passing 00111000 and for 6 intrruption cycle pulse was coming correctely but for next reverse cycle when i swap 2 phases then i've to pass 00110010 isn't it but for that pulses was not coming correctely and duty cycle was not 50% then what i done is i've taken the values for 6 intruption and swap these values for the respective pins by updating a flag and its giving the results but is this a right way and one more thing is that now i want to give 5microsecond delay in between top and bottom meance in between R and ~R , y and ~y , b and ~b how can it be possible waiting for reply thank you.
 
Re: how to give deadband

esconele said:
thank you sir for replying me ,
actually when i swaped two phases like i'm using portd 5,4,3,2,1,0 pins and for that 5 is red ,3 is blue and 1 yellow and 2 is compliment of 5, 0 is of 3 and 4 is of 1 now when i want reverse motivation of motor then i want pulse of 2 on 5 and 0 on 3 and 4 on 1 and viceversa in first cycle we were passing 00111000 and for 6 intrruption cycle pulse was coming correctely but for next reverse cycle when i swap 2 phases then i've to pass 00110010 isn't it but for that pulses was not coming correctely and duty cycle was not 50% then what i done is i've taken the values for 6 intruption and swap these values for the respective pins by updating a flag and its giving the results but is this a right way and one more thing is that now i want to give 5microsecond delay in between top and bottom meance in between R and ~R , y and ~y , b and ~b how can it be possible waiting for reply thank you.
Code:
;******************************************************************************************************
;PROJECT NAME::ARD INVERTER
; FILENAME:1912.asm(main)
; RELETED FILES:BCD.asm,p2plsp18.lkr
;3-PHASE 50Hz SUPPLY TO PORT  D WITH 120 DEG. PHASE SHIFT 
;PORTD.5-R,PORTD.2- ~R
;PORTD.3-B,PORTD.0- ~B
;PORTD.1-Y,PORTD.4- ~Y
;FOR FIRST 3 SEC MOTOR SHOULD RUN IN ONE DIRECTION 
;AFTER 1 SEC HALT AGAIN FOR NEXT 3-SEC MOTOR SHOULD RUN IN REVERSE DIRECTION
;IN BETWEEN THIS CHECK THE VTG OF EACH DIRECTION WITH ADC
;COMPARE THE VTGS OF 2 MODES RUN THAT MODE WHICH HAS LOW VTG CONTINUOUSLY
;DATE:21/12/05    
;******************************************************************************************************
;	list P = 18C452
	#include "P18F452.inc"
;*******************************
; DECLARATION OF REGISTERS
;*******************************

TENMSH EQU 50
TENMSL EQU 243
RED EQU B'10101010'
phase equ B'00111000'
revphase equ B'00000111'
F     EQU      0x0001
VARIEBALS UDATA
COUNT1   RES 1
COUNT2   RES 1
T2       RES 1
t1       RES 1  
#define	_C	STATUS,0

	
;********************************
		
	org 0x000000

	goto START
	org 0x000008
	bra INT0ISR	
	org 0x00000526
START
         

	rcall    INIT
	bsf	RCON,IPEN	;enable priority interrupts.
	bSf	INTCON,GIEH	;set the global interrupt enable bits
	bSf	INTCON,GIEL	;	"
	BSF INTCON,INT0IE
	BCF INTCON,INT0IF	;SET INT0 INTRUPT ON LOW EDGE 
	BCF INTCON2,INTEDG0

	btfsc PORTC,6
rt1:
	bra $-2
rt2:
	rcall sample 
	rcall DELAY3sec

	rcall DELAY1sec

	rcall sample1
	
	rcall DELAYrev3sec

	rcall DELAY1sec
loop0
	rcall VOLTAGE_C

	GOTO loop0
;***********************************
INIT:
	setf	PORTD
	setf    LATD				;setup portd for outputs
	movlw   0x00
	movwf	TRISD
	setf	PORTC				;setup portc for outputs
	setf	LATC
	movlw   0x00
	movwf 	TRISC
	setf	PORTB
	setf    LATB				;setup portd for outputs
	movlw   0x00
	movwf	TRISB
	clrf t1
	MOVLW 0X04
	MOVWF T2
	return
INT0ISR
	setf PORTD
	SETF LATD
	clrf TRISD
	bcf PORTC,6
	retfie
;****************************************
;INTIALISATION OF PORT PINS IN NORMAL MODE
;****************************************
sample:
	BCF PORTC,7
	clrf LATD
	clrf PORTD
	clrf TRISD
	movlw phase
	movwf PORTD

	return

;***********************************
;PORT PINS IN REVERSE MODE
;***********************************
sample1:
	clrf LATD
	clrf PORTD
	clrf TRISD
	movlw revphase
	movwf PORTD

	return

;***********************************************
delay5us:
	bcf	PIR2,TMR3IF	    ;Clear the TMR3 interrupt flag.
	movlw	0xFF		;Load TMR3 with the value 0xF000
	movwf	TMR3H
	movlw  0xFC		
	movwf	TMR3L
	bSf	T3CON,TMR3ON	;Clear the Timer3 interrupt flag again.
T3POLL
	btfss	PIR2,TMR3IF	;Poll TMR3 interrupt flag to wait for another TMR3 overflow.
	bra	T3POLL
	bcf	T3CON,TMR3ON	;Clear the Timer3 interrupt flag again.
	bcf	PIR2,TMR3IF	    ;Clear the Timer3 interrupt flag again.
	return

;*****************************************
DELAY1sec:
	bcf	PIR2,TMR3IF	        ;Clear the TMR3 interrupt flag.
	movlw D'255'
	movwf COUNT1
	MOVLW 0X06
	MOVWF COUNT2
sec1:	movlw	0xF2		;Load TMR3 with the value 0xF2FA
	movwf	TMR3H
	movlw  0xFA		
	movwf	TMR3L
	bSf	T3CON,TMR3ON	    ;Clear the Timer3 interrupt flag again.
T3POLL1
	btfss	PIR2,TMR3IF	    ;Poll TMR3 interrupt flag to wait for another TMR3 overflow.
	bra	T3POLL1
	bcf	T3CON,TMR3ON    	;Clear the Timer3 interrupt flag again.
	bcf	PIR2,TMR3IF	        ;Clear the Timer3 interrupt flag again.		
	decfsz COUNT1,1
	goto sec1
	decfsz COUNT2,1
	GOTO 	sec1

	return
;************************************************
;DELAY FOR WHICH TWO MODES SHOULD BE RUN
;************************************************
DELAY3sec:
	bcf	PIR2,TMR3IF	        ;Clear the TMR3 interrupt flag.
	movlw D'200'
	movwf COUNT1
	MOVLW 0X02
	MOVWF	COUNT2
sec3:	movlw	0xD8		;Load TMR3 with the value 0xD8F0
	movwf	TMR3H
	movlw  0xF0		
	movwf	TMR3L
	bSf	T3CON,TMR3ON     	;Clear the Timer3 interrupt flag again.
T3POLL3
	btfss	PIR2,TMR3IF	    ;Poll TMR3 interrupt flag to wait for another TMR3 overflow.
	bra	T3POLL3

	rcall TENMS

	rcall ADC
	bcf	PIR2,TMR3IF	        ;Clear the Timer3 interrupt flag again.	
	bcf	T3CON,TMR3ON	    ;Clear the Timer3 interrupt flag again.	
	decfsz COUNT1,1
	goto sec3
	DECFSZ COUNT2,1
	GOTO sec3
	btg PORTC,5
	movf temp_1,W
	movwf comp_0
	movf temp_3,W
	movwf comp_4
	movf temp_4,W
	movwf comp_5

	return
;**********************************************************************************
DELAYrev3sec:
	bcf	PIR2,TMR3IF	        ;Clear the TMR3 interrupt flag.
	movlw D'200'
	movwf COUNT1
	MOVLW 0x02
	MOVWF COUNT2
rsec3:	movlw	0xD8		;Load TMR3 with the value 0xD8F0
	movwf	TMR3H
	movlw  0xF0		
	movwf	TMR3L
	bSf	T3CON,TMR3ON	    ;Clear the Timer3 interrupt flag again.
T3POL3
	btfss	PIR2,TMR3IF	    ;Poll TMR3 interrupt flag to wait for another TMR3 overflow.
	bra	T3POL3

	rcall TENMSre

	rcall ADCc
	bcf	PIR2,TMR3IF	        ;Clear the Timer3 interrupt flag again.
	bcf	T3CON,TMR3ON	    ;Clear the Timer3 interrupt flag again.
	decfsz COUNT1,1
	goto rsec3
	DECFSZ COUNT2,1
	GOTO rsec3
	btg PORTC,4
	movf temp_1,W
	movwf comp_1
	movf temp_3,W
	movwf comp_2
	movf temp_4,W
	movwf comp_3
	return
;****************************************************
;5HZ FREQ ROUTINE FOR FIRST 3 SEC ONE DIRECTION
;****************************************************

TENMS
	MOVLW TENMSH
	MOVWF COUNTH
	MOVLW TENMSL
	MOVWF COUNTL
TEN1
	DECFSZ COUNTL,F	
	GOTO TEN1
	DECFSZ COUNTH,F
	GOTO TEN1
	rrcf    PORTD,F 
    bcf     PORTD,7 
    btfsc   STATUS,C 
    bsf     PORTD,5 

TENMSEND

	return
;*******************************************************
;5HZ FREQ ROUTINE FOR NEXT 3 SEC REVERSE DIRECTION
;*******************************************************
TENMSre
	MOVLW TENMSH
	MOVWF COUNTH
	MOVLW TENMSL
	MOVWF COUNTL
TEN1re
	DECFSZ COUNTL,F	
	GOTO TEN1re
	DECFSZ COUNTH,F
	GOTO TEN1re
	incf t1
	MOVLW 0X01
	CPFSGT T2
O1
	GOTO O2
O3
	rrcf    PORTD,F 
    bcf     PORTD,7 
    btfsc   STATUS,C 
    bsf     PORTD,5
	DECF T2
O2
	movlw 0x04 
	cpfseq t1
pl1
	goto l3
pl2
	movlw 0x18
	movwf PORTD
	incf t1
	CLRF T2
l3
	movlw 0x05
	cpfseq t1
l4
	goto l5
l6
	movlw 0x1c
	movwf PORTD
l5 
	movlw 0x06
	cpfseq t1
l7
	goto l8
l9
	movlw 0x0A
	movwf PORTD
	INCF t1
l8
	movlw 0x07
	cpfseq t1
l10
	goto pl10
l11
	movlw 0x0A 
	movwf PORTD
	INCF t1
pl10
	movlw 0x08
	cpfseq t1
l12
	goto l13
l14
	movlw 0x0e
	movwf PORTD
l13
	movlw 0x09
	cpfseq t1
l15
	goto l16
l17
	movlw 0x03
	movwf PORTD
	INCF t1
l16
	movlw 0x0a
	cpfseq t1
l18
	goto l19
l20
	movlw 0x03
	movwf PORTD
	INCF t1

l19
	movlw 0x0b 
	cpfseq t1
l21
	goto l22
l23
	movlw 0x07
	movwf PORTD 
	movlw 0x01
	movwf t1
	MOVLW 0X04
	MOVWF T2
l22
TENMSreEND

	RETURN

		    
     END
 
how to give deadband

hello sir,
first thank you for replying and helping me now its working but now problem is that i want to give 5microsecond delay in betwen top and bottom i.e dead band in between R and ~R and others also how i can achieve this waiting for reply thank you .
 
50hz PWM pulse

hello sir,
i'm using 18f4431 for my project for that crystal used is 4.9152Mhz and i want 0.1 to 50hz PWM can it be possible with this because we have to load value only in PR2 and calculated value for 50hz is 5fff how can i achieve this
thank you.
 
how to give deadband

hello everyone,
here i'm using 18f452 i want 6 output pulses with 50hz like R, ~R,Y,~Y ,B,~B AND 120DEGREE PHASE SHIFT IN BETWEEN R-Y-B,~R-~Y-~B AND 5MICROSECOND DEADBAND IN BETWEEN R & ~R,Y & ~Y AND B & ~B I'VE WRITTEN A CODE WHICH GIVES ME DEADBAND OF 5 MICROSEC BUT PHASE SHIFT IS ONLY 30DEGREE HOW COULD I AHEIVE 120DEGREE PHASE SHIFT AND ALL REMAINING THINGS TOGETHER ACTUALLY I TRIED WITH ROTATING PORT AND IT WAS GIVING 120 DEGREE PHASE SHIFT BUT IN THAT CASE DEADBAND WAS NOT POSSIBLE AND DEADBAND IS MUST PLS HELP ME .
THANK YOU

Code:
#include "p18f452.inc" 

;------------------BIT DEFINITIONS------------------------------------ 

F EQU 0x0001 
;COUNT1 EQU 200 
;COUNT2 EQU 0x0003 
;COUNT3 EQU 0x0004 
red equ B'00101010' 
green equ B'01010101' 
var UDATA 
COUNT1 res 1 
COUNT2 res 1 
COUNT3 res 1 
COUNT4 res 1 
temp_1 res 1 
temp_2 res 1 
temp_3 res 1 
;------------------VECTORS-------------------------------------------- 

org 0x000000 ; reset vector 
bra START 

org 0x000008 ; high priority interrupt vector 
bra TMR3_ISR 


org 0x000070 
;--------------------PROGRAM----------------------------------- 
START 
rcall INIT 

;Set up priority interrupts. 
bsf RCON,IPEN ;enable priority interrupts. 

bsf IPR2,TMR3IP ;set Timer3 as a high priority interrupt source 

bcf PIR2,TMR3IF ;clear the Timer3 interrupt flag 

bsf PIE2,TMR3IE ;enable Timer3 interrupts 
bsf INTCON,GIEH ;set the global interrupt enable bits 
bsf INTCON,GIEL ; " 

MOVLW 0X02 
MOVWF temp_1 





clrf T3CON 

movlw 0xd0 
movwf TMR3H ;write 0xd000 to Timer3 
clrf TMR3L 
movlw 0x01 
movwf COUNT4 
bsf T3CON,TMR3ON ;turn on Timer3 
MLOOP 

goto MLOOP 

;-------------------------------SUBROUTINES--------------------------------- 



TMR3_ISR ;high priority isr 

CPFSEQ COUNT4 
LP1 goto lpl 
LP2 
BTG PORTD,5
nop
nop
nop
nop
nop 
BTG PORTD,2 

incf COUNT4 
MOVLW 0X02 


CPFSEQ COUNT4 

LPP1 
goto lpl 
LPP2 

incf COUNT4 
GOTO LP3 
LP3 
BTG PORTD,1
nop
nop
nop
nop
nop 
BTG PORTD,4 



movlw 0x03 
cpfseq COUNT4 

lp4 
  bra lpl 

lp5 
btg PORTD,3
nop
nop
nop
nop
nop 
btg PORTD,0 
decf COUNT4 
decf COUNT4 

lp6 
  movlw 0xd0 
  movwf TMR3H 
clrf TMR3L 

lpl 
retfie 


INIT 
clrf PORTD
clrf LATD 
clrf TRISD 
movlw red 
movwf LATD 

return 



END
 
Re: how to give deadband

esconele said:
hello everyone,

Code:
TMR3_ISR ;high priority isr 

CPFSEQ COUNT4 
LP1 goto lpl

Your code is very hard to follow, the code above seems to have a goto itself instruction. You should repost your code using the code tag. You should also ensure that the code that you post is case readable. I.E. if you have goto lp1, you should not have a similar label called lpl.

Mike.
 
PHASE SHIFT OF 120

HELLO,
HERE I'VE POSTED MY CODE PLS GIVE ME THE CLUE HOW TO GIVE 120 DEGREE PHASE SHIFT IN BETWEEN R-Y-B AND 5microsec DEAD BAND IN BETWEEN R - ~R ,Y - ~Y,B - ~B WITH 50HZ FREQ ON EACH OUTPUT PIN
THANK YOU
Code:
#include "p18f452.inc" 

;------------------BIT DEFINITIONS------------------------------------ 

F EQU 0x0001 

red equ B'00101010' 

var    UDATA 
COUNT1 res 1 
COUNT2 res 1 
COUNT3 res 1 
COUNT4 res 1 
temp_1 res 1 
temp_2 res 1 
temp_3 res 1 
;------------------VECTORS-------------------------------------------- 

org 0x000000 ; reset vector 
bra START 

org 0x000008 ; high priority interrupt vector 
bra TMR3_ISR 


org 0x000070 
;--------------------PROGRAM----------------------------------- 
START 
rcall INIT 

;Set up priority interrupts. 
bsf RCON,IPEN 		;enable priority interrupts. 

bsf IPR2,TMR3IP 	;set Timer3 as a high priority interrupt source 

bcf PIR2,TMR3IF 	;clear the Timer3 interrupt flag 

bsf PIE2,TMR3IE 	;enable Timer3 interrupts 
bsf INTCON,GIEH 	;set the global interrupt enable bits 
bsf INTCON,GIEL  

MOVLW 0X02 
MOVWF temp_1 

clrf T3CON 

movlw 0xd0 
movwf TMR3H 		;write 0xd000 to Timer3 
clrf TMR3L 

movlw 0x01 
movwf COUNT4 

bsf T3CON,TMR3ON 	;turn on Timer3 

MLOOP 
      goto MLOOP 

;-------------------------------SUBROUTINES--------------------------------- 



TMR3_ISR ;high priority isr 

CPFSEQ COUNT4 
LP1: 
	goto LPLAST 
LP2: 
	BTG PORTD,5 	;toggle R
	nop 		;5microsec delay		
	nop 
	nop 
	nop 
	nop 
	BTG PORTD,2  ;toggle ~R 

	incf COUNT4 
	MOVLW 0X02 

	CPFSEQ COUNT4 

LPP1: 
	goto LPLAST
 
LPP2: 

	incf COUNT4 

	GOTO LP3 
LP3: 
	BTG PORTD,1 	;toggle Y
	nop 		;5micros delay	
	nop 
	nop 
	nop 
	nop 
	BTG PORTD,4 	;toggle ~Y

	movlw 0x03 
	cpfseq COUNT4 

LP4:
	bra LPLAST 

LP5: 
	btg PORTD,3 	;TOGGLE B 
	nop 		;5micros delay
	nop 
	nop 
	nop 
	nop 
	btg PORTD,0 	;TOGGLE ~B

	decf COUNT4 
	decf COUNT4 

LP6: 
	movlw 0xd0 
  	movwf TMR3H 
  	clrf TMR3L 

LPLAST: 
	retfie 

;initialisation of portd
INIT 
	clrf PORTD 
	clrf LATD 
	clrf TRISD 
	movlw red 
	movwf LATD 

return 

END
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top