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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6892|回復: 9
打印 上一主題 下一主題
收起左側

DSPF28335關于SPWM的源代碼

[復制鏈接]
跳轉到指定樓層
樓主
關于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. }

復制代碼

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


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:15377 發表于 2018-3-29 06:39 | 只看該作者
謝謝分享!
回復

使用道具 舉報

板凳
ID:247467 發表于 2018-4-18 20:02 | 只看該作者
也是今天才看了,PWM這個部分,感覺還不太深入,可以看看這個程序,好好在學習一下
回復

使用道具 舉報

地板
ID:324611 發表于 2018-12-20 10:58 | 只看該作者
正在學習spwm,收藏了。
回復

使用道具 舉報

5#
ID:284570 發表于 2019-7-20 17:53 | 只看該作者
贊!!
回復

使用道具 舉報

6#
ID:742944 發表于 2020-5-2 18:34 | 只看該作者
不錯,學習了
回復

使用道具 舉報

7#
ID:746506 發表于 2020-5-7 22:33 | 只看該作者
請問無法打開“Cover.h”源文件是什么意思?
回復

使用道具 舉報

8#
ID:746506 發表于 2020-5-7 22:34 | 只看該作者
你好,請問無法打開“Cover.h”文件,是不是少了這個頭文件?請問樓主有這個文件嗎,可以發我一下嗎
回復

使用道具 舉報

9#
ID:755142 發表于 2020-5-29 19:55 | 只看該作者
大佬,我想請教,加個好友唄
回復

使用道具 舉報

10#
ID:755142 發表于 2020-5-29 19:58 | 只看該作者
JerZY 發表于 2020-5-7 22:33
請問無法打開“Cover.h”源文件是什么意思?

用啥打開呀
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产成人精品综合 | 在线看片国产精品 | 一级全黄视频 | 国产精品成人国产乱一区 | heyzo在线| 国产成人精品一区二区三区视频 | 国产精品久久久久久久久久免费看 | 国产成人免费 | 亚洲性人人天天夜夜摸 | 欧美在线一区二区三区 | www.日韩| 欧美日韩精品在线一区 | 久久福利网站 | 97人人超碰 | 国内精品伊人久久久久网站 | 亚洲高清在线观看 | 日韩在线视频免费观看 | 亚洲成人av在线播放 | 国产精品中文字幕一区二区三区 | 欧美黄色一级毛片 | 成年人在线观看 | 国产探花在线观看视频 | 日产精品久久久一区二区福利 | 日韩在线免费观看视频 | 欧美在线日韩 | 午夜影院 | 日韩在线h| 一级电影免费看 | 91精品成人久久 | 99久久精品国产毛片 | 久久精品无码一区二区三区 | 九九精品在线 | 欧美一区二区免费 | 在线观看黄色电影 | 91精品久久久久久久久中文字幕 | 91视在线国内在线播放酒店 | 在线播放一区二区三区 | 国产精久久久久久久妇剪断 | 国产成人99久久亚洲综合精品 | 91视频在线 | 国产精品福利视频 |