版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、User C Programs in Power PMACMay 2011Priorities for C Programs in Power PMAC pare interrupt: Fast updating to/from PMAC3 ICPhase interrupt: “User-written phase” functionTypically for specialized commutation and current-loop algorithmsFor mutation tasks, use extra motorServo interrupt: “User-written
2、servo” functionTypically for specialized feedback and feedforward algorithmsFor non-servo tasks, use extra motorReal-time interrupt: “Real-time C PLC” functionEquivalent of Turbo PMAC PLCC0Each background scan: “Background C PLC” functionsCalled between each scan of one background Script PLC32 separ
3、ate programs (0 31), separately enabledGeneral-purpose operating system: C programs (applications)Run as programs (not called functions) on standard computerLinux GPOS allocates CPU time (when free from interrupt tasks)Creating C Routines and ProgramsPower PMAC IDE provides tool set for implementing
4、 C routinesProject manager to organize all C and Script softwareSmart text editor for writing software (or pasting in from other source)GNU C piler automatically invoked on project “build”In Project Managers “Solution Explorer”, expand “C language” branchFor user-written servo and/or phase, expand “
5、Realtime Routines”, then select “usrcode.c” for editing (multiple routines can be in this file)For RTI CPLC, expand “CPLCs” and “rticplc”, then select “rticplc.c” for editingFor background CPLCs, click on “CPLCs” and select program number (nn = 0 to 31) in resulting window, creating “bgcplcnn” subfo
6、lder and “bgcplcnn.c” file for editingFor background applications, expand “Background Programs”, and add your own files for editingTo compile and download code, right-click on project name, then select “Build and Download All Programs”IDE Support for C ProgrammingAccessing Shared Memory and Structur
7、esAll files with C code must start with “#include ”Header file provides access to shared-memory structuresAccess for both “real time” (interrupt-driven) and “general-purpose” (background) codeFunctions called by Power PMAC control code (user-written phase and servo, RTI and background CPLCs) automat
8、ically have access to several pre-defined pointerspshm: Pointer to SHM shared-memory data structurepiom: Pointer to I/O memory spacepushm: Pointer to user-defined buffer memory spaceIndependent background programs must declare variables for these pointersStructure elements are basically the same as
9、in the Script environmentCase-sensitive names in C (not in Script)No write-protection in C (but no access to many “internal” elements)Only full-word elements in I/O structuresC User-Written Servo RoutinesEach servo update period, every active motor calls its specified servo routine (built-in or user
10、-written) as functionEach motor can have its own routineCan provide own name(s) for user-written routine(s)Routine must return a “double” value for servo command outputMust be in range of +/-32,768.0Power PMAC will copy to output or use for commutationRoutine must accept a “MotorData” pointer as arg
11、umentPower PMAC will automatically pass pointer to present motors structurePermits same algorithm to be used unchanged for different motorsProvides access to several useful automatically computed floating-point valuesDesPos: Net desired position (trajectory + master)ActPos: Net actual position (incl
12、uding corrections)PosError: Following errorDesVel: Net desired velocityActVel: Net actual velocityC User-Written Servo Routines (cont.)Declare in form: “double MyServoAlg(struct MotorData *Mptr)”IDE creates declaration automatically from user-entered routine nameUser IDE Project Manager to tell whic
13、h motor(s) use this routineIn Solution Explorer, right-click on “Realtime Routines” under “C Language”Select “User Servo Setup” to get window to assign routines to motorsSets Motorx.Ctrl to UserAlgo.ServoCtrlAddriMultiple-motor servo algorithms can be implementedPermits sophisticated handling of dyn
14、amic cross-coupling effectsAlgorithm to be executed for lowest-numbered of consecutively-numbered motorsSet Motorx.ExtraMotors to number of additional motors handled hereCan access elements for additional motors in two ways:Relative addressing: Mptr2 = Mptr + 1Absolute addressing: pshm-Motor7Example
15、 User-Written Servo RoutineVery simple PID control algorithmUses Delta Tau-defined gain elements Kp, Kvfb, Kidouble user_pid_ctrl(struct MotorData *Mptr) double ctrl_effort; if (Mptr-ClosedLoop) / Servo active in closed loop? ctrl_effort = Mptr-Servo.Kp * Mptr-PosError - Mptr-Servo.Kvfb * Mptr-ActVe
16、l; / PD terms Mptr-Servo.Integrator += Mptr-PosError * Mptr-Servo.Ki;/ I term ctrl_effort += Mptr-Servo.Integrator;/ Combine return ctrl_effort;/ Return value for automatic handling else / Open loop mode Mptr-Servo.Integrator = 0.0;/ Clear integrator return 0.0;/ Zero output C User-Written Phase Rou
17、tinesEach phase update period, every motor with PhaseCtrl 0 calls its specified phase routine (built-in or user-written) as functionEach motor can have its own routineCan provide own name(s) for user-written routine(s)Routine must accept a “MotorData” pointer as argumentPower PMAC will automatically
18、 pass pointer to present motors structurePermits same algorithm to be used unchanged for different motorsCan use saved setup elements as for standard algorithmMust directly access I/O registersNo automatic pre/post-processing as for servoMust explicitly convert between fixed-point I/O and ( mended)
19、floating-point computationsHave access to Power PMACs floating-point math library, even though executing in the real-time kernelC User-Written Phase Routines (cont.)Must be declared in form: “void MyPhaseAlg(struct MotorData *Mptr)”IDE creates declaration automatically from user-entered routine name
20、Routine must write command values directly to output registersCan use address set by Motorx.pDac, as built-in routine does, e.g.:Mptr-pDac0 = PhaseACmd;Mptr-pDac1 = PhaseBCmd;User IDE Project Manager to tell which motor(s) use this routineIn Solution Explorer, right-click on “Realtime Routines” unde
21、r “C Language”Select “User Servo Setup” to get window to assign routines to motorsExample User-Written Phase RoutineSimple sine output commutation routine:void user_phase(struct MotorData *Mptr) int PresentEnc, PhaseTableOffset; float *SineTable; double DeltaEnc, PhasePos, IqVolts, IaVolts, IbVolts;
22、 PresentEnc = *Mptr-pPhaseEnc;/ Read new rotor position DeltaEnc = (double) (PresentEnc - Mptr-PrevPhaseEnc);/ Compute change and convert to floating-point Mptr-PrevPhaseEnc = PresentEnc;/ Store new rotor position for next cycle PhasePos = Mptr-PhasePos + Mptr-PhasePosSf * DeltaEnc;/ Scale change to
23、 sine table increments and accumulate if (PhasePos = 2048.0) PhasePos -= 2048.0;/ Positive rollover? PhaseTableOffset = (int) PhasePos;/ Table entry index Mptr-PhasePos = PhasePos;/ Store in structure for next cycle IqVolts = Mptr-IqCmd;/ Get torque (quadrature) command from servo output SineTable =
24、 Mptr-pVoltSineTable;/ Start address of lookup table IaVolts = IqVolts * SineTable(PhaseTableOffset + 512) & 2047;/ Compute Phase A command IbVolts = IqVolts * SineTable(PhaseTableOffset + Mptr-PhaseOffset + 512) & 2047;/ Compute Phase B command Mptr-pDac0 = (int) (IaVolts * 65536);/ Scale, fix, and
25、 output Phase A Mptr-pDac1 = (int) (IbVolts * 65536);/ Scale, fix, and output Phase BUsing Matlab/SimulinkTM for Servo DesignDesign algorithm graphically in SimulinkSimulate performance with plant model and excitation blockUse “scopes” to analysze performanceDebug and refine until ready to testUsing
26、 Matlab/SimulinkTM for Servo Design (cont.)Replace excitation block(s) and plant model with provided Power PMAC I/O blocks(One-time) installation of “DELTATAU PPMAC Library” in Simulink Library Browser(One-time) load of preset “Configuration Parameters”Invoke Real-Time WorkshopTM “Build Model” actio
27、nBring resulting “.c” and “.h” files into IDE, compile, and downloadSelecting User-Written Phase and ServoReal-Time Interrupt C PLC RoutineEach real-time interrupt (Sys.RtIntPeriod+1 servo interrupts), Power PMAC calls “realtimeinterrupt_plcc” routine if UserAlgo.RtiCplc = 1Note that if tasks from p
28、revious RTI are not finished, can “skip a beat”Routine must be in file rticplc.c in folder rticplc under CPLCs and C Language in projectRoutine must be declared as “void realtimeinterrupt_plcc()”Do not put within indefinite loop Power PMAC causes repeated execution by repeated callsUse a “sleep” fun
29、ction instead to suspendBackground C PLC RoutinesAfter each scan of one background Script PLC, Power PMAC calls each background C PLC routine n as function if its UserAlgo.BgCplcn = 1Up to 32 background C PLC routines (n = 0 to 31)Routine for C PLC n must be in file bgcplcnn.c in folder bgcplcnn und
30、er CPLCs and C Language in projectEach routine must be declared as “void user_plcc()” (routines are distinguished by file name and folder)These background C PLC routines are equivalent to background compiled PLC programs in Turbo PMACNext background Script PLC will not run until C PLCs are finished,
31、 or 100 sec later, whichever is lessDo not put within indefinite loop Power PMAC causes repeated execution by repeated callsUse a “sleep” function instead to suspendExample C PLC RoutineSample program to alternate outputs on UMAC I/O Card#include #include #include #define IoCard0Out0_7*(piom + 0 xA0000C/4)#define IoCard0Out8_15*(piom + 0 xA00010/4)#define IoCard0Out1
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 質量管理體系內(nèi)審程序及報告模板
- 肝炎防治基礎知識講座課件內(nèi)容
- 物流智能分揀系統(tǒng)建設方案書
- 高中英語閱讀專項訓練方案
- 酒店客房服務流程標準化培訓資料
- 塑料模具采購合同法律風險及注意事項
- 小學英語試卷結構分析報告
- 招聘流程優(yōu)化與人才選拔策略
- 部編版七年級語文下冊綜合復習資料
- 企業(yè)科技創(chuàng)新優(yōu)勢與風險評估報告
- 單位內(nèi)部化妝培訓大綱
- 河堤植草護坡施工方案
- 2025中國氫能源產(chǎn)業(yè)發(fā)展現(xiàn)狀分析及技術突破與投資可行性報告
- 高校行政管理流程及案例分析
- 高效節(jié)水灌溉方式課件
- 基坑安全工程題庫及答案解析
- 《人間充質基質細胞來源細胞外囊泡凍干粉質量要求》(征求意見稿)
- 2025年海南省中級經(jīng)濟師考試(工商管理專業(yè)知識和實務)能力提高訓練試題庫及答案
- 鄉(xiāng)鎮(zhèn)村監(jiān)會培訓課件
- 入團申請書教學課件
- 松下微波爐NN-DS581M使用說明書
評論
0/150
提交評論