Ir ao conteúdo
  • Cadastre-se

Ajuda inversor de frequencia


caroline cabral

Posts recomendados

ajuda para montar o circuito baseado no soft que ja tenho pois nao tenho conhecimento em asm mas dizem que o soft ja esta completo bastando asim uma interpletaçao para o harder . aparte de potencia eu ja tenho tambem

so gostaria de saber os botões e as saida do pic e suas funçoes

poderia ser no propio comentario no decorrer do programa. ou umj posivel esquema de ligaçao


;PROGRAM : V/F control of 3-Phase Induction Motor
;MICROCONTROLLER : PIC18XXX
;CRYSTAL FREQUENCY : 20MHz
;DRIVER IC USED : IR21XX
;IGBT used : CPV364M4U
;******************************************************************
;Documents to be refered with this :
; a) Diagram of control circuit
; B) Application note: 3-Phase Induction Motor control using PIC18XXX
;******************************************************************
;AUTHOR : Padmaraja Yedamale , Appliance Group
;DATE : 20-Dec-2001
;Version : V1.0
;******************************************************************
;Description:-
;------------
;By varying the frequency of supply to the Induction motor we can control the
;speed of the motor. But by varying only frequency, changes the flux
;also which results in changes in torque. So to keep the flux, hence
;torque, the magnitude of voltage applied also needs to be changed. Or in other
;words, the ration of V/F needs to be kept constant throughout the
;operating range.
;To control a 3 phase Induction motor, it needs 3 PWMs to control the 3
;phase inverter. PIC18XXX has 2 hardware PWMs. Third PWM is generated in
;the software and output to one of the port pins.
;
;----------------------------------------------------------------
include <p18c452.inc>
include <3im_vf.inc>
;----------------------------------------------------------------

#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
PWM3_DUTYCYCLE res 1 ;Duty cycle setting of software PWM
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
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 TRISB ;PORTB all output
clrf PORTB
bsf TRISB,FAULT_BIT ;Fault input from driver
movlw 0x0C
movwf CCP1CON ;CCP1 and CCP2 configured to PWM
movwf CCP2CON
bsf T2CON,2 ;Timer2 ON
movlw PR2_VALUE ;Load PR2 value to PR2 register
movwf PR2
movlw 0x90
movwf CCPR1L
movwf CCPR2L
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

;******************************************************************
TIMER2_PR2_Match
bcf PIR1,TMR2IF ;
tstfsz PWM3_DUTYCYCLE ;If Software PWM duty cycle=0, then
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 PWM3_DUTYCYCLE,TMR1L ;Lower byte of Timer1 loaded with Duty cycle
bsf PWM3_PORT,PWM3_PORT_PIN ;PWM3 pin set high
RETFIE FAST
;******************************************************************
TIMER1_OVERFLOW
bcf PWM3_PORT,PWM3_PORT_PIN ;PWM3 pin cleared after the duty cycle time expires
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
comf PRODH,W ;For directly loading to the Timer reg.
incf WREG,W
movwf PWM3_DUTYCYCLE
bra SET_PWM12
PWM3_IS_0
clrf PWM3_DUTYCYCLE ;Clear the PWM duty cycle register

SET_PWM12
btfss FLAGS,MOTOR_DIRECTION
bra ROTATE_REVERSE
movff CCPR1L_TEMP,CCPR1L
movff CCPR2L_TEMP,CCPR2L
bsf PORT_LED1,LED1
return
ROTATE_REVERSE
movff CCPR2L_TEMP,CCPR1L
movff CCPR1L_TEMP,CCPR2L
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 PWM3_DUTYCYCLE

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 PORTA,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
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 PWM3_DUTYCYCLE
clrf TABLE_OFFSET1
clrf TABLE_OFFSET2
clrf TABLE_OFFSET3
bcf PWM3_PORT,PWM3_PORT_PIN
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
;******************************************************************

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!