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 */

五、运行结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值