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.

AC Motors 7.5KW driving with VFD methods using PIC18F46K22 and IR21362

Status
Not open for further replies.
It is not easy for me to provide a complete circuit,I normally use Proteus for schematics drawing but in proteus there is nor IR21362,so I could later tomorrow provide a circuit of PIC and few possible additional components.
The IR21362 when reading its datasheet it normally provide a deadtime,the PIC output voltage is of 0.2V to 2.087V(because the potentiometer on RA0 helps in adjusting the voltage and frequency) at once so that we get V/F constant.
why do we need a driver having more rating than 600V?What are the capabilities of HCPL316 in advancement to the IR21362?could you refer to https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en012011 of AN843 of microcchip it uses this driver for driving a three phase induction motor.
for HCPL316 ,it is not easy to get a DIP type when trying to search I found only SMD types which I can not handle in my circuit.!!

Find my codes here below

PHP:
;----------------------------------------------------------------
	include		<p18F46K22.inc>
	include		<3im_vf.inc>
;----------------------------------------------------------------
; CONFIG1H
  CONFIG  FOSC = HSHP           ; Oscillator Selection bits (HS oscillator (high power > 16 MHz))
  CONFIG  PLLCFG = OFF          ; 4X PLL Enable (Oscillator used directly)
  CONFIG  PRICLKEN = ON         ; Primary clock enable bit (Primary clock is always enabled)
  CONFIG  FCMEN = ON            ; Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
  CONFIG  IESO = ON             ; Internal/External Oscillator Switchover bit (Oscillator Switchover mode enabled)

; CONFIG2L
  CONFIG  PWRTEN = OFF          ; Power-up Timer Enable bit (Power up timer disabled)
  CONFIG  BOREN = SBORDIS       ; Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
  CONFIG  BORV = 190            ; Brown Out Reset Voltage bits (VBOR set to 1.90 V nominal)

; CONFIG2H
  CONFIG  WDTEN = OFF           ; Watchdog Timer Enable bits (Watch dog timer is always disabled. SWDTEN has no effect.)
  CONFIG  WDTPS = 32768         ; Watchdog Timer Postscale Select bits (1:32768)

; CONFIG3H
  CONFIG  CCP2MX = PORTC1       ; CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
  CONFIG  PBADEN = OFF          ; PORTB A/D Enable bit (PORTB<5:0> pins are configured as digital I/O on Reset)
  CONFIG  CCP3MX = PORTB5       ; P3A/CCP3 Mux bit (P3A/CCP3 input/output is multiplexed with RB5)
  CONFIG  HFOFST = ON           ; HFINTOSC Fast Start-up (HFINTOSC output and ready status are not delayed by the oscillator stable status)
  CONFIG  T3CMX = PORTC0        ; Timer3 Clock input mux bit (T3CKI is on RC0)
  CONFIG  P2BMX = PORTD2        ; ECCP2 B output mux bit (P2B is on RD2)
  CONFIG  MCLRE = EXTMCLR       ; MCLR Pin Enable bit (MCLR pin enabled, RE3 input pin disabled)

; CONFIG4L
  CONFIG  STVREN = ON           ; Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
  CONFIG  LVP = ON              ; Single-Supply ICSP Enable bit (Single-Supply ICSP enabled if MCLRE is also 1)
  CONFIG  XINST = OFF           ; Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

; CONFIG5L
  CONFIG  CP0 = OFF             ; Code Protection Block 0 (Block 0 (000800-003FFFh) not code-protected)
  CONFIG  CP1 = OFF             ; Code Protection Block 1 (Block 1 (004000-007FFFh) not code-protected)
  CONFIG  CP2 = OFF             ; Code Protection Block 2 (Block 2 (008000-00BFFFh) not code-protected)
  CONFIG  CP3 = OFF             ; Code Protection Block 3 (Block 3 (00C000-00FFFFh) not code-protected)

; CONFIG5H
  CONFIG  CPB = OFF             ; Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
  CONFIG  CPD = OFF             ; Data EEPROM Code Protection bit (Data EEPROM not code-protected)

; CONFIG6L
  CONFIG  WRT0 = OFF            ; Write Protection Block 0 (Block 0 (000800-003FFFh) not write-protected)
  CONFIG  WRT1 = OFF            ; Write Protection Block 1 (Block 1 (004000-007FFFh) not write-protected)
  CONFIG  WRT2 = OFF            ; Write Protection Block 2 (Block 2 (008000-00BFFFh) not write-protected)
  CONFIG  WRT3 = OFF            ; Write Protection Block 3 (Block 3 (00C000-00FFFFh) not write-protected)

; CONFIG6H
  CONFIG  WRTC = OFF            ; Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
  CONFIG  WRTB = OFF            ; Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
  CONFIG  WRTD = OFF            ; Data EEPROM Write Protection bit (Data EEPROM not write-protected)

; CONFIG7L
  CONFIG  EBTR0 = OFF           ; Table Read Protection Block 0 (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
  CONFIG  EBTR1 = OFF           ; Table Read Protection Block 1 (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
  CONFIG  EBTR2 = OFF           ; Table Read Protection Block 2 (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
  CONFIG  EBTR3 = OFF           ; Table Read Protection Block 3 (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks)

; CONFIG7H
  CONFIG  EBTRB = OFF           ; Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)


;----------------------------------------------------------------------
#define TIMER0_OV_FLAG	0
#define OFFSET1_FLAG	4
#define OFFSET2_FLAG	5
#define OFFSET3_FLAG	6

#define	MOTOR_DIRECTION	7
#define MOTOR_RUNNING	1
#define	DEBOUNCE	0
#define	ON_OFF_FLAG	1
#define	DELAY_COUNT1	0xFF
#define	DELAY_COUNT2	0xFF
;===============================================================
;RAM locations in Access bank, uninitialized
	UDATA_ACS 	
TABLE_OFFSET1	res	1		;Phase1 offset to the Sine table(0)
TABLE_OFFSET2	res	1		;Phase2 offset to the Sine table(120)
TABLE_OFFSET3	res	1		;Phase3 offset to the Sine table(240)

COUNTER		res	1		;General counters
COUNTER1	res	1
FLAGS			res	1		;Flags registers used to indicate different status
FLAGS1			res	1
FREQ_REF_H	res	1			;Referance Frequency input in counts
FREQ_REF_L	res	1
FREQUENCY	res	1

CCPR1L_TEMP	res	1			;Temporary locations
CCPR2L_TEMP	res	1
CCPR3L_TEMP RES 1
PWM_DUTYCYCLE RES 1

TEMP			res	1
TEMP1		res	1
TEMP_LOCATION	res	2
SINE_TABLE	res	0x14			;Sine table
;----------------------------------------------------------------
STARTUP	code 0x00
	goto	Start		;Reset Vector address 
	
	CODE	0x08
	goto	ISR_HIGH	;Higher priority ISR at 0x0008

PRG_LOW	CODE	0x018
	goto	ISR_LOW		;Lower priority ISR at 0x0018

;****************************************************************
PROG1	code
Start
;****************************************************************
;Initialization of the Ports and timers
	clrf	FLAGS				;Clear the flags
	clrf	TRISC				;PORTC all output
	clrf	PORTC
	CLRF   TRISA
	CLRF    PORTA
;	BSF  TRISD,0
	BANKSEL TRISB
	BSF TRISB,0
	BSF,TRISB,1
	BSF TRISB,2
	
	CLRF PORTD

;	clrf	TRISB				;PORTB all output
;	clrf	PORTB
;	MOVLW 0X0F
	
;	MOVWF PORTB
;	MOVWF TRISB




	movlw 0x0F
	BANKSEL TRISB
	movf TRISB
	BSF TRISB,RUN_STOP_KEY
	BSF PORTB,FWD_REV_KEY
	BSF PORTB,FAULT_BIT
		
	CLRF ECCP1AS
	CLRF ECCP2AS
	CLRF ECCP3AS
	BSF TRISD,RUN_STOP_KEY

	bsf	TRISB,FAULT_BIT		;Fault input from driver
	movlw	0x0C
	movwf	CCP1CON			;CCP1 and CCP2 configured to PWM
	movwf	CCP2CON
	BANKSEL CCP3CON
	movwf CCP3CON
;	MOVLW 0x10
;	MOVWF PSTR1CON
;	MOVWF PSTR2CON
;	MOVWF PSTR3CON
;	MOVLW 0X80
;	MOVWF PWM1CON
;	MOVWF PWM2CON
;	MOVWF PWM3CON
	MOVLW 0X00
	MOVWF CCPTMRS0 
	bsf	T2CON,2			;Timer2 ON
	movlw	PR2_VALUE			;Load PR2 value to PR2 register
	movwf	PR2
	movlw	0x90				
	movwf	CCPR1L
	movwf	CCPR2L
	BANKSEL  CCPR3L
	MOVWF CCPR3L
	movlw	0x81			;Timer1 prescaler 1:2
	movwf	T1CON
	call	Init_Motor_Parameters	;Initialize motor parameters
	call	COPY_TABLE_TO_RAM		
;******************************************************************
;Initialize ADC registers
	movlw	ADCON0_VALUE	;From ".inc" file
	movwf	ADCON0
	movlw	ADCON1_VALUE	;From ".inc" file
	movwf	ADCON1
	movlw	0x33		;RA0,RA4,RA5 inputs,RA2&RA3-Outputs
	movwf	TRISA	;	
;	bsf	DRIVER_ENABLE_PORT,DRIVER_ENABLE_BIT	;Enable the driver chip

;******************************************************************
;Timre0 Initialization with prescaler
;******************************************************************
	movlw	0X83		;Load the T0CON with value
	movwf	T0CON		;TMR0 ON and prescalar is 1:16
	movlw	0xF8		;Timer0 Initialisation 
	movwf	TMR0H
	movlw	0x5E	;
	movwf	TMR0L	

;---------------------------------------
	bsf	INTCON,TMR0IE	;Timer0 overflow Interrupt enable
	bsf	PIE1,TMR2IE	;"Timer2 to PR2 match" Interrupt enable
	bsf	PIE1,TMR1IE	;Timer1 overflow Interrupt enable
	bsf	PIE1,ADIE	;AD Converter over Interrupt enable
	bcf	IPR1,ADIP	;Low priority for ADC interrupt
	bsf	INTCON,RBIE	;PortB interrupt enable with low priority
	bcf	INTCON2,RBIP	;for Fault checking
	movlw	0x093		;Power ON reset status bit/Brownout reset status bit
	movwf	RCON		;and Instruction flag bits are set
			        	;Priority level on Interrupots enabled
	bsf	INTCON,PEIE	;Port interrupts enable
	bsf	INTCON,GIE	;Global interrupt enable
;******************************************************************
;Main loop where the program will be looping
MAIN_LOOP
	btfss	FLAGS,TIMER0_OV_FLAG		;back from Timer0 overflow?
	bra	bypass			            	;No
	call	UPDATE_PWM_DUTYCYCLES		;Yes, update the PWM duty cycle with new value
	call	UPDATE_TABLE_OFFSET		;Update 3 offsets
	bcf	FLAGS,TIMER0_OV_FLAG		;Clear the flag
bypass
	call	SET_ADC_GO				;Start AD conversion
	call	KEY_CHECK				;Check keys change
	bra	MAIN_LOOP
;******************************************************************
;Higher priority interrupt service routine
;"Timer2 to PR2 match", "Timer1 overflow" and Timer0 overflow are checked
;******************************************************************
ISR_HIGH
	btfsc	PIR1,TMR2IF			;Timer2 to PR2 match?	
	bra	TIMER2_PR2_Match		
;	btfsc	PIR1,TMR1IF			;Timer1 overflow Interrupt?	
;	bra	TIMER1_OVERFLOW
	btfsc	INTCON,TMR0IF		;Timer0 overflow Interrupt?	
	bra	TIMER0_OVERFLOW		;Yes
	RETFIE	FAST

;******************************************************************
;///////////////////////////////////////////////////////////////////
;MODIFIED BY MYSELF FOR REMOVING TIMER 2 NOT USED FOR PWM GENERATION
;//////////////////////////////////////////////////////////////////
TIMER2_PR2_Match
	bcf	PIR1,TMR2IF		;
;	tstfsz CCPR3L_TEMP  ;If Software PWM duty cycle=0, then 
	tstfsz CCPR3L
	bra	PWM3_NOT_0		;no need to set the PWM3 port pin
	RETFIE	FAST
PWM3_NOT_0
	movlw	0xFF			;Higher byte of Timer1 loaded with FFh
	movwf	TMR1H
	movff	CCPR3L_TEMP,TMR1L
	RETFIE	FAST
;///////////////////////////////////////////////////////////////////
;MODIFIED BY MYSELF FOR REMOVING TIMER 2 NOT USED FOR PWM GENERATION
;//////////////////////////////////////////////////////////////////
;******************************************************************
;TIMER1_OVERFLOW
;	bcf	PWM3_PORT,PWM3_PORT_PIN	;PWM3 pin cleared after the duty cycle time expires
;	BCF PORTB,5
;	bcf	PIR1,TMR1IF	
;	RETFIE	FAST

;******************************************************************
TIMER0_OVERFLOW				;TMR0 overflow ISR
	movff	FREQ_REF_H,TMR0H	;Load the Higher byte of SpeedCommand to TMR0H
	movff	FREQ_REF_L,TMR0L	;Load the Lower byte of SpeedCommand to TMR0L	
	bsf	FLAGS,TIMER0_OV_FLAG
	bcf	INTCON,TMR0IF	;Clear TMR0IF	
	RETFIE	FAST	
;******************************************************************
;Lower priority interrupt service routine
;Change on PortB(Fault checking) interrupt & "ADConversion over" interrupt are checked
;******************************************************************
ISR_LOW
	btfsc	INTCON,RBIF			;RB interrupt?	
	bra	CHECK_FAULT			;Yes
	btfsc	PIR1,ADIF
	bra	AD_CONV_COMPLETE
	RETFIE	FAST
;******************************************************************
CHECK_FAULT
	movf	PORTB,W			;Check for fault bit
	btfss	WREG,FAULT_BIT
	bra	THERE_IS_FAULT	
	call	RUN_MOTOR_AGAIN		;Fault cleared?
	bcf	INTCON,RBIF			;Run motor again
	RETFIE	FAST
THERE_IS_FAULT				;Yes,fault is there
	call	STOP_MOTOR			;Stop motor
	bcf	INTCON,RBIF	
	RETFIE	FAST
;******************************************************************
AD_CONV_COMPLETE			;ADC interrupt
	movff	ADRESH,FREQUENCY 
	movlw	0x14			;Minimum Frequency set to 5Hz (scaling factor X4) 
	cpfsgt	FREQUENCY
	movwf	FREQUENCY
	movlw	0xF0			;Limiting V/F to F= 60Hz (scaling factor X4) 
	cpfslt	FREQUENCY
	movwf	FREQUENCY
	movwf	PORTD			;Out frequency to PORTD for set value
	bcf	PIR1,ADIF		;ADIF flag is cleared for next interrupt
	RETFIE	FAST		

;*************************************************************************
;This routine will update the PWM duty cycle on CCPx according to the 
;offset to the table with 0-120-240 degrees.
;This routine scales the PWM value from the table based on the frequency to keep V/F
;constant.
;*************************************************************************
UPDATE_PWM_DUTYCYCLES
	movf	TABLE_OFFSET1,W
	movf	PLUSW0,W
	bz	PWM1_IS_0
	mulwf	FREQUENCY			;Table_value X Frequency
	movff	PRODH,CCPR1L_TEMP
	bra	UPDATE_PWM2
PWM1_IS_0
	clrf	CCPR1L_TEMP			;Clear the PWM duty cycle register
	bcf	CCP1CON,4	
	bcf	CCP1CON,5

UPDATE_PWM2
	movf	TABLE_OFFSET2,W
	movf	PLUSW0,W
	bz	PWM2_IS_0
	mulwf	FREQUENCY		;Table_value X Frequency
	movff	PRODH,CCPR2L_TEMP
	bra	UPDATE_PWM3
PWM2_IS_0
	clrf	CCPR2L_TEMP			;Clear the PWM duty cycle register
	bcf	CCP2CON,4	
	bcf	CCP2CON,5	
UPDATE_PWM3
	movf	TABLE_OFFSET3,W
	movf	PLUSW0,W
	bz	PWM3_IS_0
	mulwf	FREQUENCY		;Table_value X Frequency
	movff	PRODH,CCPR3L_TEMP
	 bra  SET_PWM12
PWM3_IS_0
	clrf	CCPR3L_TEMP			;Clear the PWM duty cycle register
	bcf	CCP2CON,4	
	bcf	CCP2CON,5
;//////////////////////////////////////////////////////
;ABOVE WERE MODIFIED BY MYSELF
;//////////////////////////////////////////////////////
SET_PWM12
	btfss	FLAGS,MOTOR_DIRECTION  
	bra	ROTATE_REVERSE
	movff	CCPR1L_TEMP,CCPR1L
	movff	CCPR2L_TEMP,CCPR2L
	BANKSEL CCPR3L
	movff CCPR3L_TEMP,CCPR3L
;	movff CCPR3L_TEMP,PWM_DUTYCYCLE
;	movff PWM_DUTYCYCLE,CCPR3L

	bsf	PORT_LED1,LED1
	return	
;////////////////////////////////////////////
;/DEACTIVATE TWO DIRECTION OPERATION BY MYSELF
;////////////////////////////////////////////
ROTATE_REVERSE
	movff	CCPR2L_TEMP,CCPR1L
	movff	CCPR1L_TEMP,CCPR2L
	movff CCPR3L_TEMP,PWM_DUTYCYCLE
	MOVFF PWM_DUTYCYCLE,CCPR3L
	bcf	PORT_LED1,LED1
	return	
;*******************************************************************************
;This routine Updates the offset pointers to the table after every access
;*******************************************************************************
UPDATE_TABLE_OFFSET
	btfss	FLAGS,OFFSET1_FLAG	;If set incr. on table
	bra	DECREMENT_OFFSET1
	movlw	(SINE_TABLE_ENTRIES-1)	;Check for the last value on the table
	cpfslt	TABLE_OFFSET1
	bra	CLEAR_OFFSET1_FLAG
	incf	TABLE_OFFSET1,F		;Increment offset1
	bra	UPDATE_OFFSET2
CLEAR_OFFSET1_FLAG
	bcf	FLAGS,OFFSET1_FLAG
DECREMENT_OFFSET1
	dcfsnz	TABLE_OFFSET1,F		;Decrement offset1
	bsf	FLAGS,OFFSET1_FLAG

UPDATE_OFFSET2
	btfss	FLAGS,OFFSET2_FLAG	;If set incr. on table
	bra	DECREMENT_OFFSET2
	movlw	(SINE_TABLE_ENTRIES-1)	;Check for the last value on the table
	cpfslt	TABLE_OFFSET2
	bra	CLEAR_OFFSET2_FLAG
	incf	TABLE_OFFSET2,F		;Increment offset2
	bra	UPDATE_OFFSET3
CLEAR_OFFSET2_FLAG
	bcf	FLAGS,OFFSET2_FLAG
DECREMENT_OFFSET2
	dcfsnz	TABLE_OFFSET2,F		;Decrement offset2
	bsf	FLAGS,OFFSET2_FLAG

UPDATE_OFFSET3
	btfss	FLAGS,OFFSET3_FLAG	;If set incr. on table
	bra	DECREMENT_OFFSET3
	movlw	(SINE_TABLE_ENTRIES-1)	;Check for the last value on the table
	cpfslt	TABLE_OFFSET3
	bra	CLEAR_OFFSET3_FLAG
	incf	TABLE_OFFSET3,F		;Increment offset3
	return	
CLEAR_OFFSET3_FLAG
	bcf	FLAGS,OFFSET3_FLAG
DECREMENT_OFFSET3
	dcfsnz	TABLE_OFFSET3,F		;Decrement offset3
	bsf	FLAGS,OFFSET3_FLAG
	return	
;*******************************************************************************
;This routine calculates the Timer0 reload value based on ADC read value and the 
;scaling factor calculated based on the main clock and number of Sine table entries.
;Timer0 value = FFFF - (FREQUENCY_SCALE/Frequency)	Frequ = (adc result)
;*******************************************************************************
CALCULATE_FREQUENCY
	movff	FREQUENCY,PORTD
	clrf	TEMP
	clrf	TEMP1
	movlw	HIGH(FREQUENCY_SCALE)	;FREQUENCY_SCALE/Frequency
	movwf	TEMP_LOCATION		;16 bit by 8 bit division	     	
	movlw	LOW(FREQUENCY_SCALE)	;
	movwf	TEMP_LOCATION+1
continue_subtraction
	bsf	STATUS,C
	movf	FREQUENCY,W
	subwfb	TEMP_LOCATION+1,F
	clrf	WREG
	subwfb	TEMP_LOCATION,F
	btfss	STATUS,C
	goto	keep_result_in_rpm	
	incf	TEMP,F
	btfsc	STATUS,C		;Result of the division is stored in TEMP&TEMP1
	incf	TEMP1,F
	goto	continue_subtraction	
keep_result_in_rpm	
	;Timer0 value = FFFF-Timer0 
	bsf	STATUS,C
	movlw	0xFF
	subfwb	TEMP,F
	subfwb	TEMP1,F			;The Timer0 reload value stored in 
	movff	TEMP1,FREQ_REF_H	;FREQ_REF_H & FREQ_REF_L 
	movff	TEMP,FREQ_REF_L		;These values will be loaded to
	return				;Timer0 in Timer0 overflow interrupt		
;*******************************************************************************
;This routine sets the ADC GO bit high after an aquisition time of 20uS approx. 
;*******************************************************************************
SET_ADC_GO
	call	CALCULATE_FREQUENCY
	btfss	ADCON0,GO	
	bsf	ADCON0,GO	;Set GO bit for ADC conversion start	
	return	
;*******************************************************************************
;This routine initializes the parameters required for motor initialization.
;*******************************************************************************
Init_Motor_Parameters
	clrf	CCPR1L			;Initialize all duty cycles to 0
	clrf	CCPR2L
	CLRF    CCPR3L
	movlw	0x09			;Initialize the table offset to 3 registers
	movwf	TABLE_OFFSET1		;to form 0-120-240 degrees
	movlw	0x03
	movwf	TABLE_OFFSET2
	movlw	0x0F
	movwf	TABLE_OFFSET3
	bsf	FLAGS,OFFSET1_FLAG	;Offset flags initialization
	bcf	FLAGS,OFFSET2_FLAG
	bcf	FLAGS,OFFSET3_FLAG

	movlw	0x30			;Initialize frequency to 12Hz
	movwf	FREQUENCY
	movlw	0xFD			;Timer0 Initialisation 
	movwf	FREQ_REF_H
	movwf	TMR0H
	movlw	0x2C	;
	movwf	TMR0L	
	movwf	FREQ_REF_L
	bsf	FLAGS,TIMER0_OV_FLAG	
	return

;*******************************************************************************
;Upon initialization the Sine table contents are copied to the RAM from 
;Program memory 
;*******************************************************************************
COPY_TABLE_TO_RAM
	movlw	UPPER sine_table	;Initialize Table pointer to the first  
	movwf	TBLPTRU			;location of the table
	movlw	HIGH sine_table
	movwf	TBLPTRH
	movlw	LOW sine_table
	movwf	TBLPTRL
	movlw	LOW(SINE_TABLE)
	movwf	FSR0L
	movlw	HIGH(SINE_TABLE)
	movwf	FSR0H
	movlw	0x14
	movwf	TEMP
COPY_AGAIN
	TBLRD*+
	movff	TABLAT,POSTINC0
	decfsz	TEMP,F
	bra	COPY_AGAIN

	movlw	LOW(SINE_TABLE)		;FSR0 points to the starting of the table
	movwf	FSR0L
	movlw	HIGH(SINE_TABLE)
	movwf	FSR0H
	return		

;*******************************************************************************
;This routine checks for the keys status. 2 keys are checked, Run/Stop and 
;Forward(FWD)/Reverse(REV)  
;*******************************************************************************
KEY_CHECK
	btfsc	PORTB,RUN_STOP_KEY			;Is key pressed "RUN/STOP"?
;	btfss	PORTB,RUN_STOP_KEY
	bra	KEY_IS_RUN
	bcf	PORT_LED2,LED2
	call	STOP_MOTOR
	bsf	FLAGS,MOTOR_RUNNING
	return

KEY_IS_RUN	
	bsf	PORT_LED2,LED2
	btfss	FLAGS,MOTOR_RUNNING
	bra	CONT_RUN_KEY
	call	RUN_MOTOR_AGAIN
	bcf	FLAGS,MOTOR_RUNNING
	return
CONT_RUN_KEY
	btfsc	PORTB,FWD_REV_KEY			;Fwd/Rev key pressed?
	;btfss	PORTA,FWD_REV_KEY			;Fwd/Rev key pressed?
	bra	MOTOR_SET_FWD
	btfsc	FLAGS,MOTOR_DIRECTION	
	return
	call	STOP_MOTOR
	call	DELAY
	call	DELAY
	call	DELAY
	call	DELAY
	call	DELAY
	call	DELAY
	call	RUN_MOTOR_AGAIN
	bsf	FLAGS,MOTOR_DIRECTION
	return
MOTOR_SET_FWD
	btfss	FLAGS,MOTOR_DIRECTION	
	return
	call	STOP_MOTOR
	call	DELAY
	call	DELAY
	call	DELAY
	call	DELAY
	call	DELAY
	call	DELAY
	call	RUN_MOTOR_AGAIN
	bcf	FLAGS,MOTOR_DIRECTION
	return
;*******************************************************************************
;This routine stops the motor by driving the PWMs to 0% duty cycle.
;*******************************************************************************
STOP_MOTOR
	clrf	CCPR1L
	clrf	CCPR2L
	CLRF    CCPR3L
	clrf	TABLE_OFFSET1
	clrf	TABLE_OFFSET2
	clrf	TABLE_OFFSET3
	bcf	INTCON,TMR0IE
	bcf	PIE1,TMR2IE
	bcf	PIE1,TMR1IE
	bcf	PIE1,ADIE
	return
;*******************************************************************************
;This routine starts motor from previous stop with motor parameters initialized
;*******************************************************************************
RUN_MOTOR_AGAIN
	call	Init_Motor_Parameters
	bsf	INTCON,TMR0IE
	bsf	PIE1,TMR2IE
	bsf	PIE1,TMR1IE
	bsf	PIE1,ADIE
	return

;*******************************************************************************
;Delay routine.
;*******************************************************************************
DELAY
	movlw	DELAY_COUNT1
	movwf	COUNTER
dec_count	
	movlw	DELAY_COUNT2
	movwf	COUNTER1
dec_count1
	decfsz	COUNTER1,F
	bra	dec_count1
	decfsz	COUNTER,F
	bra	dec_count
	clrf	COUNTER
	clrf	COUNTER1
	return		
;*******************************************************************************
;Sine table for the inverter. 
;*******************************************************************************
TABLE	code 0x0100
;below table is from 270 eg. to 90 deg @ 10 deg. resolution; for 20MHz, PR2 = F9, Timer2 1:1 prescale
sine_table db	0x0,0x3,0x07,0x10,0x1B,0x28,0x38,0x4A,0x5C,0x70,0x83,0x96,0xA7,0xB7,0xC4,0xD0,0xD8,0xDD,0xDE
;*******************************************************************************
	END

an additional referential file is here
PHP:
;User defined variables
;---------------------------------------------------------------------------------------
;Oscillator frequency
#define OSCILLATOR	d'20000000'
;---------------------------------------------------------------------------------------
;Timer0 prescaler
#define	TIMER0_PRESCALE	d'16'
;---------------------------------------------------------------------------------------
;number of entries in the sine table, or the sampling frequency
#define	SINE_TABLE_ENTRIES	d'19'
;---------------------------------------------------------------------------------------
SAMPLES_PER_CYCLE = (SINE_TABLE_ENTRIES-1)*d'2'
INSTRUCTION_CYCLE = (OSCILLATOR)/d'4'
FREQUENCY_SCALE = (INSTRUCTION_CYCLE/SAMPLES_PER_CYCLE)/(TIMER0_PRESCALE/4)
;Timer prescale/4 is done to componsate ADC multiplication factor of 4 to the frequency)
;---------------------------------------------------------------------------------------
;PWM frequency definition
#define TIMER2_PRESCALE	d'01'
#define	PWM_FREQUENCY	d'20000'
PR2_VALUE = (OSCILLATOR/(4*PWM_FREQUENCY*TIMER2_PRESCALE))-1
;---------------------------------------------------------------------------------------
;ADC initialization
#define	Fosc_by_2	b'000'
#define	Fosc_by_8	b'001'
#define	Fosc_by_32	b'010'
#define	FRC		b'011'
#define	Fosc_by_4	b'100'
#define	Fosc_by_16	b'101'
#define	Fosc_by_64	b'110'

#define	ADC_CLOCK	Fosc_by_32
#define	ADC_CHANNEL	d'0'
#define	ADC_ON_BIT	b'1'
#define LEFT_JUSTIFIED
#define	ADC_PORT_CONFIG	b'1110'	;Refer the table in the manual for selection

ADCON0_VALUE = ((ADC_CLOCK<<6)|(ADC_CHANNEL<<4)|(ADC_ON_BIT))

	if ((ADC_CLOCK==Fosc_by_2)||(ADC_CLOCK ==Fosc_by_8)||(ADC_CLOCK ==Fosc_by_32)||(ADC_CLOCK==FRC))
	ifndef	LEFT_JUSTIFIED
ADCON1_VALUE = ((1<<7) | (ADC_PORT_CONFIG))
	else
ADCON1_VALUE = ADC_PORT_CONFIG
	endif
	endif
	if	((ADC_CLOCK==Fosc_by_4)||(ADC_CLOCK==Fosc_by_16)||(ADC_CLOCK==Fosc_by_64)) 	
	ifndef	LEFT_JUSTIFIED
ADCON1_VALUE = ((1<<7) |(1<<6)| (ADC_PORT_CONFIG))
	else
ADCON1_VALUE = ( (1<<6)| (ADC_PORT_CONFIG))
	endif
	endif
;---------------------------------------------------------------------------------------
;Port definitions
#define	DRIVER_ENABLE_PORT	PORTB
; #define	DRIVER_ENABLE_BIT	3
#define	FAULT_BIT	4
#define	FWD_REV_KEY	1   ;It was 4
#define	RUN_STOP_KEY	0    ;It was 5

#define	PORT_LED1	PORTA
#define	LED1		1
#define	PORT_LED2	PORTA
#define	LED2		2
;---------------------------------------------------------------------------------------

Please help
 
Last edited:

Yes may be difficult to share schematic.
Please read hcpl 316 data sheet for complete information.

Hello,find the schematic here in attachment ,I tried to replace IR21362 by 3 IR2104 because those used has one input and it outputs two signals to supply a half bridge,the IR21362 input also 3 signals but output six signals to control three half bridge.
Unfortunately to find DIP type of HCPL316 is very very difficulty for me.!!

Please help,hope you also find the code

- - - Updated - - -

Here is the waveform of the signals on oscilloscope,I have two channel oscilloscope so I could only show two signals,
 

Attachments

  • ASYM.rar
    84.1 KB · Views: 114
  • Waveform.jpeg
    Waveform.jpeg
    341.8 KB · Views: 107

IGBT driving with PIC and IR21362 or IR21365

Hello,could you please advise me on how I can fully drive an IGBT for a three phase bridge circuit?
I am making a three phase induction motor control circuit and this has to provide the required voltage to the terminals of an induction motor three phase.
I am applying 45V DC at the three phase bridge and the voltage at the terminal is 11VAC,could you please let me know how I can advance and provide more output than what I have now ,you understand very well that if I input 440VDC the output should be around 100VAC which is not enough and also the IR21362 which I am suing as IGBT driver is becoming very hot,what can I do,
The IGBT I am using is IRG4PC50FD
at 5KHZ and the quartz is of 20MHZ the bootstrap capacitors are of 22uF/50V.

Please advise.
 
Last edited by a moderator:

Hell,find the two files comprising my codes,I found that the IGBT I am using(IRG4PC50FD) operate at 1-5KHZ and then I generated a PWM signal of 5KHZ the shaft of the motor tends to turn but the voltage is very low on motor terminals its around 11VAC,I suspected that the IGBT are not fully turned on could you suggest a way for turning the IGBT fully on so that the voltage can be increased across motor terminals?

Please advise,find here below the codes I used :
Code:
;----------------------------------------------------------------
    include        <p18F46K22.inc>
    include        <3im_vf.inc>
;----------------------------------------------------------------
; CONFIG1H
  CONFIG  FOSC = HSHP          ; Oscillator Selection bits (HS oscillator (high power > 16 MHz))
  CONFIG  PLLCFG = OFF          ; 4X PLL Enable (Oscillator used directly)
  CONFIG  PRICLKEN = ON         ; Primary clock enable bit (Primary clock is always enabled)
  CONFIG  FCMEN = ON            ; Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
  CONFIG  IESO = ON             ; Internal/External Oscillator Switchover bit (Oscillator Switchover mode enabled)

; CONFIG2L
  CONFIG  PWRTEN = OFF          ; Power-up Timer Enable bit (Power up timer disabled)
  CONFIG  BOREN = SBORDIS       ; Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
  CONFIG  BORV = 190            ; Brown Out Reset Voltage bits (VBOR set to 1.90 V nominal)

; CONFIG2H
  CONFIG  WDTEN = OFF           ; Watchdog Timer Enable bits (Watch dog timer is always disabled. SWDTEN has no effect.)
  CONFIG  WDTPS = 32768         ; Watchdog Timer Postscale Select bits (1:32768)

; CONFIG3H
  CONFIG  CCP2MX = PORTC1       ; CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
  CONFIG  PBADEN = OFF          ; PORTB A/D Enable bit (PORTB<5:0> pins are configured as digital I/O on Reset)
  CONFIG  CCP3MX = PORTB5       ; P3A/CCP3 Mux bit (P3A/CCP3 input/output is multiplexed with RB5)
  CONFIG  HFOFST = ON           ; HFINTOSC Fast Start-up (HFINTOSC output and ready status are not delayed by the oscillator stable status)
  CONFIG  T3CMX = PORTC0        ; Timer3 Clock input mux bit (T3CKI is on RC0)
  CONFIG  P2BMX = PORTD2        ; ECCP2 B output mux bit (P2B is on RD2)
  CONFIG  MCLRE = EXTMCLR       ; MCLR Pin Enable bit (MCLR pin enabled, RE3 input pin disabled)

; CONFIG4L
  CONFIG  STVREN = ON           ; Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
  CONFIG  LVP = OFF              ; Single-Supply ICSP Enable bit (Single-Supply ICSP enabled if MCLRE is also 1)
  CONFIG  XINST = OFF           ; Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

; CONFIG5L
  CONFIG  CP0 = OFF             ; Code Protection Block 0 (Block 0 (000800-003FFFh) not code-protected)
  CONFIG  CP1 = OFF             ; Code Protection Block 1 (Block 1 (004000-007FFFh) not code-protected)
  CONFIG  CP2 = OFF             ; Code Protection Block 2 (Block 2 (008000-00BFFFh) not code-protected)
  CONFIG  CP3 = OFF             ; Code Protection Block 3 (Block 3 (00C000-00FFFFh) not code-protected)

; CONFIG5H
  CONFIG  CPB = OFF             ; Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
  CONFIG  CPD = OFF             ; Data EEPROM Code Protection bit (Data EEPROM not code-protected)

; CONFIG6L
  CONFIG  WRT0 = OFF            ; Write Protection Block 0 (Block 0 (000800-003FFFh) not write-protected)
  CONFIG  WRT1 = OFF            ; Write Protection Block 1 (Block 1 (004000-007FFFh) not write-protected)
  CONFIG  WRT2 = OFF            ; Write Protection Block 2 (Block 2 (008000-00BFFFh) not write-protected)
  CONFIG  WRT3 = OFF            ; Write Protection Block 3 (Block 3 (00C000-00FFFFh) not write-protected)

; CONFIG6H
  CONFIG  WRTC = OFF            ; Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
  CONFIG  WRTB = OFF            ; Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
  CONFIG  WRTD = OFF            ; Data EEPROM Write Protection bit (Data EEPROM not write-protected)

; CONFIG7L
  CONFIG  EBTR0 = OFF           ; Table Read Protection Block 0 (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
  CONFIG  EBTR1 = OFF           ; Table Read Protection Block 1 (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
  CONFIG  EBTR2 = OFF           ; Table Read Protection Block 2 (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
  CONFIG  EBTR3 = OFF           ; Table Read Protection Block 3 (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks)

; CONFIG7H
  CONFIG  EBTRB = OFF           ; Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
;----------------------------------------------------------------------
#define TIMER0_OV_FLAG    0
#define OFFSET1_FLAG    4
#define OFFSET2_FLAG    5
#define OFFSET3_FLAG    6

#define    MOTOR_DIRECTION    7
#define MOTOR_RUNNING    1
#define    DEBOUNCE    0
#define    ON_OFF_FLAG    1
#define    DELAY_COUNT1    0xFF
#define    DELAY_COUNT2    0xFF
;===============================================================
;RAM locations in Access bank, uninitialized
    UDATA_ACS     
TABLE_OFFSET1    res    1        ;Phase1 offset to the Sine table(0)
TABLE_OFFSET2    res    1        ;Phase2 offset to the Sine table(120)
TABLE_OFFSET3    res    1        ;Phase3 offset to the Sine table(240)

COUNTER        res    1        ;General counters
COUNTER1    res    1
FLAGS            res    1        ;Flags registers used to indicate different status
FLAGS1            res    1
FREQ_REF_H    res    1            ;Referance Frequency input in counts
FREQ_REF_L    res    1
FREQUENCY    res    1

CCPR1L_TEMP    res    1            ;Temporary locations
CCPR2L_TEMP    res    1
CCPR3L_TEMP RES 1
PWM_DUTYCYCLE RES 1

TEMP            res    1
TEMP1        res    1
TEMP_LOCATION    res    2
SINE_TABLE    res    0x14            ;Sine table
;----------------------------------------------------------------
STARTUP    code 0x00
    goto    Start        ;Reset Vector address 
    
    CODE    0x08
    goto    ISR_HIGH    ;Higher priority ISR at 0x0008

PRG_LOW    CODE    0x018
    goto    ISR_LOW        ;Lower priority ISR at 0x0018

;****************************************************************
PROG1    code
Start
;****************************************************************
;Initialization of the Ports and timers
    clrf    FLAGS                ;Clear the flags
	CLRF TRISC 
	CLRF TRISB 
	BSF TRISB,0		;Input Button 1
	BSF TRISB,1		;input button 2
	BCF TRISB,5 	;PWM3
	BCF TRISC,1		;PWM2
	BCF TRISC,2		;PWM1  
   BSF TRISB,RUN_STOP_KEY
    BSF PORTB,FWD_REV_KEY
    BSF PORTB,FAULT_BIT
	movlw    0x0C ;PWM registers configuration
    movwf    CCP1CON            ;CCP1 and CCP2 configured to PWM
    movwf    CCP2CON
    BANKSEL CCP3CON
    movwf CCP3CON
        
    CLRF ECCP1AS
   CLRF ECCP2AS
;	BANKSEL ECCP3AS
    CLRF ECCP3AS
  ;  BSF TRISD,RUN_STOP_KEY

 ;   bsf    TRISB,FAULT_BIT        ;Fault input from driver
    
    MOVLW 0x01
    MOVWF PSTR1CON
    MOVWF PSTR2CON
    MOVWF PSTR3CON
    MOVLW 0X80
    MOVWF PWM1CON
    MOVWF PWM2CON
    MOVWF PWM3CON

    CLRF  CCPTMRS0 ;Select timer 2 to be used for PWM generation
    bsf    T2CON,2            ;Timer2 ON
    movlw    PR2_VALUE            ;Load PR2 value to PR2 register
    movwf    PR2
    movlw    0x90                
    movwf    CCPR1L
    movwf    CCPR2L
    BANKSEL  CCPR3L
    MOVWF CCPR3L
    movlw    0x81            ;Timer1 prescaler 1:2
    movwf    T1CON
    call    Init_Motor_Parameters    ;Initialize motor parameters
    call    COPY_TABLE_TO_RAM        
;******************************************************************
;Initialize ADC registers
    movlw    ADCON0_VALUE    ;From ".inc" file
    movwf    ADCON0
    movlw    ADCON1_VALUE    ;From ".inc" file
    movwf    ADCON1
    movlw    0x01        ;RA0,RA4,RA5 inputs,RA2&RA3-Outputs
    movwf    TRISA    ;    
;    bsf    DRIVER_ENABLE_PORT,DRIVER_ENABLE_BIT    ;Enable the driver chip

;******************************************************************
;Timre0 Initialization with prescaler
;******************************************************************
    movlw    0X83        ;Load the T0CON with value
    movwf    T0CON        ;TMR0 ON and prescalar is 1:16
    movlw    0xF8        ;Timer0 Initialisation 
    movwf    TMR0H
    movlw    0x5E    ;
    movwf    TMR0L    

;---------------------------------------
    bsf    INTCON,TMR0IE    ;Timer0 overflow Interrupt enable
    bsf    PIE1,TMR2IE    ;"Timer2 to PR2 match" Interrupt enable
    bsf    PIE1,TMR1IE    ;Timer1 overflow Interrupt enable
    bsf    PIE1,ADIE    ;AD Converter over Interrupt enable
    bcf    IPR1,ADIP    ;Low priority for ADC interrupt
    bsf    INTCON,RBIE    ;PortB interrupt enable with low priority
    bcf    INTCON2,RBIP    ;for Fault checking
    movlw    0x093        ;Power ON reset status bit/Brownout reset status bit
    movwf    RCON        ;and Instruction flag bits are set
                        ;Priority level on Interrupots enabled
    bsf    INTCON,PEIE    ;Port interrupts enable
    bsf    INTCON,GIE    ;Global interrupt enable
;******************************************************************
;Main loop where the program will be looping
MAIN_LOOP
    btfss    FLAGS,TIMER0_OV_FLAG        ;back from Timer0 overflow?
    bra    bypass                            ;No
    call    UPDATE_PWM_DUTYCYCLES        ;Yes, update the PWM duty cycle with new value
    call    UPDATE_TABLE_OFFSET        ;Update 3 offsets
    bcf    FLAGS,TIMER0_OV_FLAG        ;Clear the flag
bypass
    call    SET_ADC_GO                ;Start AD conversion
    call    KEY_CHECK                ;Check keys change
    bra    MAIN_LOOP
;******************************************************************
;Higher priority interrupt service routine
;"Timer2 to PR2 match", "Timer1 overflow" and Timer0 overflow are checked
;******************************************************************
ISR_HIGH
    btfsc    PIR1,TMR2IF            ;Timer2 to PR2 match?    
    bra    TIMER2_PR2_Match        
;    btfsc    PIR1,TMR1IF            ;Timer1 overflow Interrupt?    
;    bra    TIMER1_OVERFLOW
    btfsc    INTCON,TMR0IF        ;Timer0 overflow Interrupt?    
    bra    TIMER0_OVERFLOW        ;Yes
    RETFIE    FAST

;******************************************************************
;///////////////////////////////////////////////////////////////////
;MODIFIED BY MYSELF FOR REMOVING TIMER 2 NOT USED FOR PWM GENERATION
;//////////////////////////////////////////////////////////////////
TIMER2_PR2_Match
    bcf    PIR1,TMR2IF        ;
;    tstfsz CCPR3L_TEMP  ;If Software PWM duty cycle=0, then 
    tstfsz CCPR3L
    bra    PWM3_NOT_0        ;no need to set the PWM3 port pin
    RETFIE    FAST
PWM3_NOT_0
    movlw    0xFF            ;Higher byte of Timer1 loaded with FFh
    movwf    TMR1H
    movff    CCPR3L_TEMP,TMR1L
    RETFIE    FAST
;///////////////////////////////////////////////////////////////////
;MODIFIED BY MYSELF FOR REMOVING TIMER 2 NOT USED FOR PWM GENERATION
;//////////////////////////////////////////////////////////////////
;******************************************************************
;TIMER1_OVERFLOW
;    bcf    PWM3_PORT,PWM3_PORT_PIN    ;PWM3 pin cleared after the duty cycle time expires
;    BCF PORTB,5
;    bcf    PIR1,TMR1IF    
;    RETFIE    FAST

;******************************************************************
TIMER0_OVERFLOW                ;TMR0 overflow ISR
    movff    FREQ_REF_H,TMR0H    ;Load the Higher byte of SpeedCommand to TMR0H
    movff    FREQ_REF_L,TMR0L    ;Load the Lower byte of SpeedCommand to TMR0L    
    bsf    FLAGS,TIMER0_OV_FLAG
    bcf    INTCON,TMR0IF    ;Clear TMR0IF    
    RETFIE    FAST    
;******************************************************************
;Lower priority interrupt service routine
;Change on PortB(Fault checking) interrupt & "ADConversion over" interrupt are checked
;******************************************************************
ISR_LOW
    btfsc    INTCON,RBIF            ;RB interrupt?    
    bra    CHECK_FAULT            ;Yes
    btfsc    PIR1,ADIF
    bra    AD_CONV_COMPLETE
    RETFIE    FAST
;******************************************************************
CHECK_FAULT
    movf    PORTB,W            ;Check for fault bit
    btfss    WREG,FAULT_BIT
    bra    THERE_IS_FAULT    
    call    RUN_MOTOR_AGAIN        ;Fault cleared?
    bcf    INTCON,RBIF            ;Run motor again
    RETFIE    FAST
THERE_IS_FAULT                ;Yes,fault is there
    call    STOP_MOTOR            ;Stop motor
    bcf    INTCON,RBIF    
    RETFIE    FAST
;******************************************************************
AD_CONV_COMPLETE            ;ADC interrupt
    movff    ADRESH,FREQUENCY 
    movlw    0x14            ;Minimum Frequency set to 5Hz (scaling factor X4) 
    cpfsgt    FREQUENCY
    movwf    FREQUENCY
    movlw    0xF0            ;Limiting V/F to F= 60Hz (scaling factor X4) 
    cpfslt    FREQUENCY
    movwf    FREQUENCY
    movwf    PORTD            ;Out frequency to PORTD for set value
    bcf    PIR1,ADIF        ;ADIF flag is cleared for next interrupt
    RETFIE    FAST        

;*************************************************************************
;This routine will update the PWM duty cycle on CCPx according to the 
;offset to the table with 0-120-240 degrees.
;This routine scales the PWM value from the table based on the frequency to keep V/F
;constant.
;*************************************************************************
UPDATE_PWM_DUTYCYCLES
    movf    TABLE_OFFSET1,W
    movf    PLUSW0,W
    bz    PWM1_IS_0
    mulwf    FREQUENCY            ;Table_value X Frequency
    movff    PRODH,CCPR1L_TEMP
    bra    UPDATE_PWM2
PWM1_IS_0
    clrf    CCPR1L_TEMP            ;Clear the PWM duty cycle register
    bcf    CCP1CON,4    
    bcf    CCP1CON,5

UPDATE_PWM2
    movf    TABLE_OFFSET2,W
    movf    PLUSW0,W
    bz    PWM2_IS_0
    mulwf    FREQUENCY        ;Table_value X Frequency
    movff    PRODH,CCPR2L_TEMP
    bra    UPDATE_PWM3
PWM2_IS_0
    clrf    CCPR2L_TEMP            ;Clear the PWM duty cycle register
    bcf    CCP2CON,4    
    bcf    CCP2CON,5    
UPDATE_PWM3
    movf    TABLE_OFFSET3,W
    movf    PLUSW0,W
    bz    PWM3_IS_0
    mulwf    FREQUENCY        ;Table_value X Frequency
    movff    PRODH,CCPR3L_TEMP
     bra  SET_PWM12
PWM3_IS_0
    clrf    CCPR3L_TEMP            ;Clear the PWM duty cycle register
    bcf    CCP2CON,4    
    bcf    CCP2CON,5
;//////////////////////////////////////////////////////
;ABOVE WERE MODIFIED BY MYSELF
;//////////////////////////////////////////////////////
SET_PWM12
    btfss    FLAGS,MOTOR_DIRECTION  
    bra    ROTATE_REVERSE
    movff    CCPR1L_TEMP,CCPR1L
    movff    CCPR2L_TEMP,CCPR2L
    BANKSEL CCPR3L
    movff CCPR3L_TEMP,CCPR3L
;    movff CCPR3L_TEMP,PWM_DUTYCYCLE
;    movff PWM_DUTYCYCLE,CCPR3L

    bsf    PORT_LED1,LED1
    return    
;////////////////////////////////////////////
;/DEACTIVATE TWO DIRECTION OPERATION BY MYSELF
;////////////////////////////////////////////
ROTATE_REVERSE
    movff    CCPR2L_TEMP,CCPR1L
    movff    CCPR1L_TEMP,CCPR2L
    movff CCPR3L_TEMP,PWM_DUTYCYCLE
    MOVFF PWM_DUTYCYCLE,CCPR3L
    bcf    PORT_LED1,LED1
    return    
;*******************************************************************************
;This routine Updates the offset pointers to the table after every access
;*******************************************************************************
UPDATE_TABLE_OFFSET
    btfss    FLAGS,OFFSET1_FLAG    ;If set incr. on table
    bra    DECREMENT_OFFSET1
    movlw    (SINE_TABLE_ENTRIES-1)    ;Check for the last value on the table
    cpfslt    TABLE_OFFSET1
    bra    CLEAR_OFFSET1_FLAG
    incf    TABLE_OFFSET1,F        ;Increment offset1
    bra    UPDATE_OFFSET2
CLEAR_OFFSET1_FLAG
    bcf    FLAGS,OFFSET1_FLAG
DECREMENT_OFFSET1
    dcfsnz    TABLE_OFFSET1,F        ;Decrement offset1
    bsf    FLAGS,OFFSET1_FLAG

UPDATE_OFFSET2
    btfss    FLAGS,OFFSET2_FLAG    ;If set incr. on table
    bra    DECREMENT_OFFSET2
    movlw    (SINE_TABLE_ENTRIES-1)    ;Check for the last value on the table
    cpfslt    TABLE_OFFSET2
    bra    CLEAR_OFFSET2_FLAG
    incf    TABLE_OFFSET2,F        ;Increment offset2
    bra    UPDATE_OFFSET3
CLEAR_OFFSET2_FLAG
    bcf    FLAGS,OFFSET2_FLAG
DECREMENT_OFFSET2
    dcfsnz    TABLE_OFFSET2,F        ;Decrement offset2
    bsf    FLAGS,OFFSET2_FLAG

UPDATE_OFFSET3
    btfss    FLAGS,OFFSET3_FLAG    ;If set incr. on table
    bra    DECREMENT_OFFSET3
    movlw    (SINE_TABLE_ENTRIES-1)    ;Check for the last value on the table
    cpfslt    TABLE_OFFSET3
    bra    CLEAR_OFFSET3_FLAG
    incf    TABLE_OFFSET3,F        ;Increment offset3
    return    
CLEAR_OFFSET3_FLAG
    bcf    FLAGS,OFFSET3_FLAG
DECREMENT_OFFSET3
    dcfsnz    TABLE_OFFSET3,F        ;Decrement offset3
    bsf    FLAGS,OFFSET3_FLAG
    return    
;*******************************************************************************
;This routine calculates the Timer0 reload value based on ADC read value and the 
;scaling factor calculated based on the main clock and number of Sine table entries.
;Timer0 value = FFFF - (FREQUENCY_SCALE/Frequency)    Frequ = (adc result)
;*******************************************************************************
CALCULATE_FREQUENCY
    movff    FREQUENCY,PORTD
    clrf    TEMP
    clrf    TEMP1
    movlw    HIGH(FREQUENCY_SCALE)    ;FREQUENCY_SCALE/Frequency
    movwf    TEMP_LOCATION        ;16 bit by 8 bit division             
    movlw    LOW(FREQUENCY_SCALE)    ;
    movwf    TEMP_LOCATION+1
continue_subtraction
    bsf    STATUS,C
    movf    FREQUENCY,W
    subwfb    TEMP_LOCATION+1,F
    clrf    WREG
    subwfb    TEMP_LOCATION,F
    btfss    STATUS,C
    goto    keep_result_in_rpm    
    incf    TEMP,F
    btfsc    STATUS,C        ;Result of the division is stored in TEMP&TEMP1
    incf    TEMP1,F
    goto    continue_subtraction    
keep_result_in_rpm    
    ;Timer0 value = FFFF-Timer0 
    bsf    STATUS,C
    movlw    0xFF
    subfwb    TEMP,F
    subfwb    TEMP1,F            ;The Timer0 reload value stored in 
    movff    TEMP1,FREQ_REF_H    ;FREQ_REF_H & FREQ_REF_L 
    movff    TEMP,FREQ_REF_L        ;These values will be loaded to
    return                ;Timer0 in Timer0 overflow interrupt        
;*******************************************************************************
;This routine sets the ADC GO bit high after an aquisition time of 20uS approx. 
;*******************************************************************************
SET_ADC_GO
    call    CALCULATE_FREQUENCY
    btfss    ADCON0,GO    
    bsf    ADCON0,GO    ;Set GO bit for ADC conversion start    
    return    
;*******************************************************************************
;This routine initializes the parameters required for motor initialization.
;*******************************************************************************
Init_Motor_Parameters
    clrf    CCPR1L            ;Initialize all duty cycles to 0
    clrf    CCPR2L
    CLRF    CCPR3L
    movlw    0x09            ;Initialize the table offset to 3 registers
    movwf    TABLE_OFFSET1        ;to form 0-120-240 degrees
    movlw    0x03
    movwf    TABLE_OFFSET2
    movlw    0x0F
    movwf    TABLE_OFFSET3
    bsf    FLAGS,OFFSET1_FLAG    ;Offset flags initialization
    bcf    FLAGS,OFFSET2_FLAG
    bcf    FLAGS,OFFSET3_FLAG

    movlw    0x30            ;Initialize frequency to 12Hz
    movwf    FREQUENCY
    movlw    0xFD            ;Timer0 Initialisation 
    movwf    FREQ_REF_H
    movwf    TMR0H
    movlw    0x2C    ;
    movwf    TMR0L    
    movwf    FREQ_REF_L
    bsf    FLAGS,TIMER0_OV_FLAG    
    return

;*******************************************************************************
;Upon initialization the Sine table contents are copied to the RAM from 
;Program memory 
;*******************************************************************************
COPY_TABLE_TO_RAM
    movlw    UPPER sine_table    ;Initialize Table pointer to the first  
    movwf    TBLPTRU            ;location of the table
    movlw    HIGH sine_table
    movwf    TBLPTRH
    movlw    LOW sine_table
    movwf    TBLPTRL
    movlw    LOW(SINE_TABLE)
    movwf    FSR0L
    movlw    HIGH(SINE_TABLE)
    movwf    FSR0H
    movlw    0x14
    movwf    TEMP
COPY_AGAIN
    TBLRD*+
    movff    TABLAT,POSTINC0
    decfsz    TEMP,F
    bra    COPY_AGAIN

    movlw    LOW(SINE_TABLE)        ;FSR0 points to the starting of the table
    movwf    FSR0L
    movlw    HIGH(SINE_TABLE)
    movwf    FSR0H
    return        

;*******************************************************************************
;This routine checks for the keys status. 2 keys are checked, Run/Stop and 
;Forward(FWD)/Reverse(REV)  
;*******************************************************************************
KEY_CHECK
    btfsc    PORTB,RUN_STOP_KEY            ;Is key pressed "RUN/STOP"?
;    btfss    PORTB,RUN_STOP_KEY
    bra    KEY_IS_RUN
    bcf    PORT_LED2,LED2
    call    STOP_MOTOR
    bsf    FLAGS,MOTOR_RUNNING
    return

KEY_IS_RUN    
    bsf    PORT_LED2,LED2
    btfss    FLAGS,MOTOR_RUNNING
    bra    CONT_RUN_KEY
    call    RUN_MOTOR_AGAIN
    bcf    FLAGS,MOTOR_RUNNING
    return
CONT_RUN_KEY
    btfsc    PORTB,FWD_REV_KEY            ;Fwd/Rev key pressed?
    ;btfss    PORTA,FWD_REV_KEY            ;Fwd/Rev key pressed?
    bra    MOTOR_SET_FWD
    btfsc    FLAGS,MOTOR_DIRECTION    
    return
    call    STOP_MOTOR
    call    DELAY
    call    DELAY
    call    DELAY
    call    DELAY
    call    DELAY
    call    DELAY
    call    RUN_MOTOR_AGAIN
    bsf    FLAGS,MOTOR_DIRECTION
    return
MOTOR_SET_FWD
    btfss    FLAGS,MOTOR_DIRECTION    
    return
    call    STOP_MOTOR
    call    DELAY
    call    DELAY
    call    DELAY
    call    DELAY
    call    DELAY
    call    DELAY
    call    RUN_MOTOR_AGAIN
    bcf    FLAGS,MOTOR_DIRECTION
    return
;*******************************************************************************
;This routine stops the motor by driving the PWMs to 0% duty cycle.
;*******************************************************************************
STOP_MOTOR
    clrf    CCPR1L
    clrf    CCPR2L
    CLRF    CCPR3L
    clrf    TABLE_OFFSET1
    clrf    TABLE_OFFSET2
    clrf    TABLE_OFFSET3
    bcf    INTCON,TMR0IE
    bcf    PIE1,TMR2IE
    bcf    PIE1,TMR1IE
    bcf    PIE1,ADIE
    return
;*******************************************************************************
;This routine starts motor from previous stop with motor parameters initialized
;*******************************************************************************
RUN_MOTOR_AGAIN
    call    Init_Motor_Parameters
    bsf    INTCON,TMR0IE
    bsf    PIE1,TMR2IE
    bsf    PIE1,TMR1IE
    bsf    PIE1,ADIE
    return

;*******************************************************************************
;Delay routine.
;*******************************************************************************
DELAY
    movlw    DELAY_COUNT1
    movwf    COUNTER
dec_count    
    movlw    DELAY_COUNT2
    movwf    COUNTER1
dec_count1
    decfsz    COUNTER1,F
    bra    dec_count1
    decfsz    COUNTER,F
    bra    dec_count
    clrf    COUNTER
    clrf    COUNTER1
    return        
;*******************************************************************************
;Sine table for the inverter. 
;*******************************************************************************
TABLE    code 0x0100
;below table is from 270 eg. to 90 deg @ 10 deg. resolution; for 20MHz, PR2 = F9, Timer2 1:1 prescale

sine_table db d'0', d'21', d'41', d'61', d'81', d'100', d'119', d'136', d'153', d'169', d'183', d'196', d'208', d'219', d'228', d'236', d'241', d'246', d'248' ;for 5KHZ ,19 entries
;sine_table db  d'0', d'6', d'13', d'19', d'25', d'31', d'37', d'42', d'47', d'52', d'57', d'61', d'64', d'68', d'71', d'73', d'75', d'76', d'77' ;for 4KHZ;19 enntries
;sine_table db    0x0,0x3,0x07,0x10,0x1B,0x28,0x38,0x4A,0x5C,0x70,0x83,0x96,0xA7,0xB7,0xC4,0xD0,0xD8,0xDD,0xDE ;for 20KHZ,19 entries

;*******************************************************************************
    END

and the following
Code:
;User defined variables
;---------------------------------------------------------------------------------------
;Oscillator frequency
#define OSCILLATOR    d'20000000'
;---------------------------------------------------------------------------------------
;Timer0 prescaler
#define    TIMER0_PRESCALE    d'16'
;---------------------------------------------------------------------------------------
;number of entries in the sine table, or the sampling frequency
#define    SINE_TABLE_ENTRIES    d'19'
;---------------------------------------------------------------------------------------
SAMPLES_PER_CYCLE = (SINE_TABLE_ENTRIES-1)*d'2'
INSTRUCTION_CYCLE = (OSCILLATOR)/d'4'
FREQUENCY_SCALE = (INSTRUCTION_CYCLE/SAMPLES_PER_CYCLE)/(TIMER0_PRESCALE/4)
;Timer prescale/4 is done to componsate ADC multiplication factor of 4 to the frequency)
;---------------------------------------------------------------------------------------
;PWM frequency definition
#define TIMER2_PRESCALE    d'04'
#define    PWM_FREQUENCY    d'5000'
PR2_VALUE = (OSCILLATOR/(4*PWM_FREQUENCY*TIMER2_PRESCALE))-1
;---------------------------------------------------------------------------------------
;ADC initialization
#define    Fosc_by_2    b'000'
#define    Fosc_by_8    b'001'
#define    Fosc_by_32    b'010'
#define    FRC        b'011'
#define    Fosc_by_4    b'100'
#define    Fosc_by_16    b'101'
#define    Fosc_by_64    b'110'

#define    ADC_CLOCK    Fosc_by_32
#define    ADC_CHANNEL    d'0'
#define    ADC_ON_BIT    b'1'
#define LEFT_JUSTIFIED
#define    ADC_PORT_CONFIG    b'1110'    ;Refer the table in the manual for selection

ADCON0_VALUE = ((ADC_CLOCK<<6)|(ADC_CHANNEL<<4)|(ADC_ON_BIT))

    if ((ADC_CLOCK==Fosc_by_2)||(ADC_CLOCK ==Fosc_by_8)||(ADC_CLOCK ==Fosc_by_32)||(ADC_CLOCK==FRC))
    ifndef    LEFT_JUSTIFIED
ADCON1_VALUE = ((1<<7) | (ADC_PORT_CONFIG))
    else
ADCON1_VALUE = ADC_PORT_CONFIG
    endif
    endif
    if    ((ADC_CLOCK==Fosc_by_4)||(ADC_CLOCK==Fosc_by_16)||(ADC_CLOCK==Fosc_by_64))     
    ifndef    LEFT_JUSTIFIED
ADCON1_VALUE = ((1<<7) |(1<<6)| (ADC_PORT_CONFIG))
    else
ADCON1_VALUE = ( (1<<6)| (ADC_PORT_CONFIG))
    endif
    endif
;---------------------------------------------------------------------------------------
;Port definitions
#define    DRIVER_ENABLE_PORT    PORTB
; #define    DRIVER_ENABLE_BIT    3
#define    FAULT_BIT    4
#define    FWD_REV_KEY    1   ;It was 4
#define    RUN_STOP_KEY    0    ;It was 5

#define    PORT_LED1    PORTA
#define    LED1        1
#define    PORT_LED2    PORTA
#define    LED2        2
;---------------------------------------------------------------------------------------
 

Low voltage means low average (e.g. low duty cycle) or low peak voltage (IGBTs not switching correctly)?
 

Hello Jean
Are u sure for frequency which is generated by Ur core
How do you measuring voltage with DSM?

For change voltage you have to modify routine which multiply frequency with sine table off set. Basically frequency variable u have to change

Reply
 
Last edited:

Low voltage means low average (e.g. low duty cycle) or low peak voltage (IGBTs not switching correctly)?
Hello,do we have to increase the duty cycle by setting

CCPRXL? and that one bit from CCPXCON?are those sufficient how may I proceed for fully turning on the IGBTs?

Please help

- - - Updated - - -

Hey,for frequency measurement I am using the DSO,oscilloscope so it is the one which shows the frequency and voltage of PWM Signal.
What I changed is the sine table because,the PR2 value has changed so I referred to Tahmid blog and used its software "Smart Sine" for generating the proper sine_table also,the Prescaler of Timer2 has changed from 1 to 4 and then the included file in the codes I set the 5KHZ instead of 20KHZ;you can find my codes here in attachment,my circuit is also on https://www.edaboard.com/threads/355966/#post1523052

Please help
 

Attachments

  • Codes.rar
    12.1 KB · Views: 109

Hello Jean
You don't have to change sine table values ... you have to change multipler of sine table value.
For example: lets suppose 250 value from sine table will give you maximum voltage due to maximum high duty cycle.
If we multiply 250*1 =250 hence full value , If 250*.5= 125 then half of the voltage. That's it.
Sine table value * ADC value ( frequency command) is working in your code .
I hope you understand
 

Hello,can you refer to my codes and propose what to do?
Thanks!!
 

Dearabc_de, my PWM I am using is variable with a potentiometer and it can`t reach 3.3V at all time as it starts from 3.99V as maximum,so what should be done?

Please help
 

hello jean...
ok no matter but the thing is by change in duty cycle of microcontroller then change in IGBT switching hence output voltage.
are you getting right voltage now .?

- - - Updated - - -

Code:
UPDATE_PWM_DUTYCYCLES
    movf    TABLE_OFFSET1,W
    movf    PLUSW0,W
    bz    PWM1_IS_0
    mulwf    FREQUENCY            ;Table_value X Frequency
    movff    PRODH,CCPR1L_TEMP

    bra    UPDATE_PWM2

table_value X Frequency=table_value X 1


in upper given your code frequency scales voltage. for testing purpose make frequency variable 1 so that pwm duty cycle remain same as in sine table and check output voltage
 

no good result at all!!
 

hello
few months ago i have worked on same project. for reference i had followed AN900 application notes from Microchip and successfully run 2 hp 3 phase induction motor with help of edaboard members.
can you share your schematic ?
for simplicity IGBT driver circuit you can also follow AN1664 Application notes from Motorola.
 

Hello,here is my schematics,find it in attachment.
If you have been working on the same project you can share with me your experience I hope I can handle it.

I tried to refer to all those AN notes of Microchip talking on motor drive but some time I fail mainly because of lack of components.
Here I modified AN843 (where it was using PIC18F452) which has only 2PWM pins and with the program the 3rd PWM is generated in software,so I preferred using PIC18F46K22 which has 2PWM and 3ECCP,the 3ECCP are used for giving the PWM Signals required if possible please help me to check if there is an error in the codes.
--I don`t want to take any measurement of current or voltage
-I have a variable resistor(Potentiometer) which helps in adjusting the V an F such that V/F remain a constant
-Two push buttons are enough RUN/STOP and FORWARD/REVERSE there are clearly visible on the schematic
--I want to change the controlling frequency and use 5KHZ instead of 20KHZ,please help.Find the attachment having schematics and codes.

Regarding AN900 of microchip,I can`t find the PIC18F4431 and the codes used over there seem to be more challenging than AN843,with this last one the PIC18F46K22 is giving the 3PWM on RB5,RC1 and RC2 Respectively.

Please help!!
 

Attachments

  • Forum_Ok.rar
    76.3 KB · Views: 95
Last edited by a moderator:

hello jean
my first question why do you used C4,C5,C6 Capacitor 100uF even your frequency is 5KHZ ?
second why you have used D6-D10 1N4007 ?
Third IGBT gate pull down 750E ?
why your circuit is non isolated ?
i program the micro controller in C language therefore i don't understand assembly in detail.

need some corrections in your hardware try to use C4,C5,C6 Capacitor 2.2 uF, D6-D10 1N4148, IGBT gate pull down 4k7E . try to use opto coupler for micro controller safty.



if you found my post useful then please click helped me button
 
  • Like
Reactions: jean12

    jean12

    Points: 2
    Helpful Answer Positive Rating
Hello,the capacitors C4,C5 and C6 are the bootstrap capacitors didn`t you use them for your implementation?
The opto-coupler I can find are 4N25 can those serve for isolating the IGBTs?
What about the frequency may I maintain it to 5KHZ,I previously used 5KHZ because the IGBTs I was using were operating at 1-5KHZ(IRG4PC50FD).Please can you share with me your design,for the codes in C I had some in microc but they wee incomplete and not able to complete so I MOVED to assembly with Microchip already made;can you help me with those in microc?

Please help
 

hello
its possible to implement right hardware. 1st of all you need to choose right hardware. like IGBT, Driver IC, microcontroller etc.

i don't know anything about micro controller which your using.
for successful design 1st of all make simple circuit and try to test it on low voltage instead of high dc bus volatge.

in my design i have used IR2110 instead of 3 phase driver i can post it shortly

here is link for my project but in this video i have drive 1 hp motor

https://www.youtube.com/watch?v=_EBaRl9qhh0

here is igbt driver circuit

**broken link removed**
 

Hello,could you provide the codes also?Which micro controller have you used?The link you posted for IGBT driver is invalid,check again
 

for my project i have use pic18f4431 and switching frequency is 16khz.
the link which i post its you tube link of my project. its valid i have visit this page minute ago.
yes i can post my code shortly 1 st make valid circuit before software work
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top