ePWM Modules (3)

compare modules

CMPA: comparison register A, its value is compared with the TBCTR value, and when they are the same, the event is sent to the action module.
CMPB: comparison register B, its value is compared with TBCTR value, when they are the same, the event is sent to the action module.
CMPCTL: control register (important)
insert image description here
SHDWAFULL (or SHDWBFULL): CMPA (or B) shadow register full flag
0: not full
1: full
SHDWAMODE (or SHDWBMODE): CMPA (or B) write value whether to use shadow
0: Write 1 through the shadow register
: directly write to
LOADAMODE (or LOADBMODE): if using shadow, load condition mode selection
00: when CTR=ZERO
01: when CTR=PRD
10: when CTR=ZERO or CTR=PRD is
11: forbidden
insert image description here

Action Limit Module

AQCTLA: Action-limited output A control register
AQCTLB: Action-limited output A control register
insert image description here
insert image description here
ZRO: When the counter is equal to 0
00: No action
01: Clear, make ePWMxA output low
10: Set, make ePWMxA output high
11: Toggle, make ePWMxA output high Output toggles (high to low, low to high)

PRD: When the counter is equal to the period action
00: No action
01: Clear, make ePWMxA output low
10: Set, make ePWMxA output high
11: Toggle, make ePWMxA output flip (high to low, low to high)

CAU: When the counter is equal to CMPA and counting up
00: No action
01: Clear, make ePWMxA output low
10: Set, make ePWMxA output high
11: Toggle, make ePWMxA output flip (high to low, low to high)

CAD: When the counter is equal to CMPA and the count is down
00: No action
01: Clear, make ePWMxA output low
10: Set, make ePWMxA output high
11: Toggle, make ePWMxA output flip (high to low, low to high)

CBU: When the counter is equal to CMPB and the count is increasing
00: No action 01
: Clear, make ePWMxA output low
10: Set, make ePWMxA output high
11: Toggle, make ePWMxA output flip (high to low, low to high)

CBD: When the time base counter is equal to the CMPB register and the count is decremented
00: No action 01:
Clear, make ePWMxA output low
10: Set, make ePWMxA output high
11: Toggle, make ePWMxA output toggle (high to low, low to high )
insert image description here
ACTSFA: Action when one-time software force A is invoked
00: disable
01: clear (low)
10: set (high)
11: toggle (high and low toggle)

OTSFA: one-time software force for output event A
0: write 0 has no effect, always read 0
1: trigger a single S/W event

ACTSFB: Action when one-time software force B is invoked
00: disable
01: clear (low)
10: set (high)
11: toggle (high-low toggle)

OTSFB: one-time software force for output event B
0: write 0 has no effect, always read 0
1: trigger a single S/W event

BLDCSF: main register slave mapping option reload
00: load when counter is equal to 0
01: load when counter is equal to period
10: load when counter is equal to 0 or period
11: load directly without mapping

insert image description here
CSFA: continuous software forcing on output A
00: no effect
01: continuous low signal on output A
10: continuous high signal on output A
11: software forcing is disabled and has no effect

CSFB: continuous software forcing on output B
00: no effect
01: continuous low signal on output B
10: continuous high signal on output B
11: software forcing is disabled and has no effect

event trigger module

insert image description here
insert image description here
INTESEL: EPWM interrupt option
000: Reserved
001: Time base counter (TBCTR) is 0
010: TBCTR=TBPRD
011: Reserved
100: Time base counter equals CMPA when timer increments
101: Time base counter equals CMPA when timer decrements
110: Time base counter equals CMPB when timer is incremented
111: Time base counter is equal to CMPB when timer is decremented

INTEN: Enable EPWM interrupt generation
0: Disable generation
1: Enable generation

SCOASEL: Determines when EPWMxSOCB pulses are generated
000: Reserved
001: Time base counter (TBCTR) is 0
010: TBCTR=TBPRD
011: Reserved
100: Time base counter equals CMPA when timer
increments 101: Time base counter when timer decrements Equal to CMPA
110: Time base counter is equal to CMPB when timer is incremented
111: Time base counter is equal to CMPB when timer is decremented

SOCAEN: Enable ADC conversion A (EPWMxSOCA) pulse
0: Disable
1: Enable

SCOBSEL: Determines when EPWMxSOCB pulses are generated
000: Reserved
001: Time base counter (TBCTR) is 0
010: TBCTR=TBPRD
011: Reserved
100: Time base counter equals CMPA when timer
increments 101: Time base counter when timer decrements Equal to CMPA
110: Time base counter is equal to CMPB when timer is incremented
111: Time base counter is equal to CMPB when timer is decremented

SCOBEN: Enable ADC conversion B (EPWMxSOCB) pulse
0: Disable
1: Enable

insert image description here
INTPRD: Interrupt at which event occurs
00: Disabled
01: Interrupt at the first event, ETPS[INTCNT]=0,1
10: Interrupt at the second event, ETPS[INTCNT]=1,0
11: Interrupt when the third event occurs, ETPS[INTCNT]=1,1

NTCNT: EPWM Interrupt Technology Register
00: No event occurred
01: 1
10: 2
11: 3

SOCBCNT: EPWM ADC Start of Conversion B Events (EPWMxSOCB) Counter Register, these bits determine how many selected ETSEL (SOCBSEL) events have occurred
00: None
01: 1
10: 2
11: 3

SOCBPRD: EPWMxSOCB pulse signal generation event selection
00: Disabled
01: Generate EPWMxSOCB pulse on the first event: ETPS[SOCBCNT]=0,1
10: Generate EPWMxSOCB pulse on the second event: ETPS[SOCBCNT]=1,0
11 : EPWMxSOCB pulse is generated on the third event: ETPS[SOCBCNT]=1,1

Steps for PWM configuration:
(1) Enable the ePWM peripheral clock and disable the clock of the time base module
(2) Turn on the ePWM corresponding to the GPIO clock and initialize the configuration
(3) Initialize the time base module, that is, configure the TB related register value
(4) Initialize Comparison module, that is, configure CC related register value
(5) Initialize action limit module, that is, configure AQ related register value
(6) Initialize event trigger module, that is, configure ET related register value
(7) Initialize dead zone module, chopping module, namely Configure DB, PC related register value
(8) Enable time base counter clock


#include "epwm.h"

//进行PWM6的初始化,参数输入参数为PWM波的周期
void EPWM6_Init(Uint16 tbprd)
{
    //使能 ePWM 外设时钟及使能时基模块时钟
    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
    SysCtrlRegs.PCLKCR1.bit.EPWM6ENCLK = 1;
    EDIS;

    //初始化GPIO    GPIO输出PWM波
    InitEPwm6Gpio();

    //初始化时基模块
    //设置同步
    EPwm6Regs.TBCTL.bit.SYNCOSEL = 0x0;//TB_SYNC_IN
    //允许每个使用被同步
    EPwm6Regs.TBCTL.bit.PHSEN = 0x1;//TB_ENABLE
    //时基相位寄存器赋值0
    EPwm6Regs.TBPHS.half.TBPHS = 0;
    // 清零计数器
    EPwm6Regs.TBCTR = 0x0000;
    //设置周期数值
    EPwm6Regs.TBPRD = tbprd;
    // 递增计数模式
    EPwm6Regs.TBCTL.bit.CTRMODE = 0x0;//TB_COUNT_UP
    //TBCLK=SYSCLKOUT/(HSPCLKDIV×CLKDIV)
    EPwm6Regs.TBCTL.bit.HSPCLKDIV=0x0;//不分频TB_DIV1
    EPwm6Regs.TBCTL.bit.CLKDIV=0x0;//不分频TB_DIV1

    // 初始化比较模块
    // 将影子寄存器加载设置为零
    //使用影子寄存器
    EPwm6Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;//0x0
    EPwm6Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;//0x0
    //等于0时,加载事件
    EPwm6Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;//0x0
    EPwm6Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;//0x0
    // 设置比较值为0
    EPwm6Regs.CMPA.half.CMPA = 0;
    EPwm6Regs.CMPB = 0;

    //初始化动作限定模块
    // A计数到0时触发事件,并且在A向上计数的时候触发
    EPwm6Regs.AQCTLA.bit.ZRO = AQ_CLEAR;// 0x1
    EPwm6Regs.AQCTLA.bit.CAU = AQ_SET; // 0x2
    // B计数到0时触发事件,并且在B向上计数的时候触发
    EPwm6Regs.AQCTLB.bit.ZRO = AQ_CLEAR; // 0x1
    EPwm6Regs.AQCTLB.bit.CBU = AQ_SET;// 0x2

    //初始化事件触发模块
    //选择0匹配事件中断
    EPwm6Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;//0x1
    //使能事件触发中断
    EPwm6Regs.ETSEL.bit.INTEN = 1;
    //一次中断请求
    EPwm6Regs.ETPS.bit.INTPRD = ET_1ST;//0x1

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
    EDIS;
}
void EPwm6A_SetCompare(Uint16 val)
{
    EPwm6Regs.CMPA.half.CMPA = val;  //设置占空比
}
void EPwm6B_SetCompare(Uint16 val)
{
    EPwm6Regs.CMPB = val;  //设置占空比
}

#ifndef APP_EPWM_EPWM_H_
#define APP_EPWM_EPWM_H_

#include "DSP2833x_Device.h"     // DSP2833x 头文件
#include "DSP2833x_Examples.h"   // DSP2833x 例子相关头文件

void EPWM6_Init(Uint16 tbprd);
void EPwm6A_SetCompare(Uint16 val);
void EPwm6B_SetCompare(Uint16 val);

#endif /* APP_EPWM_EPWM_H_ */

Guess you like

Origin blog.csdn.net/qq_45159887/article/details/130569276