Hi everyone, I'm trying to start and clear timer on falling edge on the pin and stop&read timer value on the rising edge. Do you have some idea?
Code:
XMC_CCU4_SLICE_COMPARE_CONFIG_t SLICE0_config =
{
.timer_mode = XMC_CCU4_SLICE_TIMER_COUNT_MODE_EA,
.monoshot = XMC_CCU4_SLICE_TIMER_REPEAT_MODE_SINGLE,
.shadow_xfer_clear = 0,
.dither_timer_period = 0,
.dither_duty_cycle = 0,
.prescaler_mode = XMC_CCU4_SLICE_PRESCALER_MODE_NORMAL,
.mcm_enable = 0,
.prescaler_initval = XMC_CCU4_SLICE_PRESCALER_32768,
.float_limit = 0,
.dither_limit = 0,
.passive_level = XMC_CCU4_SLICE_OUTPUT_PASSIVE_LEVEL_LOW,
.timer_concatenation = 0
};
XMC_CCU4_SLICE_EVENT_CONFIG_t timer_start_config =
{
.mapped_input = CCU40_IN0_P0_12,
.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_FALLING_EDGE,
.level = XMC_CCU4_SLICE_EVENT_LEVEL_SENSITIVITY_COUNT_UP_ON_LOW,
.duration = XMC_CCU4_SLICE_EVENT_FILTER_7_CYCLES
};
XMC_CCU4_SLICE_EVENT_CONFIG_t timer_stop_config =
{
.mapped_input = CCU40_IN0_P0_12,
.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_RISING_EDGE,
.level = XMC_CCU4_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_HIGH,
.duration = XMC_CCU4_SLICE_EVENT_FILTER_7_CYCLES
};
int main(void)
{
XMC_SCU_CLOCK_Init(&clock_config);
XMC_CCU4_Init(CCU40, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR_PCMP);
XMC_CCU4_StartPrescaler(CCU40);
XMC_CCU4_SetModuleClock(CCU40, XMC_CCU4_CLOCK_SCU);
XMC_CCU4_SLICE_CompareInit(CCU40_CC40, &SLICE0_config);
XMC_CCU4_EnableShadowTransfer(CCU40, (XMC_CCU4_SHADOW_TRANSFER_SLICE_0 | XMC_CCU4_SHADOW_TRANSFER_PRESCALER_SLICE_0));
XMC_CCU4_SLICE_ConfigureEvent(CCU40_CC40, XMC_CCU4_SLICE_EVENT_0, &timer_start_config);
XMC_CCU4_SLICE_ConfigureEvent(CCU40_CC40, XMC_CCU4_SLICE_EVENT_1, &timer_stop_config);
XMC_CCU4_SLICE_StartConfig(CCU40_CC40, XMC_CCU4_SLICE_EVENT_0, XMC_CCU4_SLICE_START_MODE_TIMER_START_CLEAR);
XMC_CCU4_SLICE_StopConfig(CCU40_CC40, XMC_CCU4_SLICE_EVENT_1, XMC_CCU4_SLICE_END_MODE_TIMER_STOP);
XMC_CCU4_SLICE_SetInterruptNode(CCU40_CC40, XMC_CCU4_SLICE_IRQ_ID_EVENT1, XMC_CCU4_SLICE_SR_ID_1);
XMC_CCU4_SLICE_EnableEvent(CCU40_CC40, XMC_CCU4_SLICE_IRQ_ID_EVENT0);
XMC_CCU4_SLICE_EnableEvent(CCU40_CC40, XMC_CCU4_SLICE_IRQ_ID_EVENT1);
__NVIC_SetPriority(CCU40_1_IRQn, 3U);
__NVIC_EnableIRQ(CCU40_1_IRQn);
XMC_CCU4_EnableClock(CCU40, 0);
while (1)
{
}
}
void CCU40_1_IRQHandler(void)
{
XMC_CCU4_SLICE_ClearEvent(CCU40_CC40, XMC_CCU4_SLICE_IRQ_ID_EVENT0);
XMC_CCU4_SLICE_ClearEvent(CCU40_CC40, XMC_CCU4_SLICE_IRQ_ID_EVENT1);
Button_MeasuredTime = XMC_CCU4_SLICE_GetTimerValue(CCU40_CC40);
test_flag++;
if (Button_MeasuredTime < ButtonShortPush_threshold) {}
else if ((ButtonShortPush_threshold < Button_MeasuredTime) & (Button_MeasuredTime < ButtonLongPush_threshold))
{
ButtonLongPush_flag = false;
ButtonShortPush_flag = true;
}
else if ((ButtonLongPush_threshold < Button_MeasuredTime) & (Button_MeasuredTime < ButtonStuck_threshold))
{
ButtonLongPush_flag = true;
ButtonShortPush_flag = false;
}
else
{
reset_button();
erase_push_flags();
}
}