一、介绍
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 */