6.2.1 軟體的實現
DSP程式中的工作主要是在各個中斷服務常式中執行,中斷的配置如圖6.2,共有 三個以計時器觸發的定時中斷,與一個由外部觸發的不定時中斷。透過RS232的與電腦 之間資料傳遞是在背景程式中進行,DSP接收資料時,該不定時中斷會被觸發。
兩個頻率為20 kHz定時中斷的其中之一負責讀取A/D轉換器的轉換結果;另一個20 kHz定時中斷的服務常式流程圖如圖6.3,負責執行無感測轉子角度估測演算法、根據 速度控制器的輸出結果產生各相電流命令以及電流控制器的運算,並利用電流控制器 的輸出產生PWM開關控制訊號。在此中斷服務常式中可選擇使用霍爾感測器訊號或以 無感測的方式所產生的正規化反抗電流勢波形調變相電流命令。
第三個定時中斷的頻率為2 kHz,服務常式流程圖如圖6.4所示,負責以霍爾感測器 訊號計算轉速,若為定位控制模式,還需計算轉子的累計旋轉角度。若在速度控制模 式下,可選擇以霍爾感測器訊號所得到的轉速或無感測轉速估測的結果做為速度回 授。當馬達轉速穩定後,提升馬達運轉效率的演算法亦包含在此服務常式中。
Background Process Communication Function
LED Display Function ISR c_int2( )
PWM Synchronization Rotor Position Estimation
Current Control
ISR c_int8( ) Rotor Speed Estimation
Speed Control Position Control Efficiency Upgrading
ISR c_int5( ) Receive RS232 Package
Periodic Interrupt
(20 kHz) Periodic Interrupt
(2 kHz) Aperiodic Interrupt
ISR c_int1( ) A/D Converter External Signal Sampling
Periodic Interrupt (20kHz)
圖6.2 DSP程式的中斷配置
PWM duty ratio limitation Servo ready?
Disable PWM output PWM output
no yes
RET Sensorless rotor
position estimation Sensorless rotor position estimation
ISR-2 Clear interrupt flags Reset watchdog timer
Read Hall signals and currents from A/D converter Read Hall signals and
currents from A/D converter
Hall signal or sensorless selection
Phase current command modulation
Phase current command modulation
Phase current controllers Phase current
controllers
圖6.3 內迴路控制之程式流程圖
Output current peak value command
Speed controller Speed controller
Sensorless speed estimation Sensorless speed
estimation Position control?
no yes
Efficiency upgrading Efficiency upgrading
ISR-8
RET Speed calculation using Hall signals Speed calculation using Hall signals
Speed_Hall or Speed_est selection
Record data for communication
Position controller Position controller
Sensorless speed control?
no
yes Rotation angle
accumulation Rotation angle
accumulation
Output for sensorless position estimation
'
KE
Output for sensorless position estimation
'
KE
圖6.4 外迴路控制之程式流程圖 6.2.2 數位化的數值考量
以數位的方式實現控制器與演算法時,由於處理器的字長(word length)有限,數值 的表示範圍與精確度之間往往無法兼顧,造成數位類比的轉換結果、數值的儲存、以 及數值運算的結果有誤差,此誤差稱為量化誤差(quantization error)。除此之外,若是 定點數運算的處理器,因無法儲存非整數的數值,程式設計者必須使用Q格式觀念。所
6.2.3 無感測演算法的實現
根據第四章與第五章所討論之演算法,可定出無感測演算法之程式流程圖如圖 6.5。無感測轉子角度估測是在頻率為20 kHz之中斷服務常式中執行的,因此圖6.5中的 T 等於est 5 10× −5秒。另外,由於本論文使用的是小型馬達,參數的尺度也相對的較小,
Flux increment estimation
( ) ( ) 0 0 ( ) 0 0 ( )
Back-EMF function table looking up
( )
Rotor position estimation
( 1 1 1 )
Current increment computation
( ) ( ) ( 1)
Back-EMF peak value estimation ˆ ˆr E
E=ω ⋅K
圖6.5 無感測轉子角度估測演算法之程式流程圖
0.494 H s( ) A/D 10-bit low-pass filter (2.2kHz) sensing
filter (2.2kHz) sensing normalization Inverse of
resistance Inverse of inductance
Speed_est > 0 ?
ea1(Q9) ec1(Q9)
eb1(Q9)
圖6.6 無感測轉子角度估測演算法定點數軟體實現架構方塊圖