电机控制
DSP2833源程序如下:
- #include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
- #include "DSP2833x_Examples.h" // DSP2833x Examples Include File
- #include "clarke.h"
- #include"park.h"
- #include"ipark.h"
- #include"svgen_dq.h"
- #include"DSP2833x_EPwm.h"
- #include"IQmathLib.h"
- #include"F28335_epwm.h"
- Uint16 *ExRamStart = (Uint16 *)0x100000;
- //void EPwmSetup();
- #define SYSTEM_FREQUENCY 150
- #define ISR_FREQUENCY 10
- Uint16 i;
- float Vd_testing = 0; //直轴电压标幺值
- float Vq_testing = 0.25; //交轴电压标幺值
- float Id_ref = 0; //直轴电流给定,标幺值
- float Iq_ref = 0.025; //交轴电流给定,标幺值
- //volatile _iq speed_ref =_IQ(0.01); //速度给定,标幺值 电机速度=12000*speed_ref
- //volatile _iq position_ref =_IQ(0.0); //位置给定,标幺值 位置给定=50*position_ref
- extern PWMGEN pwm1;
- void main(void)
- {
- // Step 1. Initialize System Control:
- // PLL, WatchDog, enable Peripheral Clocks
- // This example function is found in the DSP2833x_SysCtrl.c file.
- InitSysCtrl();
- // Step 2. Initalize GPIO:
- // This example function is found in the DSP2833x_Gpio.c file and
- // illustrates how to set the GPIO to it's default state.
- // InitGpio(); // Skipped for this example
- InitXintf16Gpio(); //zq
-
- // Step 3. Clear all interrupts and initialize PIE vector table:
- // Disable CPU interrupts
- DINT;
- // Initialize the PIE control registers to their default state.
- // The default state is all PIE interrupts disabled and flags
- // are cleared.
- // This function is found in the DSP2833x_PieCtrl.c file.
- InitPieCtrl();
- // Disable CPU interrupts and clear all CPU interrupt flags:
- IER = 0x0000;
- IFR = 0x0000;
- // Initialize the PIE vector table with pointers to the shell Interrupt
- // Service Routines (ISR).
- // This will populate the entire table, even if the interrupt
- // is not used in this example. This is useful for debug purposes.
- // The shell ISR routines are found in DSP2833x_DefaultIsr.c.
- // This function is found in DSP2833x_PieVect.c.
- InitPieVectTable();
- IER |= M_INT3;
- // Enable EPWM INTn in the PIE: Group 3 interrupt 1-6
- PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
- // Enable global Interrupts and higher priority real-time debug events:
- EINT; // Enable Global interrupt INTM
- ERTM; // Enable Global realtime interrupt DBGM
- // Interrupts that are used in this example are re-mapped to
- // ISR functions found within this file.
- // Step 4. Initialize the Device Peripheral. This function can be
- // found in DSP2833x_CpuTimers.c
- // InitCpuTimers(); // For this example, only initialize the Cpu Timers
- // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
- // 150MHz CPU Freq, 1 second Period (in uSeconds)
- //ConfigCpuTimer(&CpuTimer0, 150, 1000000);
- //ConfigCpuTimer(&CpuTimer1, 150, 1000000);
- //ConfigCpuTimer(&CpuTimer2, 150, 1000000);
- // StartCpuTimer0();
-
- // EPwmSetup();
- pwm1.init(&pwm1);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
5956444spwm20170327.zip
(914.41 KB, 下载次数: 27)
|