example_epwmsetup.c

来自「2812例程以及 控制直流无刷电机程序」· C语言 代码 · 共 75 行

C
75
字号
// TI File $Revision: /main/2 $
// Checkin $Date: April 18, 2005   10:08:18 $
//###########################################################################
//
// FILE:	Example_EpwmSetup.c
//
// TITLE:	Frequency measurement using EQEP peripheral
//
// DESCRIPTION:
//
// This file contains source for the ePWM initialization for the 
// freq calculation module
//
//###########################################################################
// Original Author: SD
//
// $TI Release: DSP280x V1.10 $
// $Release Date: April 18, 2005 $
//###########################################################################

#include "DSP280x_Device.h"     // DSP280x Headerfile Include File
#include "DSP280x_Examples.h"   // DSP280x Examples Include File
#include "Example_freqcal.h"    // Example specific include file


#define CPU_CLK   100e6
#define PWM_CLK   20e3
#define SP        CPU_CLK/(2*PWM_CLK)
#define TBCTLVAL  0x200E


void EPwmSetup()
{
	EPwm1Regs.TBSTS.all=0;
	EPwm1Regs.TBPHS.half.TBPHS=0;
	EPwm1Regs.TBCTR=0;

	EPwm1Regs.CMPCTL.all=0x60;
	EPwm1Regs.CMPA.half.CMPA =SP/2;
	EPwm1Regs.CMPB=0;
	
	EPwm1Regs.AQCTLA.all=0x60;
	EPwm1Regs.AQCTLB.all=0;
	EPwm1Regs.AQSFRC.all=0;
	EPwm1Regs.AQCSFRC.all=0;
	
	EPwm1Regs.DBCTL.all=0xb;
	EPwm1Regs.DBRED=0;
	EPwm1Regs.DBFED=0;
	
	EPwm1Regs.TZSEL.all=0;
	EPwm1Regs.TZCTL.all=0;
	EPwm1Regs.TZEINT.all=0;
	EPwm1Regs.TZFLG.all=0;
	EPwm1Regs.TZCLR.all=0;
	EPwm1Regs.TZFRC.all=0;

	EPwm1Regs.ETSEL.all=9;
	EPwm1Regs.ETPS.all=1;	
	EPwm1Regs.ETFLG.all=0;
	EPwm1Regs.ETCLR.all=0;
	EPwm1Regs.ETFRC.all=0;
	
	EPwm1Regs.PCCTL.all=0;
	
	EPwm1Regs.TBCTL.all=0x0010+TBCTLVAL;			// Enable Timer
	EPwm1Regs.TBPRD=SP;

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC =1;
    EDIS;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?