PWM配置为向上计数,中断内部设置一个IO翻转,通过示波器观察波形,发现IO翻转的频率正好是PWM频率的一半。
PWM配置:
void InitEPwm7Example()
{
EPwm7Regs.TBPRD = 1000; // Set timer period 6000 408
EPwm7Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm7Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm7Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm7Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm7Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm7Regs.TBCTL.bit.CLKDIV = TB_DIV1; // TB_DIV4 = 0x02
EPwm7Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm7Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm7Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
// EPwm7Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm7Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
// EPwm7Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm7Regs.CMPA.half.CMPA = 500; //3000
// Set actions
// EPwm7Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on CAU
EPwm7Regs.AQCTLA.bit.CAU = AQ_SET; // Clear PWM1A on CAD
EPwm7Regs.AQCTLA.bit.PRD = AQ_CLEAR;
// EPwm7Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Clear PWM1B on CAU
// EPwm7Regs.AQCTLB.bit.CAD = AQ_SET; // Set PWM1B on CAD
// Active Low PWMs – Setup Deadband
// EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
// EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
// EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
// EPwm1Regs.DBRED = EPWM1_MIN_DB;
// EPwm1Regs.DBFED = EPWM1_MIN_DB;
// EPwm1_DB_Direction = DB_UP;
// Interrupt where we will change the Deadband
EPwm7Regs.ETSEL.bit.INTSEL = ET_CTRU_CMPA; // Select INT on Zero event
EPwm7Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm7Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 3rd event
// EPwm7Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
// EPwm7Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from CMPA on upcount
// EPwm7Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
}
求TI大神帮忙看下。。。
B Z:跪求TI大神帮忙看下。。
PWM配置为向上计数,中断内部设置一个IO翻转,通过示波器观察波形,发现IO翻转的频率正好是PWM频率的一半。
PWM配置:
void InitEPwm7Example()
{
EPwm7Regs.TBPRD = 1000; // Set timer period 6000 408
EPwm7Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm7Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm7Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm7Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm7Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm7Regs.TBCTL.bit.CLKDIV = TB_DIV1; // TB_DIV4 = 0x02
EPwm7Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm7Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm7Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
// EPwm7Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm7Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
// EPwm7Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm7Regs.CMPA.half.CMPA = 500; //3000
// Set actions
// EPwm7Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on CAU
EPwm7Regs.AQCTLA.bit.CAU = AQ_SET; // Clear PWM1A on CAD
EPwm7Regs.AQCTLA.bit.PRD = AQ_CLEAR;
// EPwm7Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Clear PWM1B on CAU
// EPwm7Regs.AQCTLB.bit.CAD = AQ_SET; // Set PWM1B on CAD
// Active Low PWMs – Setup Deadband
// EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
// EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
// EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
// EPwm1Regs.DBRED = EPWM1_MIN_DB;
// EPwm1Regs.DBFED = EPWM1_MIN_DB;
// EPwm1_DB_Direction = DB_UP;
// Interrupt where we will change the Deadband
EPwm7Regs.ETSEL.bit.INTSEL = ET_CTRU_CMPA; // Select INT on Zero event
EPwm7Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm7Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 3rd event
// EPwm7Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
// EPwm7Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from CMPA on upcount
// EPwm7Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
}
求TI大神帮忙看下。。。
B Z:跪求TI大神帮忙看下。。
PWM配置为向上计数,中断内部设置一个IO翻转,通过示波器观察波形,发现IO翻转的频率正好是PWM频率的一半。
PWM配置:
void InitEPwm7Example()
{
EPwm7Regs.TBPRD = 1000; // Set timer period 6000 408
EPwm7Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm7Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm7Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm7Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm7Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm7Regs.TBCTL.bit.CLKDIV = TB_DIV1; // TB_DIV4 = 0x02
EPwm7Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm7Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm7Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
// EPwm7Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm7Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
// EPwm7Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm7Regs.CMPA.half.CMPA = 500; //3000
// Set actions
// EPwm7Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on CAU
EPwm7Regs.AQCTLA.bit.CAU = AQ_SET; // Clear PWM1A on CAD
EPwm7Regs.AQCTLA.bit.PRD = AQ_CLEAR;
// EPwm7Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Clear PWM1B on CAU
// EPwm7Regs.AQCTLB.bit.CAD = AQ_SET; // Set PWM1B on CAD
// Active Low PWMs – Setup Deadband
// EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
// EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
// EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
// EPwm1Regs.DBRED = EPWM1_MIN_DB;
// EPwm1Regs.DBFED = EPWM1_MIN_DB;
// EPwm1_DB_Direction = DB_UP;
// Interrupt where we will change the Deadband
EPwm7Regs.ETSEL.bit.INTSEL = ET_CTRU_CMPA; // Select INT on Zero event
EPwm7Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm7Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 3rd event
// EPwm7Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
// EPwm7Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from CMPA on upcount
// EPwm7Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
}
求TI大神帮忙看下。。。
B Z:
回复 Igor An:
GpioDataRegs.GPADAT.bit.GPIO3 = Led;Led = !Led;
中断里面设置的翻转,不是用的Toggle命令,这样也是一半吗?
PWM配置为向上计数,中断内部设置一个IO翻转,通过示波器观察波形,发现IO翻转的频率正好是PWM频率的一半。
PWM配置:
void InitEPwm7Example()
{
EPwm7Regs.TBPRD = 1000; // Set timer period 6000 408
EPwm7Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm7Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm7Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm7Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm7Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm7Regs.TBCTL.bit.CLKDIV = TB_DIV1; // TB_DIV4 = 0x02
EPwm7Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm7Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm7Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
// EPwm7Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm7Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
// EPwm7Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm7Regs.CMPA.half.CMPA = 500; //3000
// Set actions
// EPwm7Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on CAU
EPwm7Regs.AQCTLA.bit.CAU = AQ_SET; // Clear PWM1A on CAD
EPwm7Regs.AQCTLA.bit.PRD = AQ_CLEAR;
// EPwm7Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Clear PWM1B on CAU
// EPwm7Regs.AQCTLB.bit.CAD = AQ_SET; // Set PWM1B on CAD
// Active Low PWMs – Setup Deadband
// EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
// EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
// EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
// EPwm1Regs.DBRED = EPWM1_MIN_DB;
// EPwm1Regs.DBFED = EPWM1_MIN_DB;
// EPwm1_DB_Direction = DB_UP;
// Interrupt where we will change the Deadband
EPwm7Regs.ETSEL.bit.INTSEL = ET_CTRU_CMPA; // Select INT on Zero event
EPwm7Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm7Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 3rd event
// EPwm7Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
// EPwm7Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from CMPA on upcount
// EPwm7Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
}
求TI大神帮忙看下。。。
B Z:
回复 Igor An:
已经想明白了,谢谢你的回复