TMS570配置EPWM输出

一、介绍

1、功能:配置ePWM2A输出 需要的PWM波形

2、

二、CCS创建工程(略)

三、配置HALCoGen

1、使能设备

2、使能IO

3、配置EPWM2A的周期

(1)使能

(2)参数

4、File-->Generate Code 生成代码

四、修改CCS代码

/** @file HL_sys_main.c 
*   @brief Application main file
*   @date 11-Dec-2018
*   @version 04.07.01
*
*   This file contains an empty main function,
*   which can be used for the application.
*/

/* 
* Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com  
* 
* 
*  Redistribution and use in source and binary forms, with or without 
*  modification, are permitted provided that the following conditions 
*  are met:
*
*    Redistributions of source code must retain the above copyright 
*    notice, this list of conditions and the following disclaimer.
*
*    Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the 
*    documentation and/or other materials provided with the   
*    distribution.
*
*    Neither the name of Texas Instruments Incorporated nor the names of
*    its contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/


/* USER CODE BEGIN (0) */
/* USER CODE END */

/* Include Files */

#include "HL_sys_common.h"

/* USER CODE BEGIN (1) */
#include "HL_gio.h"
#include "HL_sci.h"
#include "stdio.h"
#include "HL_sys_core.h"
#include "HL_etpwm.h"   //PWM

/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */

#define UART1 sciREG1
uint8 g_SCI_RX_Var = 0;
int fputc(int ch, FILE *f)
{
    sciSendByte(UART1,ch);
  return ch;
}

/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
    int i = 0;
    gioInit();
//    sciInit();      /* initialize sci/sci-lin    */   /* even parity , 2 stop bits */
//    sciReceive(UART1, 1, &g_SCI_RX_Var);
    _enable_IRQ_interrupt_();
    etpwmInit();
    /* Alternate code for configuring ETPWM and ECAP */
        /* Configure ETPWM1 */
    /* Set the TBCLK frequency =  VCLK3 frequency = 75MHz */
    etpwmSetClkDiv(etpwmREG2, ClkDiv_by_1, HspClkDiv_by_1);

    /* Set the time period as 1000 ns (Divider value = (1000ns * 75MHz) - 1 = 74)*/
    etpwmSetTimebasePeriod(etpwmREG2, 74);

    /* Configure Compare A value as half the time period */
    etpwmSetCmpA(etpwmREG2, 37);

    /* Configure mthe module to set PWMA value as 1 when CTR=0 and as 0 when CTR=CmpA  */
    etpwmActionQualConfig_t configPWMA;
    configPWMA.CtrEqZero_Action = ActionQual_Set;
    configPWMA.CtrEqCmpAUp_Action = ActionQual_Clear;
    configPWMA.CtrEqPeriod_Action = ActionQual_Disabled;
    configPWMA.CtrEqCmpADown_Action = ActionQual_Disabled;
    configPWMA.CtrEqCmpBUp_Action = ActionQual_Disabled;
    configPWMA.CtrEqCmpBDown_Action = ActionQual_Disabled;
    etpwmSetActionQualPwmA(etpwmREG2, configPWMA);

    /* Start counter in CountUp mode */
    etpwmSetCount(etpwmREG2, 0);
    etpwmSetCounterMode(etpwmREG2, CounterMode_Up);
    etpwmStartTBCLK();

     while(1)
     {
//         printf("Hello! TMS570\r\n");
         gioToggleBit(gioPORTB, 6);
         for( i = 0;i<50000000;i++)
         {
         }
     }
/* USER CODE END */

    return 0;
}


/* USER CODE BEGIN (4) */


/* USER CODE END */

五、运行结果

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于TMS28377D这款芯片,它是一数字信号控制器(Digital Signal, DSC),内置了强大的和控制功能,广泛应用于业控制、电力电子、汽电子等领域。而EPWM则是TMS28377D中的一种模块,用于实现高精度的脉冲宽度调制(Pulse Width Modulation, PWM)功能。 关于TMS28377D EPWM的案例,这里提供一个简单的示例代码,用于实现一个基本的PWM输出: ```c #include "F2837xD_device.h" #include "F2837xD_Examples.h" #define PWM_PERIOD 1000 // PWM周期设置为1000个时钟周期 #define DUTY_CYCLE 500 // 占空比设置为50% void InitEPwm() { // 配置GPIO引脚为EPWM功能 GPIO_SetupPinMux(1, GPIO_MUX_CPU1, 1); // 配置EPWM模块 EPwm1Regs.TBPRD = PWM_PERIOD - 1; // 设置PWM周期 EPwm1Regs.CMPA.half.CMPA = DUTY_CYCLE; // 设置占空比 EPwm1Regs.TBCTL.bit.CTRMODE = 0x00; // 设置计数器模式为上升计数 EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0x00; // 设置时钟分频 EPwm1Regs.TBCTL.bit.CLKDIV = 0x00; // 设置时钟分频 EPwm1Regs.AQCTLA.bit.CAU = 0x02; // 设置PWM输出为高电平 EPwm1Regs.AQCTLA.bit.CAD = 0x01; // 设置PWM输出为低电平 // 使能EPWM模块 EPwm1Regs.TBCTL.bit.PHSEN = 0x01; // 使能相位补偿 EPwm1Regs.TBPHS.half.TBPHS = 0; // 设置相位补偿值 EPwm1Regs.TBCTR = 0x0000; // 清零计数器 EPwm1Regs.TBCTL.bit.CTRMODE = 0x02; // 设置计数器模式为连续计数 } void main() { // 初始化EPWM模块 InitEPwm(); // 死循环 while (1) { // do nothing } } ``` 这个示例代码演示了如何使用TMS28377D的EPWM模块来控制PWM输出。在这个例子中,EPWM1模块被配置输出一个周期为1000个时钟周期的PWM波形,占空比为50%。你可以根据需要调整PWM周期和占空比的值来满足具体的应用需求。 希望这个示例对你有所帮助!如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值