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.

Voltage drop out on output pins of PIC18F46K22

Status
Not open for further replies.

jean12

Advanced Member level 2
Advanced Member level 2
Joined
Aug 27, 2013
Messages
529
Helped
5
Reputation
12
Reaction score
6
Trophy points
18
Activity points
5,497
Hello,please help,I am using PIC18F46K22 for generating 3PWM signals to control a full bridge,three phase circuit but the problem I have is that the output voltage is very low at 345mv,could you please help me to handle this problem,I even disconnected the load(IGBT driver) and measure only the output of the PIC but the voltage remain the same at 345mv.

I am judging that the mistake might be from the configuration bits or the way I used for setting data direction on the ports,here below are my two files`s codes I am using:
1.Program
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 = OFF             ; 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 = OFF          ; 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
	BSF TRISB,0
	BCF TRISB,5;PWM output 3
	BCF TRISC,1;PWM output 1
	BCF TRISC,2  ;PWM output 2

	BSF TRISB,RUN_STOP_KEY ;set input pin for push button
	BSF TRISB,FWD_REV_KEY ;set input pin for push button
	CLRF LATB
	CLRF LATC
	CLRF PORTB
	CLRF PORTC

	bsf	TRISB,FAULT_BIT		;Fault input from driver
	movlw	0x0C
	movwf	CCP1CON			;CCP1 and CCP2 configured to PWM
	movwf	CCP2CON
	movwf CCP3CON ;CCP3 configured to PWM	
	MOVLW 0x01
	MOVWF PSTR1CON  ;configure PWM controlling registers
	MOVWF PSTR2CON;configure PWM controlling registers
	MOVWF PSTR3CON;configure PWM controlling registers
	MOVLW 0X80
	MOVWF PWM1CON;configure PWM controlling registers
	MOVWF PWM2CON;configure PWM controlling registers
	MOVWF PWM3CON;configure PWM controlling registers
	CLRF ECCP1AS;configure PWM controlling registers
	CLRF ECCP2AS;configure PWM controlling registers
	CLRF ECCP3AS;configure PWM controlling registers

	CLRF CCPTMRS0 ;select Timer 2 to use for PWM
	bsf	T2CON,2			;Timer2 ON
	movlw	PR2_VALUE			;Load PR2 value to PR2 register
	movwf	PR2  ;place PR2_VALUE into PR2 register
	movlw	0x90				
	movwf	CCPR1L
	movwf	CCPR2L
	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
	btfss	PORTB,RUN_STOP_KEY			;Is key pressed "RUN/STOP"?
	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
2.File to include:
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 to sort this out!!
 

Hi,

You don't tell HOW you measured the voltage.
So I assume it is a measurement problem...
Did you use a DVM? On PWM pulses?

--> with pulsed signals....use a scope

Klaus
 

Dear KlausST,I used oscilloscope as you mentioned above not a DVM.

Please help
 

Hi,

If an unconnected port, configured as output, only give 345mV, then
* either the measurement us wrong
* or the chip is damaged and needs to be replaced.

So first check if the port really is an output. Check on alternative pin functions, is it a debug pin, is it a programming pin, ADC...
Then cross check your scope reading with a known voltage. VCC?
Then replace the IC.

Klaus
 
  • Like
Reactions: jean12

    jean12

    Points: 2
    Helpful Answer Positive Rating
Hi,you are very right I have been trying multiple time but definitely I found that the probes were not good so they give very less voltage but when I replaced them with a new one I get a no stable voltage with oscilloscope between 2.25V to 4.90V;is it possible to handle the codes such that the voltage could be fixed at with a PWM Signal,only the duty cycle and frequency be variable when using the potentiometer?

What advise are you giving me such that I can apply this signal to an IR21362,I have tried with it but only the low side output(of IR21362 gives the output) and the High side give nothing.

----- I thought to use also an ULN2004 for increasing the voltage before applying to an IR21362 but no good output received.

Please help
 

Hi,

What advise are you giving me such that I can apply this signal to an IR21362,I have tried with it but only the low side output(of IR21362 gives the output) and the High side give nothing.
When the input levels of the IRxxx chip are within specification (read datasheet), then you don't need an extra driver.

The high side needs the bootstrap capacitor to be charged first....
Show us your EXACT TEST CIRCUIT, and your measurement points, the voltages and waveforms...

Klaus
 

Hi,


When the input levels of the IRxxx chip are within specification (read datasheet), then you don't need an extra driver.

The high side needs the bootstrap capacitor to be charged first....
Show us your EXACT TEST CIRCUIT, and your measurement points, the voltages and waveforms...

Klaus

Hello,KlausST,the schematics seems to be very difficult to upload because I use Proteus and I can`t find the IR21362 in proteus but for IR21362 Connections I referred to AN843 of microchip where the PIC18F452 is interfaced with IR21362.
https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en012011

I saw that the ULN2004 output around 7.2V to input to the IR21362,when the IR21362 is in the circuit on its input I find only around 4.1V which can`t trigger it for giving the output.

---Even if I referred to the above application note I judged that the bootstrap capacitors on that circuit in the AN843 are reversed!!Could you help me to clear that?

Please help
 

Hi,

As you clearely can see at the first page of the IRxx datasheet it is happy with 2.7V logic high level.
--> you don't need a driver as long as the PIC works correctely.

Use a pencil to draw the part of the schematic.

Klaus
 

Hello,KlausST,find here the snap of the IR21362 connections,I referred to AN985 of Infineon,

Please help!!
 

Attachments

  • Schematics.rar
    654.4 KB · Views: 128
Last edited:

Any situation where you don't get nearly 5V level at the logic outputs of a 5V supplied processor can be expected as one of these cases:
- wrong circuit
- defective parts
- wrong power supply
- faulty measurement equipment
- wrong PIC configuration (output pin not actually operated as output)

You should fix the error instead of trying to increase the output voltage with a buffer.

As mentioned by various contributors in your previous thread https://www.edaboard.com/threads/355384/, IR21362 can perfectly work with 5V logic levels. ULN200x drivers are particularly unsuitable: slow, need output pull-up resistors, unwanted signal inversion (gate driver will be "ON" after processor reset).
 

Dear,FvM referring to my codes posted previously could you please guide me where I might be wrong,when I check myself I found all are ok but I don`t get any signals,
for data directions I used:

Code:
     BSF TRISB,0  ;Push button 1
      BSF,TRISB,1 ;Push button 2
      BCF TRISB,5 ;PWM3
      BCF TRISC,2 ;PWM 2
      BCF TRISC,1 ;PWM 1


And then configured the registers 
CCP1CON=0X0C;
CCP2CON=0X0C;
CCP3CON=0X0C;
PR2 register
ANSELA=0X01;analog input on RA0
BSF TRISA,0
CCPR1L=0X90
CCPR2L=0X90
CCPR3L=0X90
BSF T2CON,2

Could you please advise where I am wrong?

the configuration words are as follows
Code:
; 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)
\

I want to generate 5KHZ with a quartz of 20MHZ;

an additional added file"included files"is as follows:
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
;---------------------------------------------------------------------------------------

Please help
 

Hi,

check if this is correct:
* " movf PORTB,W ;Check for fault bit"
* " CONFIG CCP2MX = PORTC1 ; CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)"
* " movwf PORTD ;Out frequency to PORTD for set value"
* " movff FREQUENCY,PORTD"
* You declared Driver_enable_bit, but you never set is as output.

Check all
* "ADC_PORT_CONFIG"

Klaus
 

Hi,

check if this is correct:
* " movf PORTB,W ;Check for fault bit"
* " CONFIG CCP2MX = PORTC1 ; CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)"
* " movwf PORTD ;Out frequency to PORTD for set value"
* " movff FREQUENCY,PORTD"
* You declared Driver_enable_bit, but you never set is as output.

Check all
* "ADC_PORT_CONFIG"

Klaus


Hello,the codes were judged to be collect because the shaft of an asynchronous motor I am using tends to move as I am now getting around 11VAC on its terminal,but this voltage is very low because the DC bus is at 45VDC,and also with this techniques the IR21362 became very hot in 1 to 2 minutes.could you help me to think on how the voltage can be increased?

With the variable resistor on RA0,I adjust that small voltage of 11VAC on the motor terminals but the voltage is very low,I am thinking that it could be a matter of IGBTs which are not fully turned on,how to solve this?

I modified the codes such that I am generating only 5KHZ[referring to the IRG4PC50FD IGBT datasheet] at 20KHZ[no voltage obtained at the motor terminal] the circuit looks like there is no command.
------What should be done for replacing the IR21362 by the IR21365? As both those ICs have only three input terminals,how are the output when taking the HO and LO,I am not understanding very well the datasheet what it says on the functionalities of those drivers.
Please help!!
 

Hi,

I find it a bit confusing..

Is the voltage at the PIC pin solved now?
If not, then this is the first to be solved.

Please step by step, not several issues in one post.

******
Now you say the driver IC becomes hot ... this is very untypical.
Again I assume there us a problem with your circuit.

Your pictures don't show the requested circuit, the description (for example pin numbering) is not complete, and the bad quality makes them hard to read.

--> show us the requested schematic, otherwise it's about impossible to help.

Klaus
 

------What should be done for replacing the IR21362 by the IR21365? As both those ICs have only three input terminals,how are the output when taking the HO and LO,I am not understanding very well the datasheet what it says on the functionalities of those drivers.

I have difficulties to understand your description, it doesn't even match your hand-sketched schematic which shows six inputs, separate HIN and LIN, three of each.

You have bridged HIN and LIN inputs, only possible for IR21362 which has inverted LIN and non-inverted HIN inputs. In so far I don't understand how you would replace IR21362 by IR21365. Not possible without changing the input signal generation.

The other point with bridged HIN and LIN is that you have to rely on internal generated gate driver dead time, typically 290 ns. Not sure if it's sufficient for your IGBTs.
 

The output voltage at the pin of the PIC is solved,now I modified the switching frequency from 20KHZ to 5KHZ and then the IR21362 has reacted,I am going to try to make IR21362 in proteus I give you the complete circuit I made so that you could help easily.

Thank you very much!!
 

Hello,find here the schematic of my implementation,don`t consider the ULN2004;its removed and the PIC output go immediately to the IR21362.

Please help
 

Attachments

  • drawing1.pdf
    21.6 KB · Views: 119

Hi,

VSS must be GND! It is the voltage reference for the digital input signals.

Review it. And the Itrip circuit.

All. ALL! Power supply capacitors are missing! A 100nF very close to each VCC IC pin and at least one bulk.
I recommend the same for the high voltage bus.

Next time please post your schematic with your first post. It is essential to locate errors.

Klaus
 

I guess the Proteus schematic print is only partly corresponding to the real circuit. It's more like a design idea, nobody knows how the real circuit looks like. The point that you still show the double faulty ULN2004 interface (missing pull-ups, COM pin is shorting outputs to ground) is just indicating the vagueness of posted information.
 

the pull up resistors were not added because I forget but I said ignore that ULN2004 as it was removed as you suggested,do you want me to upload a photo of the design?

I noticed that error and removed now the pull-up resistors are added!!

Please !!

- - - Updated - - -

Hi,

VSS must be GND! It is the voltage reference for the digital input signals.

Review it. And the Itrip circuit.

All. ALL! Power supply capacitors are missing! A 100nF very close to each VCC IC pin and at least one bulk.
I recommend the same for the high voltage bus.

Next time please post your schematic with your first post. It is essential to locate errors.

Klaus
Hello,KlausST could you please let me know where I have to connect the VSS,I thought its the ground;for ITRIP where should I connect it,thx a lot!!
 

Attachments

  • drawing_ok.pdf
    22.1 KB · Views: 125

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top