converrtidor dcdc
DESCRIPTION
dc-dcTRANSCRIPT
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
Diseño e Implementación de un Inversor con Control
PWM para una Carga Constante de 60W con un Nivel
de Tensión AC de 120VRMS y Frecuencia de 60 HZ
Rincón Edward1 ,Cristian Ortiz
2
Estudiante de Ingeniería Electromecanica1, 2
COD: 10903921, 1090456
2
E-mail: [email protected]
ABSTRACT. The DC / DC converters are responsible
for adapting a continuous signal from a power source to
the specifications required by the load; while an investor
convert direct current into alternating current AC DC,
allowing supply a load on your AC outlet, regulating
voltage and frequency. In other words an investor
transfers power from a DC source to an AC load.
Resumen. Los convertidores DC/DC son los encargados
de adecuar una señal continua proveniente de una fuente
de energía a las especificaciones exigidas por la carga;
mientras que un inversor convierten la corriente
continua DC en corriente alterna AC, permitiendo
alimentar una carga en su salida de alterna, regulando la
tensión y la frecuencia. Dicho de otro modo un inversor
transfiere potencia desde una fuente de corriente
continua a una carga de corriente alterna.
I. INTRODUCCION
Los circuitos de electrónica de potencia convierten la
energía eléctrica de un tipo en otro utilizando dispositivos
semiconductores como interruptores, para controlar o
modificar una tensión o una corriente y elementos de
almacenamiento de energía, como inductores y capacitores.
Entre las aplicaciones típicas de la electrónica de potencia
están la conversión de corriente alterna en corriente
continua, la conversión de corriente continua en alterna y la
conversión de una tensión continua no regulada en una
tensión continua regulada.
Los convertidores DC/DC son los encargados de adecuar
una señal continua proveniente de una fuente de energía a
las especificaciones exigidas por la carga; mientras que un
inversor convierten la corriente continua DC en corriente
alterna AC, permitiendo alimentar una carga en su salida de
alterna, regulando la tensión y la frecuencia. Dicho de otro
modo un inversor transfiere potencia desde una fuente de
corriente continua a una carga de corriente alterna.
La energía eléctrica en corriente alterna es indispensable en
cualquier lugar y a todo momento, por lo tanto en espacios
donde no llega la red pública, se hace necesario utilizar
sistemas de energía alternativa, que consisten en recoger y
almacenar energía, en recipientes diseñados para este fin, lo
que comúnmente conocemos como baterías. El problema de
estas, es que solo entregan corriente directa (DC) y la
mayoría de electrodomésticos trabajan con corriente alterna
(AC). Es en este momento que el inversor toma importancia,
para convertir esa corriente continua en corriente alterna.
El presente proyecto está enfocado en el diseño de un
inversor con control de modo voltaje.
II. OBJETIVO
Diseñar e implementar un inversor con control PWM para
una carga constante de 60w con un nivel de tensión AC de
120Vrms a una frecuencia de 60 Hz.
III. DESARROLLO
El primer paso a la hora de realizar un diseño es conocer las
especificaciones del mismo, en este caso, se requiere
alimentar una carga de 60W con un nivel de tensión AC de
120Vrms y a una frecuencia de 60Hz con una variación en
la tensión (Vrms) no mayor al 2%, teniendo como entrada
una fuente DC de 12V con una variación de ±10% de su
valor nominal.
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
a) Diseño del Inversor
El inversor a diseñar consta de cuatro transistores
dispuestos en una configuración conocida como puente H.
La figura 1 muestra la disposición de cuatro transistores
MOSFET canal N para la configuración de un puente H.
Figura 1. Configuración Puente, Imagen tomada de:
http://tesis.pucp.edu.pe/repositorio/bitstream/handle/123456
789/249/PORTUGAL_FERNANDEZ_EDGARDO_DISE%C
3%91O_INVERSOR_MULTINIVEL_MONOF%C3%81SIC
O.pdf?sequence=1
Fuente:
p-41
La tensión de salida alterna será tomada entre los
terminales “Vao” y “Vbo”. La tensión “Vab” se define
como la diferencia de la tensión “Vao” menos la tensión
“Vbo”. Esta tensión puede tomar tres valores “+Vcd”, “-
Vcd” y tensión igual a cero voltios.Cuando “Vab” toma el
valor de “+Vcd” los transistores “M1” y “M4” están
cortocircuitados y los transistores “M2” y “M3“ abiertos,
cuando toma el valor de “–Vcd“ los transistores “M2“ y
“M3“ están cortocircuitados y los transistores “M1“ y
“M4“ abiertos, para tomar el valor de tensión igual a cero
voltios existen dos opciones: “M3“ y “M4“
cortocircuitados y “M1“ y “M2“ abiertos, o, “M1“ y “M2“
cortocircuitados y “M3“ y “M4“ abiertos. Ambas opciones
permiten la circulación de corriente en ambos sentidos
cuando la tensión en el puente sea cero [1].
La activación de los transistores se realizará desde un
microcontrolador, permitiendo una precisión en los tiempos
de conmutación de los dispositivos semiconductores. Entre
cada transistor y el microcontrolador se requiere un circuito
que permita aislar eléctricamente las etapas de control y
potencia, este circuito es conocido como driver.
Para obtener a la salida del inversor una tensión de
120vrms, es decir Vmax= 170v, se requiere generar una
tensión en la entrada del puente del mismo nivel, por tal
razón la fuente DC debe ser capaz de suministrar una
tensión igual a ese valor (170vdc).
Para el diseño de este se usó un puente de IGBT inteligente,
al cual se le suministra un voltaje DC y las señales SPWM
para que este realice internamente la activación y
desactivación de los IGBT y mantenga a la salida un voltaje
120Vrms.
Fig.2 Diseño Circuital del Inversor
Fig.3 PCB del Inversor.
Fig.4 Montaje del Inversor
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
Las señales SPWM se generaron con un microcontrolador
PIC18F2550 utilizando lenguaje de programación
ensamblador.
b) Diseño de la Fuente DC de Alimentación
El diseño de la fuente DC de alimentación consiste en tres
etapas de convertidor boost, las primeras dos etapas
constaran de un control a laso abierto y la tercera etapa
dispondrá de un controlador PI el cual será el encargado de
mantener a la salida de esta un voltaje DC de 170v.
Diseño del Convertidor Boost- Etapa 1
La primera etapa se encargara de elevar el Vin=12v a
V1=34.65v.
Primero se debe establecer la relación de trabajo, para esto
se realiza el siguiente análisis:
Fig.5 Convertidor Boost-Etapa 1
Para S1=ON,S2=OFF:
Para S1=OFF,S2=ON:
Fig.6 Graficas VS1 y IS1
Fig.7 Graficas VS2 y IS2
Como , y
∫
Como y , se obtiene una D=0.65.
Para determinar el valor de la inductancia:
Como VS1=0; (
)
Haciendo y
Para una
Para determinar el valor del capacitor:
Para reducir el rizado de voltaje en la salida y la variación de
la corriente es constante
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
Para un
Diseño del Convertidor Boost- Etapa 2
Para construir la segunda etapa se realiza el mismo análisis,
teniendo en cuenta que ahora Vin= 34.65v y V2= 112.2v.
Fig. 8 Diseño del convertidor Boost- Etapa 2
Utilizando la Ec.1 y reemplazando los valores anteriormente
mencionados se obtiene una D=0.69.
Utilizando la Ec.2 y reemplazando se obtiene:
Para una
Utilizando la Ec.3 y utilizando un , , se obtiene:
Para un
Diseño del Convertidor Boost- Etapa 3
Del mismo modo utilizando las Ec.2 y Ec.3, se hallaron los
valores de L y C para esta etapa:
Para una
Fig.9 Diseño convertidor Boost- Etapa 3
Tabla.1 Valores de los componentes
Etap
as
Valores Calculados Valores Reales
Etap
a 1
L=0.156
mH
C=
L=
C=
Etap
a 2
L=1.30m
H
C=
L=1.5mH C=470
Etap
a 3
L=2.68m
H
C=
L=3mH C=55.68
Para realizar el control en lazo abierto para las dos primeras
etapas se hizo necesario generar una señal rampa para luego
compararla con un voltaje y de este modo se obtuvo la señal
PWM, que será la señal de control para S1 y S2.
Para generar la señal rampa hacemos uso del siguiente
circuito:
Fig.10 Circuito para generar señal rampa
En la Fig.8 se puede observar los pulsos del capacitor para
activar y desactivar el transistor NPN y obtener la señal
rampa.
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
Fig.11 Pulsos generados por el Capacitor
Fig.12 Señal rampa simulada
Fig.13 Señal rampa obtenida
Fig.14 Señal PWM obtenida para Etapa1 y Etapa2
Diseño del controlador:
Se implementó un control PI, el cual es el encargado de
mantener a la salida de la fuente DC un voltaje de 170v.
Fig.15 Controlador PI
Donde:
Gracias a la herramienta de sintonizacion proporcionada por
Matlab se obtienen los valores para Kp y Ki:
Como
Para el obtener el valor de las resistencias se asume que
R22=1K :
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
Una vez se obtenga la señal rampa y la señal de control,
estas deberán ser comparadas para obtener la señal PWM, la
cual será la encargada del encendido y apagado del
transistor S1.
Fig.16 Modulador PWM
Fig.17 Señal Modulada
REFERENCIAS
[1]http://tesis.pucp.edu.pe/repositorio/bitstream/ha
ndle/123456789/249/PORTUGAL_FERNANDEZ_
EDGARDO_DISE%C3%91O_INVERSOR_MUL
TINIVEL_MONOF%C3%81SICO.pdf?sequence=
1p-41
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
ANEXOS
;************************************************************
****** ;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 <18f47j53>
;include <18f45.inc>
processor 18F2550 LIST P = P18F2550
INCLUDE <P18f2550.INC>
CONFIG PLLDIV=5,CPUDIV=OSC1_PLL2,FOSC=HS;HSPLL_HS
CONFIG
PWRT=ON,BOR=OFF,WDT=OFF,MCLRE=On,LVP=OFF,DEBUG=OFF
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
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
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
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
;************************************************************
******
;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 PORTB ;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
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
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,PORTB
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
PO 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
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
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
UNIVERSIDAD FRANCISCO DE PAULA SANTANDER
FACULTAD DE INGENIERIAS – INGENIERIA ELECTROMECANICA
ELECTRONICA DE POTENCIA II
;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,0x9
6,0xA7,0xB7,0xC4,0xD0,0xD8,0xDD,0xDE
;*******************************************************************************
END