Other Parts Discussed in Thread:C2000WARE
#include "F2837xD_device.h" #include "F2837xD_Examples.h" #define duty 4999//max 1800, set 3600--->now *0.5=1800 #define DeadTime 100//0xAF=175 //ETSEL ZERO=0xA09 PRD=0xA0A ZERO&PRD=0xA0B CAU=0xA0C CAD=0xA0D CBU=0xA0E CBD=0xA0F //------------------------------------------------------------------- void ePWM(void) // 設定ePWM { // EALLOW;// Enable EALLOW protected register access // SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // EDIS;// Disable EALLOW protected register access//-----ePWM1設定--------EPwm1Regs.TBCTL.all = 0x4031; //初始化Time base counter 的設wEPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;EPwm1Regs.TBCTL.bit.CLKDIV = 1;EPwm1Regs.TBCTR = 0x0000;// Clear timer counterEPwm1Regs.TBPRD = duty;// Set timer periodEPwm1Regs.TBPHS.bit.TBPHS = 0x0000; // Set timer phase//*****************************************EPwm1Regs.CMPA.bit.CMPA = duty;EPwm1Regs.CMPB.bit.CMPB = 0;//*****************************************EPwm1Regs.CMPCTL.all = 0x0; //計數器比較器的存取設定 0x50=1010000//01:CLR 10:SET 00:do nothingEPwm1Regs.AQCTLA.bit.ZRO = 0x0;EPwm1Regs.AQCTLA.bit.CAD = 0x8;EPwm1Regs.AQCTLA.bit.CBD = 0x4;//EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;EPwm1Regs.AQCTLB.bit.ZRO = 0x0;EPwm1Regs.AQCTLB.bit.CAD = 0x8;EPwm1Regs.AQCTLB.bit.CBD = 0x4;//EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;EPwm1Regs.AQSFRC.all = 0x0000;// Action-qualifier s/w force registerEPwm1Regs.AQCSFRC.all = 0x0000;// Action-qualifier continuous s/w force registerEPwm1Regs.DBCTL.all = 0x002B;// 決定上升下降延遲方式EPwm1Regs.DBRED.all = DeadTime;// rising edge delayEPwm1Regs.DBFED.all = DeadTime;// falling edge delayEPwm1Regs.PCCTL.bit.CHPEN = 0;// PWM chopper unit disabledEALLOW;EPwm1Regs.TZCLR.all = 0x0007;EPwm1Regs.TZSEL.all = 0x0008;//指定使用TZ4為觸發源EPwm1Regs.TZCTL.all = 0x000A;//以觸發TZ4使ePWM強制關閉之AB位置 0xA=1010EDIS;//EPwm1Regs.ETCLR.all = 0x004;//EPwm1Regs.ETSEL.all = 0xA09;EPwm1Regs.ETPS.all = 0x0005;//EPwm1Regs.TBCTL.bit.CTRMODE = 0x2; //上下數模式//-----ePWM1設定--------EPwm2Regs.TBCTL.all = 0xC031; //初始化Time base counter 的設wEPwm2Regs.TBCTL.bit.HSPCLKDIV = 0;EPwm2Regs.TBCTL.bit.CLKDIV = 1;EPwm2Regs.TBCTR = 0x0000;// Clear timer counterEPwm2Regs.TBPRD = duty;// Set timer periodEPwm2Regs.TBPHS.bit.TBPHS = 0x0000; // Set timer phase//*****************************************EPwm2Regs.CMPA.bit.CMPA = duty;EPwm2Regs.CMPB.bit.CMPB = 0;//*****************************************EPwm2Regs.CMPCTL.all = 0x0; //計數器比較器的存取設定//01:CLR 10:SET 00:do nothingEPwm2Regs.AQCTLA.bit.ZRO = 0x0;EPwm2Regs.AQCTLA.bit.CAD = 0x8;EPwm2Regs.AQCTLA.bit.CBD = 0x4;//EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;EPwm2Regs.AQCTLB.bit.ZRO = 0x0;EPwm2Regs.AQCTLB.bit.CAD = 0x8;EPwm2Regs.AQCTLB.bit.CBD = 0x4;//EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;EPwm2Regs.AQSFRC.all = 0x0000;// Action-qualifier s/w force registerEPwm2Regs.AQCSFRC.all = 0x0000;// Action-qualifier continuous s/w force registerEPwm2Regs.DBCTL.all = 0x002B;// 決定上升下降延遲方式EPwm2Regs.DBRED.all = DeadTime;// rising edge delayEPwm2Regs.DBFED.all = DeadTime;// falling edge delayEPwm2Regs.PCCTL.bit.CHPEN = 0;// PWM chopper unit disabledEALLOW;EPwm2Regs.TZCLR.all = 0x0007;EPwm2Regs.TZSEL.all = 0x0008;//指定使用TZ4為觸發源EPwm2Regs.TZCTL.all = 0x000A;//以觸發TZ4使ePWM強制關閉EDIS;//EPwm1Regs.ETCLR.all = 0x004;//EPwm2Regs.ETSEL.all = 0xA09;EPwm2Regs.ETPS.all = 0x0005;//EPwm1Regs.TBCTL.bit.CTRMODE = 0x2; //上下數模式//-----ePWM1設定--------EPwm3Regs.TBCTL.all = 0xC031; //初始化Time base counter 的設wEPwm3Regs.TBCTL.bit.HSPCLKDIV = 0;EPwm3Regs.TBCTL.bit.CLKDIV = 1;EPwm3Regs.TBCTR = 0x0000;// Clear timer counterEPwm3Regs.TBPRD = duty;// Set timer periodEPwm3Regs.TBPHS.bit.TBPHS = 0x0000; // Set timer phase//*****************************************EPwm3Regs.CMPA.bit.CMPA = duty;EPwm3Regs.CMPB.bit.CMPB = 0;//*****************************************EPwm3Regs.CMPCTL.all = 0x0; //計數器比較器的存取設定//01:CLR 10:SET 00:do nothingEPwm3Regs.AQCTLA.bit.ZRO = 0x0;EPwm3Regs.AQCTLA.bit.CAD = 0x8;EPwm3Regs.AQCTLA.bit.CBD = 0x4;//EPwm3Regs.AQCTLA.bit.CAD = AQ_CLEAR;EPwm3Regs.AQCTLB.bit.ZRO = 0x0;EPwm3Regs.AQCTLB.bit.CAD = 0x8;EPwm3Regs.AQCTLB.bit.CBD = 0x4;//EPwm3Regs.AQCTLB.bit.CBD = AQ_CLEAR;EPwm3Regs.AQSFRC.all = 0x0000;// Action-qualifier s/w force registerEPwm3Regs.AQCSFRC.all = 0x0000;// Action-qualifier continuous s/w force registerEPwm3Regs.DBCTL.all = 0x002B;// 決定上升下降延遲方式EPwm3Regs.DBRED.all = DeadTime;// rising edge delayEPwm3Regs.DBFED.all = DeadTime;// falling edge delayEPwm3Regs.PCCTL.bit.CHPEN = 0;// PWM chopper unit disabledEALLOW;EPwm3Regs.TZCLR.all = 0x0007;EPwm3Regs.TZSEL.all = 0x0008;//指定使用TZ4為觸發源EPwm3Regs.TZCTL.all = 0x000A;//以觸發TZ4使ePWM強制關閉EDIS;//EPwm3Regs.ETCLR.all = 0x004;//EPwm3Regs.ETSEL.all = 0x0A09;EPwm3Regs.ETPS.all = 0x0005;//EPwm3Regs.TBCTL.bit.CTRMODE = 0x2; //上下數模式EPwm4Regs.TBCTL.all = 0xC031; //初始化Time base counter 的設wEPwm4Regs.TBCTL.bit.HSPCLKDIV = 0;EPwm4Regs.TBCTL.bit.CLKDIV = 1;EPwm4Regs.TBCTR = 0x0000;// Clear timer counterEPwm4Regs.TBPRD = duty;// Set timer periodEPwm4Regs.TBPHS.bit.TBPHS = 0x0000; // Set timer phase//*****************************************EPwm4Regs.CMPA.bit.CMPA = duty;EPwm4Regs.CMPB.bit.CMPB = 0;//*****************************************EPwm4Regs.CMPCTL.all = 0x0; //計數器比較器的存取設定//01:CLR 10:SET 00:do nothingEPwm4Regs.AQCTLA.bit.ZRO = 0x0;EPwm4Regs.AQCTLA.bit.CAD = 0x8;EPwm4Regs.AQCTLA.bit.CBD = 0x4;//EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;EPwm4Regs.AQCTLB.bit.ZRO = 0x0;EPwm4Regs.AQCTLB.bit.CAD = 0x8;EPwm4Regs.AQCTLB.bit.CBD = 0x4;//EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;EPwm4Regs.AQSFRC.all = 0x0000;// Action-qualifier s/w force registerEPwm4Regs.AQCSFRC.all = 0x0000;// Action-qualifier continuous s/w force registerEPwm4Regs.DBCTL.all = 0x002B;// 決定上升下降延遲方式EPwm4Regs.DBRED.all = DeadTime;// rising edge delayEPwm4Regs.DBFED.all = DeadTime;// falling edge delayEPwm4Regs.PCCTL.bit.CHPEN = 0;// PWM chopper unit disabledEALLOW;EPwm4Regs.TZCLR.all = 0x0007;EPwm4Regs.TZSEL.all = 0x0008;//指定使用TZ4為觸發源EPwm4Regs.TZCTL.all = 0x000A;//以觸發TZ4使ePWM強制關閉EDIS;//EPwm1Regs.ETCLR.all = 0x004;////ETSEL ZERO=0xA09 PRD=0xA0A ZERO&PRD=0xA0B CAU=0xA0C CAD=0xA0D CBU=0xA0E CBD=0xA0FEPwm4Regs.ETSEL.all = 0x0A0C;EPwm4Regs.ETPS.all = 0x0005;//EPwm1Regs.TBCTL.bit.CTRMODE = 0x2; //上下數模式//-----ePWM1設定--------EPwm5Regs.TBCTL.all = 0x4031; //初始化Time base counter 的設wEPwm5Regs.TBCTL.bit.HSPCLKDIV = 0;EPwm5Regs.TBCTL.bit.CLKDIV = 1;EPwm5Regs.TBCTR = 0x0000;// Clear timer counterEPwm5Regs.TBPRD = duty;// Set timer periodEPwm5Regs.TBPHS.bit.TBPHS = 0x0000; // Set timer phase//*****************************************EPwm5Regs.CMPA.bit.CMPA = duty;EPwm5Regs.CMPB.bit.CMPB = 0;//*****************************************EPwm5Regs.CMPCTL.all = 0x0; //計數器比較器的存取設定//01:CLR 10:SET 00:do nothingEPwm5Regs.AQCTLA.bit.ZRO = 0x0;EPwm5Regs.AQCTLA.bit.CAD = 0x8;EPwm5Regs.AQCTLA.bit.CBD = 0x4;//EPwm5Regs.AQCTLA.bit.CAD = AQ_CLEAR;EPwm5Regs.AQCTLB.bit.ZRO = 0x0;EPwm5Regs.AQCTLB.bit.CAD = 0x8;EPwm5Regs.AQCTLB.bit.CBD = 0x4;//EPwm5Regs.AQCTLB.bit.CBD = AQ_CLEAR;EPwm5Regs.AQSFRC.all = 0x0000;// Action-qualifier s/w force registerEPwm5Regs.AQCSFRC.all = 0x0000;// Action-qualifier continuous s/w force registerEPwm5Regs.DBCTL.all = 0x002B;// 決定上升下降延遲方式EPwm5Regs.DBRED.all = DeadTime;// rising edge delayEPwm5Regs.DBFED.all = DeadTime;// falling edge delayEPwm5Regs.PCCTL.bit.CHPEN = 0;// PWM chopper unit disabledEALLOW;EPwm5Regs.TZCLR.all = 0x0007;EPwm5Regs.TZSEL.all = 0x0008;//指定使用TZ4為觸發源EPwm5Regs.TZCTL.all = 0x000A;//以觸發TZ4使ePWM強制關閉EDIS;//EPwm5Regs.ETCLR.all = 0x004;////ETSEL ZERO=0xA09 PRD=0xA0A ZERO&PRD=0xA0B CAU=0xA0C CAD=0xA0D CBU=0xA0E CBD=0xA0FEPwm5Regs.ETSEL.all = 0x0A0E;EPwm5Regs.ETPS.all = 0x0005;//EPwm5Regs.TBCTL.bit.CTRMODE = 0x2; //上下數模式//-----ePWM1設定--------EPwm6Regs.TBCTL.all = 0x4031; //初始化Time base counter 的設wEPwm6Regs.TBCTL.bit.HSPCLKDIV = 0;EPwm6Regs.TBCTL.bit.CLKDIV = 1;EPwm6Regs.TBCTR = 0x0000;// Clear timer counterEPwm6Regs.TBPRD = duty;// Set timer periodEPwm6Regs.TBPHS.bit.TBPHS = 0x0000;// Set timer phaseEPwm6Regs.CMPA.bit.CMPA = duty;EPwm6Regs.CMPB.bit.CMPB = 0;EPwm6Regs.CMPCTL.all = 0x0; //計數器比較器的存取設定//01:CLR 10:SET 00:do nothingEPwm6Regs.AQCTLA.bit.ZRO = 0x0;EPwm6Regs.AQCTLA.bit.CAD = 0x8;EPwm6Regs.AQCTLA.bit.CBD = 0x4;//EPwm6Regs.AQCTLA.bit.CAD = AQ_CLEAR;EPwm6Regs.AQCTLB.bit.ZRO = 0x0;EPwm6Regs.AQCTLB.bit.CAD = 0x8;EPwm6Regs.AQCTLB.bit.CBD = 0x4;//EPwm6Regs.AQCTLB.bit.CBD = AQ_CLEAR;EPwm6Regs.AQSFRC.all = 0x0000;// Action-qualifier s/w force registerEPwm6Regs.AQCSFRC.all = 0x0000;// Action-qualifier continuous s/w force registerEPwm6Regs.DBCTL.all = 0x002B;// 決定上升下降延遲方式EPwm6Regs.DBRED.all = DeadTime;// rising edge delayEPwm6Regs.DBFED.all = DeadTime;// falling edge delayEPwm6Regs.PCCTL.bit.CHPEN = 0;// PWM chopper unit disabledEALLOW;EPwm6Regs.TZCLR.all = 0x0007;EPwm6Regs.TZSEL.all = 0x0008;//指定使用TZ4為觸發源EPwm6Regs.TZCTL.all = 0x000A;//以觸發TZ4使ePWM強制關閉EDIS;//EPwm6Regs.ETCLR.all = 0x004;////ETSEL ZERO=0xA09 PRD=0xA0A ZERO&PRD=0xA0B CAU=0xA0C CAD=0xA0D CBU=0xA0E CBD=0xA0FEPwm6Regs.ETSEL.all = 0x0A0E;EPwm6Regs.ETPS.all = 0x0005;//EPwm6Regs.TBCTL.bit.CTRMODE = 0x2; //上下數模式 // EALLOW;// Enable EALLOW protected register access // SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // HSPCLK to ePWM modules enabled // EDIS;// Disable EALLOW protected register access//----------- }
Green Deng:
你好,请问你是使用的TI例程吗?具体是基于哪个例程?
另外,你说的下属模式是指什么?
PS: 上传代码建议用输入框中的“插入 – 代码 – 语言:C”来进行上传
,
YE CHENG-SYUAN:
而我换成上下模式也是无法达成我想要的讯号,而例程主要是#include "F2837xD_Examples.h"
,
Green Deng:
请参考例程中的epwm_ex2_updown_aq.c:
C:\ti\c2000\C2000Ware_4_01_00_00\driverlib\f2837xd\examples\cpu1\epwm
,
YE CHENG-SYUAN:
我找到C2000Ware_4_01_00_00 ,但它无法让我下载
,
Green Deng:
无法下载会出现什么报错吗?
,
YE CHENG-SYUAN:
,
Green Deng:
你好,你是用公司内网下载的吗?是不是被公司的IT设置了限制?
,
YE CHENG-SYUAN:
我是用学校内网下载的,应该不会受到限制才对
,
Green Deng:
建议你试一下我个人网络,因为这个网站没有报告有这方面的情况,你这边无法下载极有可能是你自己的网络问题。
,
YE CHENG-SYUAN:
已经可以下载了,谢谢