/************** GLOBAL DEFINITIONS ***********/
#define INITIALIZE
#include "general.h"
#include "Parms.h"
#include "SVGen.h"
#include "ReadADC.h"
#include "MeasCurr.h"
#include "Control.h"
#include "PI.h"
#include "Park.h"
#include "UserParms.h"
#include "smcpos.h"
#include "FdWeak.h"
// DSPIC33FJ32MC202 Configuration Bit Settings
// 'C' source line config statements
#include <xc.h>
// FBS
#pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_FLASH // Boot Segment Program Flash Code Protection (No Boot program Flash segment)
// FGS
#pragma config GWRP = OFF // General Code Segment Write Protect (User program memory is not write-protected)
#pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected)
// FOSCSEL
#pragma config FNOSC = FRCPLL // Oscillator Mode (Internal Fast RC (FRC) w/ PLL)
#pragma config IESO = OFF // Internal External Switch Over Mode (Start-up device with user-selected oscillator source)
// FOSC
#pragma config POSCMD = NONE // Primary Oscillator Source (Primary Oscillator Disabled)
#pragma config OSCIOFNC = OFF // OSC2 Pin Function (OSC2 pin has clock out function)
#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow Only One Re-configuration)
#pragma config FCKSM = CSECMD // Clock Switching and Monitor (Clock switching is enabled, Fail-Safe Clock Monitor is disabled)
// FWDT
#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config WDTPRE = PR128 // WDT Prescaler (1:128)
#pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog timer enabled/disabled by user software)
// FPOR
#pragma config FPWRT = PWR128 // POR Timer Value (128ms)
#pragma config ALTI2C = OFF // Alternate I2C pins (I2C mapped to SDA1/SCL1 pins)
#pragma config LPOL = ON // Motor Control PWM Low Side Polarity bit (PWM module low side output pins have active-high output polarity)
#pragma config HPOL = OFF // Motor Control PWM High Side Polarity bit (PWM module high side output pins have active-high output polarity)
#pragma config PWMPIN = ON // Motor Control PWM Module Pin Mode bit (PWM module pins controlled by PORT register at device Reset)
// FICD
#pragma config ICS = PGD3 // Comm Channel Select (Communicate on PGC3/EMUC3 and PGD3/EMUD3)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is Disabled)
/************** END OF GLOBAL DEFINITIONS ***********/
SMC smc1 = SMC_DEFAULTS; // Variable structure used for slide mode observer.
unsigned long Startup_Ramp = 0; // Start up ramp in open loop.
unsigned int Startup_Lock = 0; // LOCK_TIME counter
unsigned char OpenLoop_Flag; // Indicates if motor is running in open or closed loop
unsigned char RunMotor_Flag; // If motor is running, or stopped.
unsigned char ChangeMode_Flag; // Change mode flag
unsigned char EnVoltRipCo_Flag; // voltage ripple compensation
tPIParm PIParmD; // Structure definition for Flux component of current, or Id
tPIParm PIParmQ; // Structure definition for Torque component of current, or Iq
tPIParm PIParmW; // Structure definition for Speed, or Omega
tReadADCParm ReadADCParm; // Struct used to read ADC values.
// Speed Calculation Variables
int16 PrevTheta = 0; // Previous theta
int16 AccumTheta = 0; // Accumulates delta theta over a number of times
WORD AccumThetaCnt = 0; // Counter used to calculate motor speed.
// Vd and Vq vector limitation variables
int16 qVdSquared = 0;
int16 DCbus = 0; // DC Bus measured continuously
int16 TargetDCbus = 0; // DC Bus is measured before running motor
int16 Theta_error = 0; // This value is used to transition from open loop to closed loop.
// Single shunt three phase reconstruction algorithm variables
int16 SEVTCMP_First = 0; // This variable holds the first trigger
int16 SEVTCMP_Second = 0; // Variable holding the second trigger value
int16 Sector = 0; // Variable indicating the active sector
int16 Ia = 0; // Reconstructed value for Ia
int16 Ib = 0; // Reconstructed value for Ib
int16 Ic = 0; // Reconstructed value for Ic
int16 Ibus = 0; // Measured value through single shunt resistor
int16 tcrit = 0; // variable used to create minimum window
int16 deadtime = 0;
int16 T1 = 0;
int16 T2 = 0;
int16 Ta = 0;
int16 Tb = 0;
int16 Tc = 0;
int16 T1Comp = 0;
int16 T2Comp = 0;
float InitialTorque = 0;
signed int g_for_debug1;
short g_for_debug2;
int16 HighPeriod = 0; //low period of InputPwm
int16 LowPeriod = 0; //high period of InputPwm
int16 DutycycleFinal = 0; //InputPwm dutycycle
int16 SpeedRef = 0; //speed reference
int16 DutycycleFilter = 0;
int16 PeriodCounter; // counter for InputPwm period in PWMInterrupt()
uint16 CounterFor100ms; // counter for 100ms in PWMInterrupt()
uint16 Velocity_Ref; // used in PwmCurveCalculate()
uint8 PwminHighFlag;
uint8 PwminLowFlag;
uint8 StartWaitCounter; // wait for sometime before start
uint8 StopWaitCounter; // wait for sometime before stop
uint8 PwminRecoverCounter; // Pwmin recover counter
/*********************** main Routine ***********************/
int main (void)
{
/***********************************************************
* set up the oscillator and PLL for 40 MIPS
* Fosc = Fin*(M/(N1*N2)) = (7.37*43)/(2*2) = 80MHz
* Fcy = Fosc / 2 = 40MIPS
***********************************************************/
PLLFBD = 41; //PLL倍频比M = 41+2
CLKDIVbits.PLLPOST = 0; //N1=2
CLKDIVbits.PLLPRE = 0; //N2=2
OSCTUN = 0; //7.37MHz
__builtin_write_OSCCONH(0x01); //带PLL的FRC
__builtin_write_OSCCONL(0x01); //振荡器切换时
while(OSCCONbits.COSC != 0b001); //等待当前振荡器切换至"带PLL的FRC振荡器"
while(OSCCONbits.LOCK != 1); //Wait for PLL to lock
/***********************************************************/
SMCInit(&smc1);
SetupPorts();
SetupControlParameters();
FWInit();
while(1)
{
Nop();
// Make sure ADC does not generate interrupts while parameters are being initialized
IEC0bits.AD1IE = 0;
// zero out i sums
PIParmD.qdSum = 0;
PIParmQ.qdSum = 0;
PIParmW.qdSum = 0;
InitialTorque = 0;
SetupParm(); // Init user parameters
OpenLoop_Flag = 1;
ChangeMode_Flag = 1;
RunMotor_Flag = 0;
PORTAbits.RA2 = 1; // Enable TLE7184F
IEC0bits.AD1IE = 1; // Enable adc Interrupt
while(1)
{
Nop();
if(CounterFor100ms >= 4000) //(Per 100ms)
{
//PORTAbits.RA4= !PORTAbits.RA4;
CounterFor100ms = 0;
if(StartWaitCounter <= 12) //First Start,wait for pwmin filter
StartWaitCounter++;
if((PeriodCounter > 10000) && (PwminHighFlag == 0))
{
PwminHighFlag = 1;
PwminRecoverCounter = 0;
PeriodCounter = 0;
}
DutycycleFinal = FracDiv(HighPeriod, HighPeriod + LowPeriod + 1);// (0-100%) --> (0-32768)
if(PwminHighFlag)
SpeedRef = 16000;
没有合适的资源?快使用搜索试试~ 我知道了~
PMSM.rar_PMSM 控制_foc_him8bc_pmsm control_pmsm foc
共88个文件
o:27个
d:14个
h:11个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 193 浏览量
2022-09-15
01:08:30
上传
评论
收藏 306KB RAR 举报
温馨提示
调节PMSM的速度。FOC控制方式。Microchip方案
资源推荐
资源详情
资源评论
收起资源包目录
PMSM.rar (88个子文件)
PMSM
MeasCurr.o 23KB
smc.s 5KB
control.h 262B
FdWeak.c 3KB
MeasCurr.inc 122B
pi.s 3KB
PI.inc 252B
InvPark.s 1KB
svgen.h 628B
main.c 24KB
park.h 643B
pi.o 22KB
trig.s 5KB
general.inc 33B
smcpos.o 100KB
clrkpark.s 2KB
ReadADC0.s 788B
smc.o 25KB
CalcRef.s 1KB
InvPark.o 22KB
PMSM.X
PMSM.X.debug.map 119KB
PMSM.X.production.map 119KB
dist
default
production
PMSM.X.production.hex 28KB
PMSM.X.production.cof 678KB
nbproject
Package-default.bash 1KB
Makefile-impl.mk 2KB
configurations.xml 14KB
Makefile-local-default.mk 2KB
private
private.xml 343B
configurations.xml 1KB
Makefile-variables.mk 411B
project.xml 737B
Makefile-default.mk 24KB
Makefile-genesis.properties 458B
debug
default
Makefile 3KB
build
default
production
_ext
1472
CalcRef.o.d 82B
MeasCurr.o 20KB
MeasCurr.o.d 124B
atan2CORDIC.o.d 73B
main.o.d 237B
pi.o 20KB
smcpos.o 92KB
smc.o 22KB
InvPark.o 20KB
ReadADC0.o.d 106B
FdWeak.o 92KB
initdspic.o.d 106B
svgen_ss.o 94KB
clrkpark.o 20KB
smcpos.o.d 116B
trig.o 21KB
FdWeak.o.d 132B
InvPark.o.d 101B
ReadADC0.o 19KB
initdspic.o 91KB
main.o 111KB
trig.o.d 95B
clrkpark.o.d 103B
pi.o.d 89B
CalcRef.o 2KB
smc.o.d 95B
svgen_ss.o.d 133B
atan2CORDIC.o 2KB
smcpos.h 3KB
FdWeak.o 100KB
svgen_ss.o 102KB
svgen_ss.c 4KB
clrkpark.o 22KB
ReadADC.h 241B
pi.h 444B
FdWeak.h 403B
trig.o 23KB
ReadADC.inc 151B
initdspic.c 2KB
MeasCurr.s 1KB
smcpos.inc 555B
smcpos.c 7KB
UserParms.h 5KB
Control.inc 211B
ReadADC0.o 22KB
initdspic.o 98KB
CalcRef.o 2KB
atan2CORDIC.s 4KB
MeasCurr.h 329B
park.inc 556B
general.h 1KB
parms.h 129B
atan2CORDIC.o 2KB
共 88 条
- 1
资源评论
刘良运
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功