本帖最后由 defalut 于 2014-6-18 19:54 编辑
FSL_TICS_Robin 发表于 2014-6-18 13:58
像这种与时钟分频、倍频有关的参数,如果你是用PE配置生成的。
那么只需要在参数配置界面的Clock path界 ...
再请教一个问题。 如何把KL26的脉宽检测实例, 将互补对称模式改成 单路模式,我屏蔽了一路,留下
TPM0的ch1产生PWM, 然后用TPM1的ch1检测TPM0产生的脉宽。 发现不是下降沿进入TPM1中断。
Change PWM duty: 0-9 (0-90%)
5
Press any key to detect pulse width
Measured Pulse width: 2400 TPM1 cycles
Change PWM duty: 0-9 (0-90%)
5
Press any key to detect pulse width
Measured Pulse width: 7201 TPM1 cycles
Change PWM duty: 0-9 (0-90%)
void SIM_Init(void)
{
SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1);
SIM_SOPT2 &= ~SIM_SOPT2_PLLFLLSEL_MASK;
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK| SIM_SCGC5_PORTC_MASK;
SIM_SCGC6 |= SIM_SCGC6_TPM0_MASK| SIM_SCGC6_TPM1_MASK;
}
/***************************************************************************//*!
* @brief PORT module initialization.
******************************************************************************/
void PORT_Init(void)
{
//PORTA_PCR12 = PORT_PCR_ISF_MASK |PORT_PCR_MUX(0x3);
PORTA_PCR13 = PORT_PCR_ISF_MASK |PORT_PCR_MUX(0x3);
PORTC_PCR2 = PORT_PCR_ISF_MASK |PORT_PCR_MUX(0x4)| PORT_PCR_DSE_MASK;
//PORTC_PCR1 = PORT_PCR_ISF_MASK |PORT_PCR_MUX(0x4)| PORT_PCR_DSE_MASK; /* TMP0_CH0 located on PTC1 on FRDM KL26Z. TMP0_CH2 not broken out on FRMD KL26Z. */
}
/***************************************************************************//*!
* @brief TPM0 module initialization.
******************************************************************************/
void TPM0_Init(void)
{
enable_irq(17); set_irq_priority(17, 3);
TPM0_CNT = 0;
TPM0_MOD = 0x12C0;
TPM0_SC = TPM_SC_TOIE_MASK|TPM_SC_CMOD(1);
TPM0_C1SC = TPM_CnSC_MSB_MASK| TPM_CnSC_ELSB_MASK; /* TMP0_CH1 */
TPM0_C1V = 0x00;
//TPM0_C0SC = TPM_CnSC_MSB_MASK| TPM_CnSC_ELSA_MASK; /* TMP0_CH0 */
//TPM0_C0V = 0x00;
}
/***************************************************************************//*!
* @brief TPM1 module initialization.
******************************************************************************/
void TPM1_Init(void)
{
enable_irq(18); set_irq_priority(18, 1);
TPM1_CONF = TPM_CONF_TRGSEL(8)|TPM_CONF_CSOO_MASK|TPM_CONF_CSOT_MASK;
TPM1_CNT = 0;
TPM1_MOD = 0x2BC0;
TPM1_SC = TPM_SC_TOIE_MASK|TPM_SC_CMOD(1);
//TPM1_C0SC = TPM_CnSC_ELSA_MASK;
//TPM1_C0V = 0x00;
TPM1_C1SC = TPM_CnSC_ELSB_MASK;
TPM1_C1V = 0x00;
}
/***************************************************************************//*!
* @brief TPM0 overflow interrupt service routine.
******************************************************************************/
void tpm0_isr(void)
{
TPM0_SC |= TPM_SC_TOF_MASK;
TPM0_C1V = (uint16)u16PWMDuty; /* TMP0_CH1 */
//TPM0_C0V = (uint16)u16PWMDuty; /* TMP0_CH0 */
}
/***************************************************************************//*!
* @brief TPM1 overflow interrupt service routine.
******************************************************************************/
void tpm1_isr(void)
{
int16 TPM_c0v = 0, TPM_c1v = 0;
TPM1_SC |= TPM_SC_TOF_MASK;
TPM_c1v = (int16)TPM1_C1V;
//TPM_c0v = (int16)TPM1_C0V;
//i16PulseWidth = TPM_c1v - TPM_c0v;
i16PulseWidth = TPM_c1v;
//TPM1_C0SC |= TPM_CnSC_CHF_MASK;
TPM1_C1SC |= TPM_CnSC_CHF_MASK;
}
|