找回密码
 注册
关于网站域名变更的通知
查看: 282|回复: 2
打印 上一主题 下一主题

DSP2812产生三相SPWM波

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2021-9-30 10:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
  • 单片机源程序如下:4 K+ D- w2 o1 K

    * C* Z$ h" m9 J0 sDSP2812产生三相SPWM波,有需要的拿走
  • /*
  • 本程序在220V 3400转 5对级直流无刷电机调试下通过
  • */
  • #include "DSP281x_Device.h"     // DSP281x HeadeRFile Include File
  • #include "DSP281x_Examples.h"   // DSP281x Examples Include File
  • #include "math.h"
  • #define C_TIME 20
  • #define pwm_half_per 3750 /*3750 pwm=20khz*//*sytEMClk=150MHz*/
  •                           /*1875 pwm=40kHz*/
  • #define pole 2  /*电机的级对数*/
  • #define timer2_per 60000//234375/* timer2 period with a 1/128 timer prescaler and 150MHz CPUCLK*/
  • #define PI 3.1415926
  • unsigned int adc_res;
  • unsigned int dir=1;
  • unsigned int ldd=0;
  • unsigned int PWM_DUTY=2000;
  • unsigned int I_result[2048];
  • unsigned int i=0;
  • unsigned int hall=0x000;
  • unsigned int time_cnt=C_TIME;
  • unsigned int hallspeed=0;
  • unsigned int prehall=0;
  • unsigned int speed;
  • unsigned int a=0,b=0,c=0,d=0;
  • unsigned int displaytime=0;
  • unsigned int displayflag=0;
  • unsigned int fc=10000;
  • unsigned int f=50;
  • float M=0.9;
  • unsigned int k=0;
  • // Prototype statements for functions found within this file.
  • void init_eva(void);
  • void eva_timer1_isr(void);
  • //void init_evb(void);
  • // Global counts used in this example
  • void main(void)
  • {
  • // Step 1. Initialize System Control:
  • // PLL, WatchDog, enable Peripheral Clocks
  • // This example function is found in the DSP281x_SysCtrl.c file.
  •    InitSysCtrl();
  • // Step 2. Initalize GPIO:
  • // This example function is found in the DSP281x_Gpio.c file and
  • // illustrates how to set the GPIO to it's default state.
  • // InitGpio();  // Skipped for this example
  • // Initialize only GPAMUX and GPBMUX for this test
  •    EALLOW;
  •    // Enable PWM pins
  •    GpioMuxRegs.GPAMUX.all = 0x003F; // EVA PWM 1-6  pins
  •    GpioMuxRegs.GPAQUAL.all=0x0000;
  •    EDIS;
  • // Step 3. Clear all interrupts and initialize PIE vector table:
  • // Disable CPU interrupts
  •    DINT;
  • // Initialize 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 DSP281x_PieCtrl.c file.
  •    InitPieCtrl();
  •    IER = 0x0000;
  •    IFR = 0x0000;
  •   // Interrupts that are used in this example are re-mapped to
  • // ISR functions found within this file.
  •    EALLOW;  // This is needed to write to EALLOW protected registers
  •    PieVectTable.T1PINT = &eva_timer1_isr;
  •    EDIS;
  • // Disable CPU interrupts and clear all CPU interrupt flags:
  • // 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 DSP281x_DefaultIsr.c.
  • // This function is found in DSP281x_PieVect.c.
  •    InitPieVectTable();
  •    EvaRegs.T1CON.all=0x0000;//disable time1
  • // Step 4. Initialize all the Device Peripherals:
  • // This function is found in DSP281x_InitPeripherals.c
  • // InitPeripherals(); // Not required for this example
  •    init_eva();
  • //   init_evb();
  • // Step 5. User specific code, enable interrupts:
  • // Enable PIE group 2 interrupt 4 for T1PINT
  •     PieCtrlRegs.PIEIER2.all = M_INT4;
  •     // Enable CPU INT2 for T1PINT, INT3 for T2PINT, INT4 for T3PINT
  •     // and INT5 for T4PINT:
  •     IER |= M_INT2;
  •     // Enable global Interrupts and higher priority real-time debug events:
  •     EINT;   // Enable Global interrupt INTM
  •     ERTM;   // Enable Global realtime interrupt DBGM
  •     EvaRegs.EVAIMRA.bit.T1PINT = 1;
  •     EvaRegs.EVAIFRA.bit.T1PINT = 1;
  •   // Just sit and loop forever:
  •   // PWM pins can be observed with a scope.
  •   for(;;)
  •   {
  •   }
  • }
  • void init_eva()
  • {
  • // EVA Configure T1PWM, T2PWM, PWM1-PWM6
  • // Initalize the timers
  •    EvaRegs.GPTCONA.bit.TCMPOE = 1;//0
  •    EvaRegs.GPTCONA.bit.T1PIN = 2;//0
  •    // Initalize EVA Timer1
  •    //EvaRegs.T1PR=0.0001;
  •    EvaRegs.T1PR = pwm_half_per;       // Timer1 period
  •    EvaRegs.T1CMPR=0;
  •    //EvaRegs.T1CMPR = PWM_DUTY;     // Timer1 compare
  •    EvaRegs.T1CNT = 0x0000;      // Timer1 counter
  •    EvaRegs.DBTCONA.all=0x0000;      //deadband units off
  •    EvaRegs.ACTRA.all  =0x0fff; //pwm pin set active high*/
  •    // Enable compare for PWM1-PWM6
  •    EvaRegs.CMPR1=0;
  •    //EvaRegs.CMPR1=PWM_DUTY;
  •    EvaRegs.CMPR2=PWM_DUTY;
  •    EvaRegs.CMPR3=PWM_DUTY;
  •    EvaRegs.COMCONA.all = 0xA600;
  •    EvaRegs.T1CON.all = 0x842;//0x840
  •   // Compare action control.  Action that takes place
  •   // on a cmpare event
  •   // output pin 1 CMPR1 - active high
  •   // output pin 2 CMPR1 - active low
  •   // output pin 3 CMPR2 - active high
  •   // output pin 4 CMPR2 - active low
  •   // output pin 5 CMPR3 - active high
  •   // output pin 6 CMPR3 - active low
  •   EvaRegs.DBTCONA.all = 0x1000; // Disable deadband
  • }
  • void eva_timer1_isr(void)
  • {
  •    EvaRegs.EVAIMRA.bit.T1PINT = 1;
  •    EvaRegs.EVAIFRA.all = BIT7;
  •    EvaRegs.ACTRA.all =0x0666;//0x0c02
  •    //EvaRegs.CMPR3=pwm_half_per-200;
  •    //EvaRegs.CMPR1=PWM_DUTY;
  •    //EvaRegs.CMPR2=PWM_DUTY;
  •    EvaRegs.CMPR1=(pwm_half_per/2)*(1+0.9*sin(PI*k/100));
  •    EvaRegs.CMPR2=(pwm_half_per/2)*(1+0.9*sin(PI*k/100+2*PI/3));
  •    EvaRegs.CMPR3=(pwm_half_per/2)*(1+0.9*sin(PI*k/100+4*PI/3));
  •    k++;
  •    if(k==200)
  •    {
  •      k=0;
  •    }
  • //  EvaRegs.CMPR1=PWM_DUTY;
  • //  EvaRegs.CMPR2=PWM_DUTY;
  • //  EvaRegs.CMPR3=PWM_DUTY;
  •    PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
  • }

  • ) {' f3 n3 V) \1 l7 f
5 d1 `% t8 I# |' M3 Y

+ z+ W# L9 [% i8 z6 {6 M; c6 X$ r' G

该用户从未签到

2#
发表于 2021-9-30 11:21 | 只看该作者
对电机转数有什么要求

该用户从未签到

3#
发表于 2021-9-30 17:53 | 只看该作者
电机转数差距大吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-8-11 21:21 , Processed in 0.125000 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表