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

標(biāo)題: DSPF28335關(guān)于SPWM的源代碼 [打印本頁]

作者: D_alone    時間: 2018-3-16 15:08
標(biāo)題: DSPF28335關(guān)于SPWM的源代碼
關(guān)于DSPF28335寫的SPWM代碼分享給大家

源程序如下:
  1. /*
  2. * main.c
  3. */

  4. #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

  5. // Prototype statements for functions found within this file.
  6. void InitEPwm1Example(void);
  7. extern void InitSpwm(void);

  8. void main(void) {
  9. // Step 1. Initialize System Control:
  10. // PLL, WatchDog, enable Peripheral Clocks
  11. // This example function is found in the DSP2833x_SysCtrl.c file.
  12.    InitSysCtrl();

  13. // Step 2. Initialize GPIO:
  14. // This example function is found in the DSP2833x_Gpio.c file and
  15. // illustrates how to set the GPIO to it's default state.
  16. // InitGpio();  // Skipped for this example

  17. // For this case just init GPIO pins for ePWM1, ePWM2, ePWM3
  18. // These functions are in the DSP2833x_EPwm.c file
  19.    InitEPwm1Gpio();


  20. // Step 3. Clear all interrupts and initialize PIE vector table:
  21. // Disable CPU interrupts
  22.    DINT;

  23. // Initialize the PIE control registers to their default state.
  24. // The default state is all PIE interrupts disabled and flags
  25. // are cleared.
  26. // This function is found in the DSP2833x_PieCtrl.c file.
  27.    InitPieCtrl();

  28. // Disable CPU interrupts and clear all CPU interrupt flags:
  29.    IER = 0x0000;
  30.    IFR = 0x0000;

  31. // Initialize the PIE vector table with pointers to the shell Interrupt
  32. // Service Routines (ISR).
  33. // This will populate the entire table, even if the interrupt
  34. // is not used in this example.  This is useful for debug purposes.
  35. // The shell ISR routines are found in DSP2833x_DefaultIsr.c.
  36. // This function is found in DSP2833x_PieVect.c.
  37.    InitPieVectTable();

  38. // Interrupts that are used in this example are re-mapped to
  39. // ISR functions found within this file.
  40. // EALLOW;  // This is needed to write to EALLOW protected registers
  41. // PieVectTable.EPWM1_INT = &EPWM1_INT_ISR;

  42. // EDIS;    // This is needed to disable write to EALLOW protected registers

  43. // Step 4. Initialize all the Device Peripherals:
  44. // This function is found in DSP2833x_InitPeripherals.c
  45. // InitPeripherals();  // Not required for this example

  46. // For this example, only initialize the ePWM

  47.    EALLOW;
  48.    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
  49.    EDIS;

  50.    InitEPwm1Example();
  51.    InitSpwm();

  52.    EALLOW;
  53.    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
  54.    EDIS;

  55. // Step 5. User specific code, enable interrupts:

  56. // Enable CPU INT3 which is connected to EPWM1-3 INT:
  57.    IER |= M_INT3;

  58. // Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
  59.    PieCtrlRegs.PIEIER3.bit.INTx1 = 1;

  60. // Enable global Interrupts and higher priority real-time debug events:
  61.    EINT;   // Enable Global interrupt INTM
  62.    ERTM;   // Enable Global realtime interrupt DBGM

  63. // Step 6. IDLE loop. Just sit and loop forever (optional):
  64.    for(;;)
  65.    {
  66.            __asm("          NOP");
  67.    }

  68. }
  69. void InitEPwm1Example()
  70. {
  71.    // Setup TBCLK
  72.    EPwm1Regs.TBPRD = 0xffff;           // Set timer period 801 TBCLKs
  73.    EPwm1Regs.TBPHS.half.TBPHS = 0x0000;           // Phase is 0
  74.    EPwm1Regs.TBCTR = 0x0000;                      // Clear counter

  75.    // Set Compare values
  76.    EPwm1Regs.CMPA.half.CMPA = 0x7fff;     // Set compare A value
  77.    EPwm1Regs.CMPB = 0x7fff;               // Set Compare B value

  78.    // Setup counter mode
  79.    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
  80.    EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;        // Disable phase loading
  81.    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2;       // Clock ratio to SYSCLKOUT
  82.    EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV8;

  83.    // Setup shadowing
  84.    EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
  85.    EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
  86.    EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;  // Load on Zero
  87.    EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;


  88.    // Set actions
  89.    EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;             // Set PWM1A on event A, up count
  90.    EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;           // Clear PWM1A on event A, down count

  91.    EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;             // Set PWM1B on event B, up count
  92.    EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;           // Clear PWM1B on event B, down count

  93.    // Interrupt where we will change the Compare Values
  94.    EPwm1Regs.ETSEL.bit.INTSEL = ET_CTRU_CMPA;      // Select INT on Zero event
  95.    EPwm1Regs.ETSEL.bit.INTEN = 1;                 // Enable INT
  96.    EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;            // Generate INT on 3rd event

  97. }

復(fù)制代碼

所有資料51hei提供下載:
SPWM.zip (91.11 KB, 下載次數(shù): 99)



作者: cchessy    時間: 2018-3-29 06:39
謝謝分享!
作者: 天下1213    時間: 2018-4-18 20:02
也是今天才看了,PWM這個部分,感覺還不太深入,可以看看這個程序,好好在學(xué)習(xí)一下

作者: mcu_mpu    時間: 2018-12-20 10:58
正在學(xué)習(xí)spwm,收藏了。
作者: 小小肚皮    時間: 2019-7-20 17:53
贊!!
作者: sky_study    時間: 2020-5-2 18:34
不錯,學(xué)習(xí)了
作者: JerZY    時間: 2020-5-7 22:33
請問無法打開“Cover.h”源文件是什么意思?
作者: JerZY    時間: 2020-5-7 22:34
你好,請問無法打開“Cover.h”文件,是不是少了這個頭文件?請問樓主有這個文件嗎,可以發(fā)我一下嗎
作者: sea12138    時間: 2020-5-29 19:55
大佬,我想請教,加個好友唄
作者: sea12138    時間: 2020-5-29 19:58
JerZY 發(fā)表于 2020-5-7 22:33
請問無法打開“Cover.h”源文件是什么意思?

用啥打開呀




歡迎光臨 (http://m.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 国产区精品| 中文字幕在线免费观看 | 亚洲欧美日韩在线一区二区 | 免费一区二区 | 这里只有精品99re | 午夜精品久久久久久久久久久久久 | 久久九精品| 日韩在线电影 | 亚洲视频在线播放 | 在线中文视频 | 亚洲一区网站 | 成人av一区 | 国产精品一区一区三区 | 日韩有码一区 | 成人激情视频 | a黄毛片 | 日韩亚洲视频 | 九九热精品视频 | 欧美一级欧美三级在线观看 | 日本黄色不卡视频 | 亚洲精品一区二区三区在线观看 | 国产精品一区在线观看 | 久久精品国产一区老色匹 | 麻豆av在线免费观看 | 欧美一区二区视频 | 欧美xxxx色视频在线观看免费 | 亚洲精品一区中文字幕乱码 | 97色免费视频 | 日韩一区二区在线免费观看 | 精品日韩一区二区 | 精品国产乱码久久久久久丨区2区 | 一区二区三区四区国产 | 国产精品成人一区二区三区夜夜夜 | 精品日本中文字幕 | 欧美成人第一页 | 高清亚洲| 久久久久久免费免费 | 久久久久久国产一区二区三区 | 亚洲精品国产a久久久久久 午夜影院网站 | 日韩在线免费视频 | 亚洲国产成人精品女人久久久 |