久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3848|回復: 0
收起左側

DSP2812產生三相SPWM波程序

[復制鏈接]
ID:573493 發表于 2019-6-27 15:54 | 顯示全部樓層 |閱讀模式
DSP2812產生三相SPWM波,有需要的拿走

單片機源程序如下:
  1. /*
  2. 本程序在220V 3400轉 5對級直流無刷電機調試下通過
  3. */
  4. #include "DSP281x_Device.h"     // DSP281x Headerfile Include File
  5. #include "DSP281x_Examples.h"   // DSP281x Examples Include File
  6. #include "math.h"

  7. #define C_TIME 20
  8. #define pwm_half_per 3750 /*3750 pwm=20khz*//*sytemclk=150MHz*/
  9.                           /*1875 pwm=40kHz*/

  10. #define pole 2  /*電機的級對數*/
  11. #define timer2_per 60000//234375/* timer2 period with a 1/128 timer prescaler and 150MHz CPUCLK*/
  12. #define PI 3.1415926
  13. unsigned int adc_res;
  14. unsigned int dir=1;
  15. unsigned int ldd=0;
  16. unsigned int PWM_DUTY=2000;

  17. unsigned int I_result[2048];
  18. unsigned int i=0;
  19. unsigned int hall=0x000;
  20. unsigned int time_cnt=C_TIME;
  21. unsigned int hallspeed=0;
  22. unsigned int prehall=0;
  23. unsigned int speed;
  24. unsigned int a=0,b=0,c=0,d=0;
  25. unsigned int displaytime=0;
  26. unsigned int displayflag=0;

  27. unsigned int fc=10000;
  28. unsigned int f=50;
  29. float M=0.9;
  30. unsigned int k=0;
  31. // Prototype statements for functions found within this file.
  32. void init_eva(void);
  33. void eva_timer1_isr(void);

  34. //void init_evb(void);

  35. // Global counts used in this example


  36. void main(void)
  37. {

  38. // Step 1. Initialize System Control:
  39. // PLL, WatchDog, enable Peripheral Clocks
  40. // This example function is found in the DSP281x_SysCtrl.c file.
  41.    InitSysCtrl();

  42. // Step 2. Initalize GPIO:
  43. // This example function is found in the DSP281x_Gpio.c file and
  44. // illustrates how to set the GPIO to it's default state.
  45. // InitGpio();  // Skipped for this example  

  46. // Initialize only GPAMUX and GPBMUX for this test
  47.    EALLOW;
  48.    // Enable PWM pins
  49.    GpioMuxRegs.GPAMUX.all = 0x003F; // EVA PWM 1-6  pins
  50.    GpioMuxRegs.GPAQUAL.all=0x0000;
  51.    EDIS;
  52.    
  53. // Step 3. Clear all interrupts and initialize PIE vector table:
  54. // Disable CPU interrupts
  55.    DINT;

  56. // Initialize PIE control registers to their default state.
  57. // The default state is all PIE interrupts disabled and flags
  58. // are cleared.  
  59. // This function is found in the DSP281x_PieCtrl.c file.
  60.    InitPieCtrl();
  61.    IER = 0x0000;
  62.    IFR = 0x0000;
  63.    
  64.   // Interrupts that are used in this example are re-mapped to
  65. // ISR functions found within this file.
  66.    EALLOW;  // This is needed to write to EALLOW protected registers
  67.    PieVectTable.T1PINT = &eva_timer1_isr;

  68.    EDIS;  



  69. // Disable CPU interrupts and clear all CPU interrupt flags:


  70. // Initialize the PIE vector table with pointers to the shell Interrupt
  71. // Service Routines (ISR).  
  72. // This will populate the entire table, even if the interrupt
  73. // is not used in this example.  This is useful for debug purposes.
  74. // The shell ISR routines are found in DSP281x_DefaultIsr.c.
  75. // This function is found in DSP281x_PieVect.c.
  76.    InitPieVectTable();
  77.    EvaRegs.T1CON.all=0x0000;//disable time1
  78. // Step 4. Initialize all the Device Peripherals:
  79. // This function is found in DSP281x_InitPeripherals.c
  80. // InitPeripherals(); // Not required for this example
  81.    init_eva();
  82. //   init_evb();

  83. // Step 5. User specific code, enable interrupts:
  84. // Enable PIE group 2 interrupt 4 for T1PINT
  85.     PieCtrlRegs.PIEIER2.all = M_INT4;


  86.     // Enable CPU INT2 for T1PINT, INT3 for T2PINT, INT4 for T3PINT
  87.     // and INT5 for T4PINT:
  88.     IER |= M_INT2;

  89.     // Enable global Interrupts and higher priority real-time debug events:
  90.     EINT;   // Enable Global interrupt INTM
  91.     ERTM;   // Enable Global realtime interrupt DBGM
  92.     EvaRegs.EVAIMRA.bit.T1PINT = 1;
  93.     EvaRegs.EVAIFRA.bit.T1PINT = 1;
  94.   // Just sit and loop forever:
  95.   // PWM pins can be observed with a scope.       
  96.    
  97.   for(;;)
  98.   {
  99.   }

  100. }

  101. void init_eva()
  102. {

  103. // EVA Configure T1PWM, T2PWM, PWM1-PWM6
  104. // Initalize the timers
  105.    

  106.    EvaRegs.GPTCONA.bit.TCMPOE = 1;//0
  107.    EvaRegs.GPTCONA.bit.T1PIN = 2;//0
  108.    // Initalize EVA Timer1
  109.    //EvaRegs.T1PR=0.0001;
  110.    EvaRegs.T1PR = pwm_half_per;       // Timer1 period
  111.    EvaRegs.T1CMPR=0;
  112.    //EvaRegs.T1CMPR = PWM_DUTY;     // Timer1 compare
  113.    EvaRegs.T1CNT = 0x0000;      // Timer1 counter
  114.    EvaRegs.DBTCONA.all=0x0000;      //deadband units off
  115.    EvaRegs.ACTRA.all  =0x0fff; //pwm pin set active high*/
  116.    // Enable compare for PWM1-PWM6
  117.    EvaRegs.CMPR1=0;
  118.    //EvaRegs.CMPR1=PWM_DUTY;
  119.    EvaRegs.CMPR2=PWM_DUTY;
  120.    EvaRegs.CMPR3=PWM_DUTY;
  121.    EvaRegs.COMCONA.all = 0xA600;
  122.    EvaRegs.T1CON.all = 0x842;//0x840   

  123.    
  124.   // Compare action control.  Action that takes place
  125.   // on a cmpare event
  126.   // output pin 1 CMPR1 - active high
  127.   // output pin 2 CMPR1 - active low
  128.   // output pin 3 CMPR2 - active high
  129.   // output pin 4 CMPR2 - active low
  130.   // output pin 5 CMPR3 - active high
  131.   // output pin 6 CMPR3 - active low

  132.   EvaRegs.DBTCONA.all = 0x1000; // Disable deadband



  133. }


  134. void eva_timer1_isr(void)
  135. {
  136.    
  137.    EvaRegs.EVAIMRA.bit.T1PINT = 1;

  138.    EvaRegs.EVAIFRA.all = BIT7;
  139.    EvaRegs.ACTRA.all =0x0666;//0x0c02
  140.    //EvaRegs.CMPR3=pwm_half_per-200;
  141.    //EvaRegs.CMPR1=PWM_DUTY;
  142.    //EvaRegs.CMPR2=PWM_DUTY;
  143.    EvaRegs.CMPR1=(pwm_half_per/2)*(1+0.9*sin(PI*k/100));
  144.    EvaRegs.CMPR2=(pwm_half_per/2)*(1+0.9*sin(PI*k/100+2*PI/3));
  145.    EvaRegs.CMPR3=(pwm_half_per/2)*(1+0.9*sin(PI*k/100+4*PI/3));
  146.    k++;
  147.    if(k==200)
  148.    {
  149.      k=0;
  150.    }
  151. //  EvaRegs.CMPR1=PWM_DUTY;
  152. //  EvaRegs.CMPR2=PWM_DUTY;
  153. //  EvaRegs.CMPR3=PWM_DUTY;
  154.    
  155.    PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
  156. }

  157.        
復制代碼

所有資料51hei提供下載:
75448169dsp2812spwm.zip (422.74 KB, 下載次數: 63)


回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 免费观看一级特黄欧美大片 | 九九热免费观看 | 国产成人精品久久二区二区91 | 欧美电影大全 | 91超碰在线观看 | 久久亚洲视频 | 另类一区| 国产精品毛片一区二区在线看 | 日韩av在线一区二区 | 激情五月综合 | 九九热在线视频观看这里只有精品 | 国产在线精品一区二区三区 | 国产免费福利小视频 | 天天草天天 | 一区二区三区国产好的精 | 国产精品日韩 | 91就要激情 | 一区在线观看 | 91精品综合久久久久久五月天 | 久久精品男人的天堂 | 99精品视频免费在线观看 | 国产精品一区二区久久久久 | 一区二区三区亚洲精品国 | 国产午夜视频 | 日韩伦理一区二区 | 欧美高清一区 | 黄免费观看 | 黑人巨大精品欧美一区二区一视频 | 在线三级网址 | 95国产精品 | 国产欧美日韩一区二区三区 | 日本精品一区二区三区视频 | 亚洲欧美综合 | 亚洲国产精品一区二区久久 | caoporn免费 | 日韩在线一区二区三区 | www.久久国产精品 | 亚洲精品一区二区冲田杏梨 | av天天干| 亚洲人免费视频 | 好姑娘高清在线观看电影 |