43
自動控制工程學系專題製作 三相變頻器 A Three Phase DC-to-AC Inverter 指導教授:陳孝武 生:林士豪 李俊宏 陳建良 中華民國九十九年六月

三相變頻器 A Three Phase DC-to-AC Inverter · 器驅動系統而達成,由於數位控制的優點與軟體控制可根據應用狀況而作較大彈性 之修改,已逐漸的取代了以往類比式的變頻器而成為未來的主流[3]

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

  • 逢 甲 大 學

    自動控制工程學系專題製作

    專 題 論 文

    三相變頻器

    A Three Phase DC-to-AC Inverter

    指導教授:陳孝武

    學 生:林士豪

    李俊宏

    陳建良

    中華民國九十九年六月

  • 逢 甲 大 學

    自動控制工程學系專題製作

    專 題 論 文

    三相變頻器

    A Three Phase DC-to-AC Inverter

    學生:林士豪 李俊宏 陳建良 經專題口試合格特此證明

    評 審 委 員 指 導 教 授

    系 主 任

    考試日期:中華民國九十九年五月二十一日

  • i

    感謝

    在這一次的專題有很多的人在幫助我們,陳孝武老師教我們修改程式,還有

    電路的除錯。陳俊宏學長教我們操做實驗機台和 DSP 模擬器。還有一位實驗室

    學長,我們常常請教他電路圖的問題。在此願將專題的成果分享給所有關心我的

    朋友,家人,同學,謝謝大家。

  • ii

    中文摘要

    單晶片控制器具有電腦的計算能力和記憶能力,但與個人電腦比較,單晶片

    控制器的優點為其較輕、薄、短、小。TMS320C240為一個周邊功能相當完整的

    數位信號處理器 DSP,它在機電整合控制具有多方面的優點,尤其應用於馬達的

    伺服控制更是得心應手。[1]我們這一專題做的是三相變頻器,由光耦合器

    (TLP250),功率電晶體驅動 IC(IR2111),功率電晶體 (IRF640)再加上一些電

    容、電阻構成,光耦合器隔離 DSP 輸入電源和操作大電壓源, IR2111 產生上組

    (HO)同相波與下組(LO)反相波,控制功率電晶體是否導通。這些元件做出來的

    變頻器會很小,而且可以簡單的修改程式碼的數值達到三相交流電源頻率的變

    化。

  • iii

    Abstract

    Single chip control has the calculate ability of computer and memory ability.

    However ,compared with personal computer, the advantages of single chip control is

    quite slight ,thin ,short and small. Several signal processing unit DSP of

    TMS320C240 is a peripheral function to be equal to complete , it is to have advantage

    of many ways in mechatronic control , especially it is to apply server control of

    three-phase motor. Disquisition is server control of three-phase motor by mere

    coincidence device (TLP250),power transistor driver IC(IR2111),power

    transistor(IRF640) add some capacitance and resistance, mere coincidence device

    quarantine DSP input power source and operate big power source , IR2111 produce

    (HO) inphase waves and (LO) RP-wave, control power transistor conducting or not

    conducting . These elements made of circuits is small and they are easy to operate by

    DSP. Besides, it has characters of quiet having no noise , exemption from

    maintenance and it can be used for a long time AC server motor without brushes. It

    can be applied in many occasions.

  • iv

    感謝----------------------------------------------i

    中文摘要-----------------------------------------ii

    英文摘要----------------------------------------iii

    目錄---------------------------------------------iv

    圖目錄-------------------------------------------vi

    第一章 前言---------------------------------------1

    第二章 原理說明-----------------------------------2

    2.1 變頻器簡介---------------------------------2

    2.2 TMS320F240簡介------------------------------2

    2.2.1 PWM信號-----------------------------------2

    2.2.2 PWM信號產生-------------------------------3

    2.2.3 完全比較單元------------------------------5

    2.2.4 事件管理者之PWM輸出產生-------------------6

    第三章 數位訊號輸出程式---------------------------8

    3.1 流程圖--------------------------------------8

    3.2 程式----------------------------------------8

    第四章 電路分析-----------------------------------9

    4.1電路圖---------------------------------------9

    4.2 元件介紹------------------------------------10

  • v

    第五章 實驗結果----------------------------------14

    第六章 結論--------------------------------------16

    參考文獻----------------------------------------17

    附錄--------------------------------------------18

  • vi

    圖目錄

    圖 2-1 三相電晶體開關------------------------------3

    圖 2-2 PWM創造正弦波示意圖-------------------------4

    圖2-3 三相PWM波-----------------------------------4

    圖2-4 三相正弦波----------------------------------5

    圖 2-5完全比較單元方塊圖---------------------------5

    圖 2-6 PWM電路的方塊圖-----------------------------6

    圖 2-7完全比較單元之對稱 PWM波形產生---------------7

    圖 3-1程式流程圖-----------------------------------8

    圖 4-1電路圖---------------------------------------9

    圖 4-2 TLP250接腳圖-------------------------------10

    圖 4-3上面 DSP輸入波形;下面 TLP250輸出波形-------10

    圖 4-4 IR2111接腳圖-------------------------------11

    圖 4-5上面 Vin波形;下面 HO波形-------------------11

    圖 4-6上面 Vin波形;下面 LO波形-------------------12

    圖 4-7 IRF640接腳圖-------------------------------12

    圖 4-8 上面 LOAD波形;下面 DSP輸出波形-------------13

    圖 5-1三相變頻馬達控制電路------------------------14

    圖 5-2 Y 型負載波形-------------------------------14

  • vii

    圖 5-3 負載波形-----------------------------------15

  • 1

    第一章 前言

    1.1 研究動機及目的

    數位訊號處理器DSP(Digital Signal Process)已經常被應用於數位電源供應或

    馬達控制,DSP為單晶片(Single Chip)技術,單晶片控制器具有電腦的計算能力

    和記憶能力,但與個人電腦比較,單晶片控制器的優點為其較輕、薄、短、小。

    由於多數的微控制器和DSP已經內建了PWM控制器,因此很容易實現以數位訊號

    來控制類比電路。PWM是一種能將類比訊號準位編成數位碼的技術。透過高解析度的

    計數器,將一個方波的工作週期調變,藉此將特定的類比訊號準位編碼。PWM訊號仍

    然是數位的,因為在任何時候,直流供電不是開啟的就是關閉的。藉由連續的開啟

    和關閉脈衝,將電壓或電流供應給類比負載。在負載上有直流供電時稱為「開啟時

    間(on-time)」,沒有時稱為「關閉時間(off-time)」。

    DSP在控制馬達上使用相當廣泛,藉由程式的編寫可以方便達到控制伺服馬達

    或是步進馬達的效果,這次專題利用DSP加上變頻器電路,把直流電轉換成三相交流

    電,再修改程式的數值來達到變頻的效果。

  • 2

    第二章 原理說明

    2.1變頻器簡介

    台灣地區由於天然資源蘊藏貧乏,98%能源仰賴進口。在全球溫室效應,到了

    夏季轉為高溫晴朗型態,家在近年工商業持續成長,空調用電激增,夏季尖峰用電

    屢創新高,由於電源開發困難及短缺,將造成民眾生活的不便。因此如何推廣省能

    設備與提升能源效率的節約用電措施,已成國內能源政策的重要課題之ㄧ。

    在目前省能設備中「變頻器(Inverter)」為最直接有較之節能控制方法。如抄紙

    機、冷卻風扇;建築空調冷卻水塔風扇、空調箱AHU變風量、家用之洗衣機、冷氣機

    等。以上設備系統案例導入變頻器、控制設備負載大小運轉,證實可減少用電量。

    [2]

    由於近年來大型積體電路的快速發展,功率電子元件的進步,複雜的控制法則

    得以藉微處理器為基礎的軟體予以實現,使交流馬達的變速控制可藉由數位式變頻

    器驅動系統而達成,由於數位控制的優點與軟體控制可根據應用狀況而作較大彈性

    之修改,已逐漸的取代了以往類比式的變頻器而成為未來的主流[3]

    2.2 TMS320F240簡介

    TMS320F240為一個週邊功能相當完整的數位訊號處理器,數位訊號處理器其

    優點為運算處理能力快速,但是I/O方面的功能並非所長,而在TMS320F240之下I/O

    則做了補強與改進,同時他的匯流排架構是採用管線式(piper line)處理,雖同樣是

    16bit處理器,但他的執行速度可達20MIPS,適用於複雜的數學計算。以DSP快速的

    運算能力加上I/O功能,使用C語言或是組合語言來控制,在配上外部簡單電路整合,

    就可達到機電整合方面的控制,常被做馬達轉速控制。

    2.2.1 PWM信號

    脈波寬度調變(pulse–width–modulated,PWM)信號為一個具有可改變脈波寬度

    之串列脈波。在馬達控制系統中,PWM信號是控制電力到馬達開關設備的開合關時

  • 3

    間,提供馬達線圈不同大小、頻率的相電壓、相電流和能量,去控制馬達的轉速和

    轉矩。[4]

    2.2.2 PWM信號產生

    產生PWM信號,需要一個計時器以重複計數其周期值,也就是PWM周期,比

    較暫存器存有其調變值,比較暫存器之內含值將不斷與計時器之記數值做比較,當

    比較符合時,相對應之輸出腳位將發生轉態(由低準位至高準位或由高準位至低準

    位)。當第二次比較符合發生或達到計時器設定之週期值時,另一個轉態(由高準位

    至低準位或由低準位至高準位)將再度在輸出腳位發生。以此方式產生之PWM輸出

    脈波,其開(ON)與關(OFF)之期間正比於比較暫存器之內含值,因此若改寫比較暫

    存器之調變值,則PWM輸出脈波開與關期間之比例值也跟著改變。

    圖2-1 三相電晶體開關

  • 4

    圖2-2 PWM創造正弦波示意圖

    圖2-3 三相PWM波

  • 5

    圖2-4三相正弦波

    2.2.3 完全比較單元

    完全比較單元有兩種模式比較模式和PWM模式,可在COMCON位元設定

    圖2-5 完全比較單元方塊圖(x=1,2,3;y=1,3,5)

    在PWM模式下,任何一個完全比較單元皆能個別設定為PWM模式,完全比較單

    元的操作在PWM模式中纇似GP計時器比較操作,除了完全比較單元受控於不同的

    控制暫存器和可由停滯帶(dead-band)單元和空間向量PWM邏輯修改。[2]

  • 6

    圖2-6 PWM電路的方塊圖

    2.2.4 事件管理者之PWM輸出產生

    三組完全比較單元其中之任一與GP計時器1,停滯帶單元與EV模組輸出邏輯之

    結合可產生一組可程式停滯帶與輸出極性之PWM輸出,在EV模組內,三組完全比

    較單元有六個如上述之PWM之輸出。此六個輸出能使用在控制AC感應或無刷DC馬

    達。藉著完全比較動作控制暫存器(ACTR)之設定,此輸出腳位將更具有彈性之輸

    出,使其更易於控制切換是與同步式磁阻馬達,以應用在各種場合上。[2]

  • 7

    圖2-7 完全比較單元之對稱PWM波形產生(X=1,3或5)

  • 8

    第三章數位訊號輸出程式

    3.1 流程圖

    圖3-1 程式流程圖(x=1,2,3;y=1,3,5)

    3.2 程式(附錄1)

  • 9

    第四章 電路分析 4.1 電路圖

    圖4-1 電路圖

  • 10

    4.2 元件介紹

    4.2.1光耦合器(TLP250)

    圖4-2 TLP250接腳圖

    光耦合器(photo coupler)亦稱光耦合器(photo isolator),將發光元件與受光元件結

    合,用來傳遞訊號,發光體大部分使用高效率的砷化價鋁紅外線發光二極體,受光

    體則使用光電晶體,以光耦合器作為訊號轉換,可以達到電性完全隔離,電性的隔

    離可以阻止電路中產生雜訊或突波傳送到另一電路,除了可以避免雜訊影響電路動

    作外,也可以作為保護電路。

  • 11

    圖4-3 上面DSP輸入波形;下面TLP250輸出波形

    4.2.2 功率電晶體驅動IC(IR2111)

    圖4-4 IR2111接腳圖

    IR2111可用來驅動高壓功率MOS元件,IC特點僅需要一組電源即可驅動上組

    (HO)與下組(LO)功率元件開關,並具有dead time功能,可避免上下兩組功率元件同

    時導通狀況,因此在電路設計上可以精減許多並提高系統穩定度。

    4-5 上面Vin波形;下面HO波形

  • 12

    圖4-6 上面Vin波形;下面LO波形

    4.2.3 功率電晶體 (IRF640)

    圖4-7 IRF640接腳圖

    此IRF640最大操作電壓為200V,最大承載電流18A。必須注意閘極限流電阻的

    大小,當所需的現流電阻越小時,功率元件開 關的時間將減少,使功率元件操作溫

    度減低,若操作溫度過高時,則會有元件燒毀的現象,因此需額外增加散熱片在功

    率元件上,若閘極限流電阻較大時,則必須注意閘極限流電阻的功率損耗和功率元

    件散熱問題。

  • 13

    圖4-8 上面LOAD波形;下面DSP輸出波形

  • 14

    第五章 實驗結果

    圖5-1 三相變頻馬達控制電路

    右圖電路為輸入30V,輸出14V左右,再接至左圖電路,以執行控制馬達。

    圖5-2 Y型負載波形

  • 15

    圖5-3 Y型電路

  • 16

    第六章 結論 這次的專題,我們在負載端接Y型電路,測三點波形,一共有三相,相與相

    之間都差一百二十度,而使交流馬達轉動,在程式中改變omega數據,可改變頻

    率,而使馬達轉速不同。由於不同的轉速,馬達所消耗的電量也不同,轉速快

    耗電量大,反之轉速慢耗電小,當馬達不需要全功率負載時,可透過降低轉速

    來達到省電的效果。

  • 17

    參考文獻 [1] 黃英哲,董勝源編著, TMS320C240 原理與C語言控制應用實習 ,長高科技

    圖 ,民國91年8月

    [2]財團法人台灣綠色生產力基金會,變頻器應用Q&A 節能技術手冊,台北縣新店

    [3] 鄒應嶼,電動機控制簡介,國立交通大學電機工程系所電力電子實驗室,新竹

    市,民國89。

    [4] 襲應時、陳建武、徐永松編著,DSP 控制器原理與應用 ,滄海書局 ,民國 92

    年 8月

  • 18

    附錄

    附錄 1 ;*******************************************************************

    ; File Name: pwm1.asm

    ; Originator: Digital Control systems Apps group - Houston

    ; Target System: 'C240 Evaluation Board

    ;

    ; Description: Pulse Width Modulator - Sets up the registers

    ; for an asymmetric PWM output. The output is a

    ; square wave with a sine wave modulated duty cycle.

    ; PWM Period is 0.05ms => 20kHz

    ;

    ; Entering the command

    ; wa *FREQSTEP,,u

    ; Allows one to change the step size to change

    ; the frequency in the debugger environment

    ;

    ; Last Updated: 20 June 1997

    ;

    ;*******************************************************************

    .include f240regs.h

    ;-------------------------------------------------------------------

    ; Vector address declarations

    ;-------------------------------------------------------------------

    .sect ".vectors"

    RSVECT B START ; Reset Vector

    INT1 B PHANTOM ; Interrupt Level 1

    INT2 B t1uf_isr ; Interrupt Level 2

    INT3 B PHANTOM ; Interrupt Level 3

    INT4 B PHANTOM ; Interrupt Level 4

    INT5 B PHANTOM ; Interrupt Level 5

    INT6 B PHANTOM ; Interrupt Level 6

    RESERVED B PHANTOM ; Reserved

    SW_INT8 B PHANTOM ; User S/W Interrupt

    SW_INT9 B PHANTOM ; User S/W Interrupt

    SW_INT10 B PHANTOM ; User S/W Interrupt

    SW_INT11 B PHANTOM ; User S/W Interrupt

    SW_INT12 B PHANTOM ; User S/W Interrupt

    SW_INT13 B PHANTOM ; User S/W Interrupt

    SW_INT14 B PHANTOM ; User S/W Interrupt

    SW_INT15 B PHANTOM ; User S/W Interrupt

    SW_INT16 B PHANTOM ; User S/W Interrupt

    TRAP B PHANTOM ; Trap vector

    NMINT B PHANTOM ; Non-maskable Interrupt

    EMU_TRAP B PHANTOM ; Emulator Trap

  • 19

    SW_INT20 B PHANTOM ; User S/W Interrupt

    SW_INT21 B PHANTOM ; User S/W Interrupt

    SW_INT22 B PHANTOM ; User S/W Interrupt

    SW_INT23 B PHANTOM ; User S/W Interrupt

    ;===============================================================

    ====

    ; M A I N C O D E - starts here

    ;===============================================================

    ====

    .bss temp,1 ; temporary storage

    .bss one,1 ; +1

    .bss omega,1 ; set angular speed: D10

    .bss set_v,1 ; set voltage: D1

    .bss t_sample,1 ; sampling period: D-9

    .bss theta_h,1 ; phase of ref vector hi word: D3

    .bss theta_l,1 ; theta lo word

    .bss theta_r,1 ; rounded theta_h: D3

    .bss theta_m,1 ; theta mapped to 1st quadrant: D3

    .bss theta_i,1 ; theta to index for sine table: D6

    .bss SS,1 ; sin sign modification: D15

    .bss SC,1 ; cos sign modification: D15

    .bss sin_indx,1 ; index to sine table: D15

    .bss sin_entry,1 ; beginning of sin table

    .bss sin_end,1 ; end of sin table

    .bss sin_theta,1 ; sin(theta): D1

    .bss cos_theta,1 ; cos(theta): D1

    .bss Ud,1 ; voltage Ud: D2

    .bss Uq,1 ; voltage Uq: D2

    .bss theta_s,1 ; theta to sector mapping: D0

    .bss sector,1 ; sector reference U is in: D15

    .bss theta_90,1 ; 90: D3

    .bss theta_180,1 ; 180: D3

    .bss theta_270,1 ; 270: D3

    .bss theta_360,1 ; 360: D3

    .bss dec_ms,24 ; Decomposition matrices: D1

    .bss t1_periods,1 ; scaled Timer 1 period: D10

    .bss cmp_1,1 ; decomp on 1st basic sp vector: D15

    .bss cmp_2,1 ; decomp on 2nd basic sp vector: D15

    .bss cmp_0,1 ; decomp on 0 basic sp vector /2: D15

    .bss first_tog,1 ; the 1st-to-toggle channel

    .bss sec_tog,1 ; the 2nd-to-toggle channel

    .bss svpat,1 ; S/V pattern for ACTR

    ; Scaled sampling period

    ; Ts*D-9=Ts*2**24, Ts=50uS

    t_sample_ .set 0346h ; D-9

  • 20

    ; Conversion from theta to index for sine table

    ; 360/(0.5pi)*D8, D8=2**(15-8)=2**7 ; 360 entry sine table

    ; theta_i_ .set 29335 ; D8

    ; 90/(0.5pi)*D6, D6=2**9 ; 90 entry sine table

    theta_i_ .set 29335 ; D6

    ; Conversion from theta to sector

    ; 6/(2*pi)*D0, D0=2**(15-0)

    theta_s_ .set 31291 ; D0

    .text

    NOP

    START: SETC INTM ;Disable interrupts

    SPLK #0002h,IMR ;Mask all core interrupts except INT2

    LACC IFR ;Read Interrupt flags

    SACL IFR ;Clear all interrupt flags

    CLRC SXM ;Clear Sign Extension Mode

    CLRC OVM ;Reset Overflow Mode

    CLRC CNF ;Config Block B0 to Data mem

    ;-----------------------------------

    ; Set up PLL Module

    ;-----------------------------------

    LDP #00E0h

    ;The following line is necessary if a previous program set the PLL

    ;to a different ;setting than the settings which the application

    ;uses. By disabling the PLL, the CKCR1 register can be modified so

    ;that the PLL can run at the new settings when it is re-enabled.

    SPLK #0000000001000001b,CKCR0 ;CLKMD=PLL Disable SYSCLK=CPUCLK/2

    ; 5432109876543210

    SPLK #0000000010111011b,CKCR1 ;CLKIN(OSC)=10MHz,CPUCLK=20MHz

    ;CKCR1 - Clock Control Register 1

    ; Bits 7-4 (1011) CKINF(3)-CKINF(0) - Crystal or Clock-In Frequency = 10MHz

    ; Bit 3 (1) PLLDIV(2) - PLL divide by 2 bit Divide PLL input by 2

    ; Bits 2-0 (011) PLLFB(2)-PLLFB(0) - PLL multiplication ratio PLL Multiplication

    Ration = 4

    ; 5432109876543210

    SPLK #0000000011000001b,CKCR0 ;CLKMD=PLL Enable

    SYSCLK=CPUCLK/2

    ;CKCR0 - Clock Control Register 0

    ; Bits 7-6 (11) CLKMD(1),CLKMD(0) - Operational mode of

    ; Clock Module

    ; PLL Enabled; Run on CLKIN on exiting low

    ; power mode

    ; Bits 5-4 (00) PLLOCK(1),PLLOCK(0) - PLL Status.

    ; READ ONLY

    ; Bits 3-2 (00) PLLPM(1),PLLPM(0) - Low Power Mode

  • 21

    ; LPM0

    ; Bit 1 (0) ACLKENA - 1MHz ACLK Enable

    ; ACLK Disabled

    ; Bit 0 (1) PLLPS - System Clock Prescale Value

    ; f(sysclk)=f(cpuclk)/2

    ; 5432109876543210

    SPLK #0100000011000000b,SYSCR ;CLKOUT=CPUCLK

    ;SYSCR - System Control Register

    ; Bit 15-14 (01) RESET1,RESET0 - Software Reset Bits

    ; No Action

    ; Bits 13-8 (000000) Reserved

    ; Bit 7-6 (11) CLKSRC1,CLKSRC0 - CLKOUT-Pin Source Select

    ; CPUCLK: CPU clock output mode

    ; Bit 5-0 (000000)Reserved

    SPLK #006Fh, WDCR ;Disable WD if VCCP=5V (JP5 in pos. 2-3)

    KICK_DOG ;Reset Watchdog

    ;-----------------------------------

    ; Set up Digital I/O Port

    ;-----------------------------------

    LDP #225 ;DP=225, Data Page to Configure OCRA

    ; 5432109876543210

    SPLK #0011100000001111b,OCRA

    ;OCRA - Output Control Register A

    ; Bit # Name (CRA.n = 1) (CRA.n = 0)

    ; Bit 0 CRA.0 ADCIN0 IOPA0

    ; Bit 1 CRA.1 ADCIN1 IOPA1

    ; Bit 2 CRA.2 ADCIN9 IOPA2

    ; Bit 3 CRA.3 ADCIN8 IOPA3

    ; Bit 7-4 (1111) Reserved

    ; Bit 8 CRA.8 PWM7/CMP7 IOPB0

    ; Bit 9 CRA.9 PWM8/CMP8 IOPB1

    ; Bit 10 CRA.10 PWM9/CMP9 IOPB2

    ; Bit 11 CRA.11 T1PWM/T1CMP IOPB3

    ; Bit 12 CRA.12 T2PWM/T2CMP IOPB4

    ; Bit 13 CRA.13 T3PWM/T3CMP IOPB5

    ; Bit 14 CRA.14 TMRDIR IOPB6

    ; Bit 15 CRA.15 TMRCLK IOPB7

    ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

    ;- Event Manager Module Reset

    ;*

    ;- This section resets all of the Event Manager Module Registers.

    ;* This is necessary for silicon revision 1.1; however, for

    ;- silicon revisions 2.0 and later, this is not necessary

    ;*

    ;-

    ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • 22

    LDP #232 ;DP=232 Data Page for the Event Manager

    SPLK #0000h,GPTCON ;Clear General Purpose Timer Control

    SPLK #0000h,T1CON ;Clear GP Timer 1 Control

    SPLK #0000h,T2CON ;Clear GP Timer 2 Control

    SPLK #0000h,T3CON ;Clear GP Timer 3 Control

    SPLK #0000h,COMCON ;Clear Compare Control

    SPLK #0000h,ACTR ;Clear Full Compare Action Control Register

    SPLK #0000h,SACTR ;Clear Simple Compare Action Control Register

    SPLK #0000h,DBTCON ;Clear Dead-Band Timer Control Register

    SPLK #0000h,CAPCON ;Clear Capture Control

    SPLK #0FFFFh,EVIFRA;Clear Interrupt Flag Register A

    SPLK #0FFFFh,EVIFRB;Clear Interrupt Flag Register B

    SPLK #0FFFFh,EVIFRC;Clear Interrupt Flag Register C

    SPLK #0000h,EVIMRA ;Clear Event Manager Mask Register A

    SPLK #0000h,EVIMRB ;Clear Event Manager Mask Register B

    SPLK #0000h,EVIMRC ;Clear Event Manager Mask Register C

    ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

    ;- End of RESET section for silicon revision 1.1 *

    ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

    ;-----------------------------------

    ; Set up Event Manager Module

    ;-----------------------------------

    ; Set period

    t1_period_ .set 500 ; Tpwm/50nS/2=50uS/50nS/2=500

    t1_periods_ .set 500*32 ; D10, scaled Timer 1 period

    ;t2_period_ .set 1000 ;

    init_ev ldp #T1CMPR>>7 ; set DP

    splk #10,T1CMPR ; Init GPT comp registers

    ; splk #10,T2CMPR ;

    SPLK #t1_period_,T1PR ; Init GPT1 period reg

    ; SPLK #t2_period_,T2PR ; Init GPT2 period reg

    ; 2109876543210

    splk #0000001010101b,GPTCON

    ;GPTCON - GP Timer Control Register

    ; Bit 15 (0) T3STAT - GP Timer 3 Status. READ ONLY

    ; Bit 14 (0) T2STAT - GP Timer 2 Status. READ ONLY

    ; Bit 13 (0) T1STAT - GP Timer 1 Status. READ ONLY

    ; Bits 12-11 (00) T3TOADC - ADC start by event of GP Timer 3

    ; No event starts ADC

    ; Bits 10-9 (00) T2TOADC - ADC start by event of GP Timer 2

    ; No event starts ADC

    ; Bits 8-7 (00) T1TOADC - ADC start by event of GP Timer 1

    ; No event starts ADC

    ; Bit 6 (1) TCOMPOE - Compare output enable

    ; Enable all three GP timer compare outputs

  • 23

    ; Bits 5-4 (01) T3PIN - Polarity of GP Timer 3 compare output

    ; Active Low

    ; Bits 3-2 (01) T2PIN - Polarity of GP Timer 2 compare output

    ; Active Low

    ; Bits 1-0 (01) T1PIN - Polarity of GP Timer 1 compare output

    ; Active Low

    ; 5432109876543210

    SPLK #1010100000000010b,T1CON

    ;T1CON - GP Timer 1 Control Register

    ; Bits 15-14 (10) FREE,SOFT - Emulation Control Bits

    ; Operation is not affected by emulation suspend

    ; Bits 13-11 (001) TMODE2-TMODE0 - Count Mode Selection ?????? (101)

    ; Single up counting mode

    ; Bits 10-8 (000) TPS2-TPS0 - Input Clock Prescaler Divide by 1

    ; Bit 7 (0) Reserved in T1CON.

    ; Bit 6 (0) TENABLE - Timer Enable

    ; Disable timer operations

    ; Bits 5-4 (00) TCLKS1,TCLKS0 - Clock Source Select

    ; Internal Clock Source

    ; Bits 3-2 (00) TCLD1,TCLD0 - Timer Compare Register Reload Condition

    ; When counter is 0

    ; Bit 1 (1) TECMPR - Timer compare enable

    ; Enable timer compare operation

    ; Bit 0 (0) Reserved in T1CON.

    ; Set GPT1 in Up/Dn mode for symm PWM ?????

    ; 5432109876543210

    SPLK #0000000000000000b,T2CON

    ; Set GPT2 NOT USED

    ; 5432109876543210

    SPLK #0000000000000000b,T3CON

    ; Set GPT3 NOT USED

    SPLK #t1_period_,CMPR1 ; Init. PWM duty cycle to 0%

    SPLK #t1_period_,CMPR2

    SPLK #t1_period_,CMPR3

    ; 5432109876543210

    SPLK #0000011001100110b,ACTR ; Full Compare Action Control Register

    (ACTR)

    ; Bits 15-12 Used only in space-vector PWM output generation

    ; Bits 11-10 (01) PWM6 Active low

    ; Bits 9-8 (10) PWM5 Active high

    ; SPLK #01F4h,DBTCON ; Cfg deadband 1*32*50nS=1.6uS

    ; 5432109876543210

    SPLK #1000001000000111b,COMCON

    ; Enbl PWM outputs&cmp opera

    init_vars LDP #one>>7 ; Point to B1 page 0

    SPLK #1,one ; +1 => one

  • 24

    SPLK #11585,set_v ; 11585

    SPLK #t_sample_,t_sample ; sampling period

    SPLK #t1_periods_,t1_periods ; max compare value

    SPLK #0,theta_l ; theta low byte

    SPLK #0,theta_h ; theta high byte

    LAR AR0,#theta_90 ; point to 1st destination

    LAR AR1,#(28-1) ; 32 entries

    LACC #angles_ ; point to 1st data item

    LARP AR0 ;

    init_tbl TBLR *+,1 ; move and point to next destination

    ADD one ; point to next data item

    BANZ init_tbl,0

    splk #theta_i_,theta_i ; theta to sin_index ratio

    splk #theta_s_,theta_s ; theta to sector ratio

    SPLK #sin_entry_,sin_entry

    ; init 1st and last entries of sin tb

    SPLK #(sin_entry_+90),sin_end

    ; 5432109876543210

    LDP #EVIMRA>>7

    SPLK #0000000010000000b,EVIMRA ;Enables the T1PINT

    LDP #224 ;DP = 224 Data Page for ADC Registers

    ; 5432109876543210

    SPLK #1000110100000000b,ADCTRL1

    ; 5432109876543210

    SPLK #0000000000000101b,ADCTRL2

    LDP #232

    LACC T1CON

    OR #(B6_MSK)

    SACL T1CON

    ;Sets Bit 6 of T1CON

    ;T1CON - GP Timer 1 Control Register

    ; Bit 6 (1) TENABLE - Timer Enable

    ; Enable Timer Operations

    LDP #224

    LACC ADCTRL1

    OR #(B0_MSK)

    SACL ADCTRL1

    LDP #232

    SPLK #0FFFFh,EVIFRA ;Clear all pending interrupts

    SPLK #0080h,EVIMRA ;Enable Timer 1 Period Interrupt

    ; LDP #0

    CLRC INTM ;Enable interrupts

    END B END ;End of Program

    ;===============================================================

  • 25

    ====

    ; SV PWM routine

    ; The routine refers to the following variables:

    ; omega - set angular frequency with scale of D10 in unit of rad

    ; t_sample - sampling period with scale of D-9 in unit of second

    ; t1_period_ - T1 period, the maximum compare value

    ;-------------------------------------------------------------------

    t1uf_isr LDP #224 ;DP = 224 Data Page for ADC Registers

    ; ret

    LACC ADCTRL1 ;ACC = ADCTRL1 \ Clears the ADC Int

    SACL ADCTRL1 ;ADCTRL1 = ACC / flag if set

    LACC ADCFIFO1 ;Load the converted value

    ; RPT #7 ;Shift the value to the right 7 times

    ;SFR ;since 6 LSBs are always 0

    ;-------------------------------------------------------------------

    ; Generate revolving voltage vector Uout=trans(Ud Uq)

    ;-------------------------------------------------------------------

    ;LDP #100h ; DP = (256)

    ; SACL FREQSTEP

    ldp #omega>>7 ; Integrate speed to get phase

    sacl omega

    splk #6F00h,omega

    LT omega ; set W -> T: D10

    MPY t_sample ; D10*D-9=D(1+1)

    PAC ; product -> ACC: D2

    SFR ; -> D3

    ADDH theta_h ; D3+D3=D3 (32 bit)

    ADDS theta_l ;

    SACH theta_h ; save

    SACL theta_l ;

    chk_lolim bcnd chk_uplim,GEQ ; check upper limit if positive

    ADDH theta_360 ; D3+D3=D3, rollover if not

    SACH theta_h ; save

    B rnd_theta ;

    chk_uplim SUBH theta_360 ; D3-D3=D3 compare with 2*pi

    bcnd rest_theta,LEQ ; resume theta_h if within limit

    SACH theta_h ; rollover if not

    B rnd_theta ;

    rest_theta ADDH theta_360 ; resume theta high

    rnd_theta ADD #1,15 ; round up to upper 16 bits

    SACH theta_r ;

    ;-------------------------------------------------------------------

    ; Quadrant mapping

    ;-------------------------------------------------------------------

    LACC one ; assume theta (theta_h) is in

    ; quadrant 1

  • 26

    SACL SS ; 1=>SS, sign of SIN(theta)

    SACL SC ; 1=>SC, sign of COS(theta)

    LACC theta_r ;

    SACL theta_m ; theta=>theta_m

    SUB theta_90 ;

    BLEZ E_Q ; jump to end if 90>=theta

    ; assume theta (theta_h) is in quadrant 2

    splk #-1,SC ; -1=>SC

    LACC theta_180 ;

    SUB theta_r ; 180-theta

    SACL theta_m ; =>theta_m

    BGEZ E_Q ; jump to end if 180>=theta

    ; assume theta (theta_h) is in quadrant 3

    splk #-1,SS ; -1=>SS

    LACC theta_r ;

    SUB theta_180 ; theta-180

    SACL theta_m ; =>theta_m

    LACC theta_270 ;

    SUB theta_r ;

    BGEZ E_Q ; jump to end if 270>=theta

    ; theta (theta_h) is in quadrant 4

    splk #1,SC ; 1=>SC

    LACC theta_360 ;

    SUB theta_r ;

    SACL theta_m ; 360-theta_h=>theta_m

    E_Q

    ;-------------------------------------------------------------------

    ; sin(theta), cos(theta)

    ;-------------------------------------------------------------------

    lt theta_m ; D3. Find index

    mpy theta_i ; D3*D6=D(9+1)

    pac ; D10

    sach sin_indx ; D10

    lacc sin_indx,11 ; r/s 5 by l/s 11 -> integer (D15)

    sach sin_indx ; right shift 5 bits => D15

    lacc sin_entry ; Look up sin

    add sin_indx ;

    tblr sin_theta ;

    lacc sin_end ;

    sub sin_indx ;

    tblr cos_theta ;

    LT SS ; Look up cos

    MPY sin_theta ; modify sign: D15*D1=D(16+1)

    PAC ;

    SACL sin_theta ; left shift 16 bits and save: D1

    LT SC ;

  • 27

    MPY cos_theta ; modify sin: D15*D1=D(16+1)

    PAC ;

    SACL cos_theta ; left shift 16 bits and save: D1

    ;-------------------------------------------------------------------

    ; The following 4 lines are for purpose of debugging

    ;-------------------------------------------------------------------

    ; lacc sin_theta,10 ;

    ; add #04000h,10 ; Add 1

    ; ldp #T2CMPR>>7 ;

    ; sach T2CMPR ; save to T2CMPR for debug

    ;-------------------------------------------------------------------

    ; Calcualte Ud & Uq

    ;-------------------------------------------------------------------

    LT set_v ; set v -> T: D1

    MPY cos_theta ; set v*cos(theta): D1*D1=D(2+1)

    PAC ; product -> ACC: D3

    SACH Ud,1 ; d component of ref Uout: D2

    MPY sin_theta ; set v*sin(theta): D1*D1=D(2+1)

    PAC ; product -> ACC: D3

    SACH Uq,1 ; q component of ref Uout: D2

    ;-------------------------------------------------------------------

    ; Determine sector

    ;-------------------------------------------------------------------

    lt theta_r ; D3

    mpy theta_s ; D3*D0=D4

    pac

    sach sector ;

    lacc sector,5 ; r/s 11 by l/s 5 -> integer (D15)

    sach sector ; right shift 11 bits

    ;-------------------------------------------------------------------

    ; Calculate T1&T2 based on: Tpwn Uout=V1*T1+V2*T2

    ;

    ; i.e. [T1 T2]=Tpwn*inverse[V1 V2]*Uout

    ; i.e. [0.5*T1 0.5*T2]=Tp*inverse[V1 V2]*Uout

    ; i.e. [0.5*C1 0.5*C2]=inverse[V1 V2]*Uout=M(sector)*Uout

    ;

    ; where C1=T1/Tp, C2=T2/Tp, are normalized wrt Tp

    ; M(sector)=inverse of [V1 V2] = decomposition matrix

    ; obtained through table lookup

    ; Uout=Transpose of [Ud Uq]

    ; Tp=Timer 1 period = 0.5*Tpwm

    ; Tpwm=PWM period Tpwm

    ;-------------------------------------------------------------------

    LACC #dec_ms

    ADD sector,2 ;

    SACL temp ; get the pointer

  • 28

    LAR AR0,temp ; point to parameter table

    ; Calculate 0.5*C1 based on 0.5*C1=Ud*M(1,1)+Uq*M(1,2)

    LT Ud ; D2

    MPY *+ ; M(1,1) Ud: D2*D1=D(3+1)

    PAC ; D4

    LT Uq ; D4

    MPY *+ ; M(1,2) Uq: D2*D1=D(3+1)

    APAC ; 0.5*C1: D4+D4=D4

    BGEZ cmp1_big0 ; continue if bigger than zero

    ZAC ; set to 0 if less than 0

    cmp1_big0 SACH temp ; 0.5*C1: D4

    LT temp ; D4

    MPY t1_periods ; D4*D10 = D(14+1)

    PAC ; D15

    ; .if SVPAT=HWPAT

    ; ADD one,16 ; Avoid C1=0

    ; .endif

    SACH cmp_1 ; 0.5*C1*Tp: D15

    ; Calculate 0.5*C2 based on 0.5*C2=Ud*M(2,1)+Uq*M(2,2)

    LT Ud ; D2

    MPY *+ ; M(2,1) Ud: D2*D1=D(3+1)

    PAC ; D4

    LT Uq ; D2

    MPY *+ ; M(2,2) Uq: D2*D1=D(3+1)

    APAC ; 0.5*C2: D4+D4=D4

    BGEZ cmp2_big0 ; continue if bigger than zero

    ZAC ; zero it if less than zero

    cmp2_big0 SACH temp ; 0.5*C2: D4

    LT temp ; D4

    MPY t1_periods ; D4*D10 = D(14+1)

    PAC ; D15

    ; .if SVPAT=HWPAT

    ; ADD one,16 ; Avoid 0 C2 = 0

    ; .endif

    SACH cmp_2 ; 0.5*C2*Tp: D15

    ; Calculate 0.5*C0 based on 0.5*C3*Tp=Tp*(1-0.5*C1-0.5*C2)

    LACC #t1_period_ ;

    SUB cmp_1 ;

    SUB cmp_2 ; D15

    BGEZ cmp0_big0 ; continue if bigger than zero

    ZAC ; zero it if less than zero

    cmp0_big0 SACL cmp_0 ;

    LACC cmp_0,15 ; right shift 1b (by l/s 15b)

    SACH cmp_0 ; 0.25*C0*Tp

    ; .if SVPAT=HWPAT

    ;-------------------------------------------------------------------

  • 29

    ; Determine the ACTR pattern and reload ACTR and CMPR1&2

    ;-------------------------------------------------------------------

    ; LACC #cckwise_

    ; ADD sector ; point to entry in lookup table

    ; TBLR svpat ; get the pattern

    ; LAR AR0,#ACTR ; point to ACTR

    ; LACC * ; Read ACTR

    ; AND #0FFFh ; Clear sv pattern bits

    ; OR svpat ; Re-configure sv pattern bits

    ; SACL * ; Re-load ACTR

    ; LAR AR0,#CMPR1 ; point to CMPR1

    ; LACC cmp_1 ;

    ; SACL *+ ; cmp_1=>CMPR1, point to CMPR2

    ; ADD cmp_2 ;

    ; SACL * ; cmp_2=>CMPR2

    ; SUB #t1_period_ ; limit CMPR2

    ; BLEZ in_lmt ;

    ; SPLK #t1_period_,*

    ;in_lmt

    ; .endif

    ; .if SVPAT=SWPAT

    ;-------------------------------------------------------------------

    ; Determine channel toggling sequence and load compare registers

    ;-------------------------------------------------------------------

    LACC #first_ ;

    ADD sector ; point to entry in look up table

    TBLR first_tog ; get 1st-to-toggle channel

    LAR AR0,first_tog ; point to the channel

    LACC cmp_0 ;

    SACL * ; cmp_0 => the channel

    LACC #second_ ;

    ADD sector ; point to entry in look up table

    TBLR sec_tog ; get 2nd-to-toggle channel

    LAR AR0,sec_tog ; point to the channel

    LACC cmp_0 ;

    ADD cmp_1 ; cmp_0+cmp_1

    SACL * ; => the channel

    LACC #CMPR3 ;

    SUB first_tog ;

    ADD #CMPR2 ;

    SUB sec_tog ;

    ADD #CMPR1 ;

    SACL temp ; get 3rd-to-toggle channel

    LAR AR0,temp ; point to the channel

    LACC cmp_0 ;

    ADD cmp_1 ;

  • 30

    ADD cmp_2 ; cmp_0+cmp_1+cmp_2

    SACL * ; =>the channel

    LDP #232 ; DP = 232

    LACC EVIFRA ; ACC = EVIFRA

    SACL EVIFRA ; EVIFRA = ACC; resets the interrupt flag

    CLRC INTM ; Enable core interrupts

    ; .endif

    ; ldp #PCDATDIR>>7 ; set DP

    ; lacc PCDATDIR ;

    ; or #00008h ; IOPC[3] to 1

    ; sacl PCDATDIR ;

    RET ; return

    .data

    ;-------------------------------------------------------------------

    ; Frequently used angles

    ;-------------------------------------------------------------------

    ********************************************************************

    ** The order between these angles and the decomposition **

    ** matrices in the following must not be changed. **

    ********************************************************************

    angles_ .WORD 01922h ; pi/2: D3

    .WORD 03244h ; pi: D3

    .WORD 04b66h ; 3*pi/2: D3

    .WORD 06488h ; 2*pi: D3

    ; .if SVPAT=SWPAT

    ;-------------------------------------------------------------------

    ; Decomposition matrices indexed by the sector Uout is in for s/w

    ; implemented SV PWM scheme

    ;-------------------------------------------------------------------

    .WORD 20066 ; D1

    .WORD -11585

    .WORD 0

    .WORD 23170

    .WORD -20066

    .WORD 11585

    .WORD 20066

    .WORD 11585

    .WORD 0

    .WORD 23170

    .WORD -20066

    .WORD -11585

    .WORD 0

    .WORD -23170

    .WORD -20066

    .WORD 11585

  • 31

    .WORD -20066

    .WORD -11585

    .WORD 20066

    .WORD -11585

    .WORD 20066

    .WORD 11585

    .WORD 0

    .WORD -23170

    ; .endif

    ; .if SVPAT=HWPAT

    ;-------------------------------------------------------------------

    ; Decomposition matrices indexed by the sector Uout is in for h/w

    ; implemented SV PWM scheme

    ;-------------------------------------------------------------------

    ; .WORD 20066 ; D1

    ; .WORD -11585

    ; .WORD 0

    ; .WORD 23170

    ; .WORD 20066

    ; .WORD 11585

    ; .WORD -20066

    ; .WORD 11585

    ; .WORD 0

    ; .WORD 23170

    ; .WORD -20066

    ; .WORD -11585

    ; .WORD -20066

    ; .WORD 11585

    ; .WORD 0

    ; .WORD -23170

    ; .WORD -20066

    ; .WORD -11585

    ; .WORD 20066

    ; .WORD -11585

    ; .WORD 0

    ; .WORD -23170

    ; .WORD 20066

    ; .WORD 11585

    ; .endif

    ; .if SVPAT=SWPAT

    ;-------------------------------------------------------------------

    ; Addresses of compare registers of the 1st-to-toggle channels

    ; indexed by the sector, ref v is in

    ;-------------------------------------------------------------------

    first_ .WORD CMPR1 ;

    .WORD CMPR2 ;

  • 32

    .WORD CMPR2 ;

    .WORD CMPR3 ;

    .WORD CMPR3 ;

    .WORD CMPR1 ;

    ;-------------------------------------------------------------------

    ; Addresses of compare registers of the 2nd-to-toggle channels

    ; indexed by the sector, ref v is in

    ;-------------------------------------------------------------------

    second_ .WORD CMPR2 ;

    .WORD CMPR1 ;

    .WORD CMPR3 ;

    .WORD CMPR2 ;

    .WORD CMPR1 ;

    .WORD CMPR3 ;

    ; .endif

    ; .if SVPAT=HWPAT

    ;-------------------------------------------------------------------

    ; Lookup table for ACTR[15-12] indexed by sector number

    ;-------------------------------------------------------------------

    ;cckwise_ .WORD 0001000000000000b

    ; .WORD 0011000000000000b

    ; .WORD 0010000000000000b

    ; .WORD 0110000000000000b

    ; .WORD 0100000000000000b

    ; .WORD 0101000000000000b

    ; .endif

    ;-----------------------------------------------------------

    ; sine table for theta from 0 to 90 per every 1 degree

    ;-----------------------------------------------------------

    sin_entry_ ; sin table

    .WORD 0 ; D1

    .WORD 286

    .WORD 572

    .WORD 857

    .WORD 1143

    .WORD 1428

    .WORD 1713

    .WORD 1997

    .WORD 2280

    .WORD 2563

    .WORD 2845

    .WORD 3126

    .WORD 3406

    .WORD 3686

    .WORD 3964

    .WORD 4240

  • 33

    .WORD 4516

    .WORD 4790

    .WORD 5063

    .WORD 5334

    .WORD 5604

    .WORD 5872

    .WORD 6138

    .WORD 6402

    .WORD 6664

    .WORD 6924

    .WORD 7182

    .WORD 7438

    .WORD 7692

    .WORD 7943

    .WORD 8192

    .WORD 8438

    .WORD 8682

    .WORD 8923

    .WORD 9162

    .WORD 9397

    .WORD 9630

    .WORD 9860

    .WORD 10087

    .WORD 10311

    .WORD 10531

    .WORD 10749

    .WORD 10963

    .WORD 11174

    .WORD 11381

    .WORD 11585

    .WORD 11786

    .WORD 11982

    .WORD 12176

    .WORD 12365

    .WORD 12551

    .WORD 12733

    .WORD 12911

    .WORD 13085

    .WORD 13255

    .WORD 13421

    .WORD 13583

    .WORD 13741

    .WORD 13894

    .WORD 14044

    .WORD 14189

    .WORD 14330

  • 34

    .WORD 14466

    .WORD 14598

    .WORD 14726

    .WORD 14849

    .WORD 14968

    .WORD 15082

    .WORD 15191

    .WORD 15296

    .WORD 15396

    .WORD 15491

    .WORD 15582

    .WORD 15668

    .WORD 15749

    .WORD 15826

    .WORD 15897

    .WORD 15964

    .WORD 16026

    .WORD 16083

    .WORD 16135

    .WORD 16182

    .WORD 16225

    .WORD 16262

    .WORD 16294

    .WORD 16322

    .WORD 16344

    .WORD 16362

    .WORD 16374

    .WORD 16382

    .WORD 16384

    .text

    PHANTOM KICK_DOG ;Resets WD counter

    B PHANTOM