1. 不對稱比較事件:
在週期比較和單次比較中使用陰影轉移的好處,是允許中心對齊模式提供非對稱比較事件。即時條件類似於處理邊緣對齊模式下的陰影值更新。
2. 單次模式:
單次模式下的計時器,可應用在觸發事件和觸發的操作之間調用一定延遲的應用程式,具有特定的作用,設置TSSM暫存器。例如,分流電流信號測量中的雜訊抑制。任何CAPCOM4計時器都可以設置為這種模式,以便與其他計時器、ADC或其他模組工作。
3. CCU4 configuration and LLD example code:
#include “xmc_ccu4.h”
/* CCU4 Compare Configuration */
XMC_CCU4_SLICE_COMPARE_CONFIG_t compare_config = {
.timer_mode = (uint32_t) XMC_CCU4_SLICE_TIMER_COUNT_MODE_EA,
.monoshot = (uint32_t) false,
.shadow_xfer_clear = (uint32_t) 0,
.dither_timer_period = (uint32_t) 0,
.dither_duty_cycle = (uint32_t) 0,
.prescaler_mode = (uint32_t) XMC_CCU4_SLICE_PRESCALER_MODE_NORMAL,
.mcm_enable = (uint32_t) 0,
.prescaler_initval = (uint32_t) 10, // prescaler = 2^10
.float_limit = (uint32_t) 0,
.dither_limit = (uint32_t) 0,
.passive_level = (uint32_t) XMC_CCU4_SLICE_OUTPUT_PASSIVE_LEVEL_LOW,
.timer_concatenation = (uint32_t) 0
};
/* CCU4 Capture Configuration */
XMC_CCU4_SLICE_CAPTURE_CONFIG_t capture_config = {
.fifo_enable = false,
.timer_clear_mode = XMC_CCU4_SLICE_TIMER_CLEAR_MODE_CAP_LOW,
.same_event = false,
.ignore_full_flag = true,
.prescaler_mode = XMC_CCU4_SLICE_PRESCALER_MODE_NORMAL,
.prescaler_initval = (uint32_t) 10,
.float_limit = (uint32_t) 0,
.timer_concatenation = (uint32_t) 0
};
/* CCU4 Event Configuration */
XMC_CCU4_SLICE_EVENT_CONFIG_t compare_event0_config = {
.mapped_input = XMC_CCU4_SLICE_INPUT_I, /* mapped to SCU.GSC40 */
.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_RISING_EDGE,
.level = XMC_CCU4_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_HIGH,
.duration = XMC_CCU4_SLICE_EVENT_FILTER_3_CYCLES
};
XMC_CCU4_SLICE_EVENT_CONFIG_t capture_event0_config = {
//off time capture
.mapped_input = XMC_CCU4_SLICE_INPUT_C, //CAPTURE on P0.1
.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
};
XMC_CCU4_SLICE_EVENT_CONFIG_t capture_event1_config = {
//on time capture
.mapped_input = XMC_CCU4_SLICE_INPUT_C, //CAPTURE on P0.1
.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_FALLING_EDGE,
.level = XMC_CCU4_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_HIGH,
.duration = XMC_CCU4_SLICE_EVENT_FILTER_7_CYCLES
};
/* GPIO Configuration */
XMC_GPIO_CONFIG_t SLICE0_OUTPUT_config = {
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT4,
.input_hysteresis = XMC_GPIO_INPUT_HYSTERESIS_STANDARD,
.output_level = XMC_GPIO_OUTPUT_LEVEL_LOW,
};
// Set up the system clock
XMC_SCU_CLOCK_Init(&clock_config);
// Enable prescaler clock
XMC_CCU4_Init(MODULE_PTR, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR);
// Start the prescaler clock
XMC_CCU4_StartPrescaler(MODULE_PTR);
// Start of CCU4 configurations
XMC_CCU4_SetModuleClock(MODULE_PTR, XMC_CCU4_CLOCK_SCU);
// Initialize the CCU4 slice
XMC_CCU4_SLICE_CompareInit(COMPARE_SLICE_PTR, &compare_config);
XMC_CCU4_SLICE_CaptureInit(CAPTURE_SLICE_PTR, &capture_config);
// Set duty cycle
XMC_CCU4_SLICE_SetTimerCompareMatch(COMPARE_SLICE_PTR, 93750U);
XMC_CCU4_SLICE_SetTimerPeriodMatch(COMPARE_SLICE_PTR, 140625U);
// Enable shadow transfer
XMC_CCU4_EnableShadowTransfer(MODULE_PTR, (uint32_t)(XMC_CCU4_SHADOW_TRANSFER_SLICE_0 | XMC_CCU4_SHADOW_TRANSFER_PRESCALER_SLICE_0));
XMC_CCU4_EnableShadowTransfer(MODULE_PTR, (uint32_t)(XMC_CCU4_SHADOW_TRANSFER_SLICE_0 | XMC_CCU4_SHADOW_TRANSFER_PRESCALER_SLICE_1));
// Enable External Start to Event 0
XMC_CCU4_SLICE_ConfigureEvent(COMPARE_SLICE_PTR, XMC_CCU4_SLICE_EVENT_0, &Compare_event0_config);
XMC_CCU4_SLICE_Capture0Config(CAPTURE_SLICE_PTR, XMC_CCU4_SLICE_EVENT_0);
XMC_CCU4_SLICE_Capture1Config(CAPTURE_SLICE_PTR, XMC_CCU4_SLICE_EVENT_1);
XMC_CCU4_SLICE_ConfigureEvent(CAPTURE_SLICE_PTR, XMC_CCU4_SLICE_EVENT_0, &capture_event0_config);
XMC_CCU4_SLICE_ConfigureEvent(CAPTURE_SLICE_PTR, XMC_CCU4_SLICE_EVENT_1, &capture_event1_config);
XMC_CCU4_SLICE_StartConfig(COMPARE_SLICE_PTR, XMC_CCU4_SLICE_EVENT_0, XMC_CCU4_SLICE_START_MODE_TIMER_START_CLEAR);
// Enable compare match events
XMC_CCU4_SLICE_EnableEvent(COMPARE_SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP);
XMC_CCU4_SLICE_EnableEvent(CAPTURE_SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_EVENT1);
// Connect compare match event to SR0
XMC_CCU4_SLICE_SetInterruptNode(COMPARE_SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP, XMC_CCU4_SLICE_SR_ID_0);
XMC_CCU4_SLICE_SetInterruptNode(CAPTURE_SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_EVENT1, XMC_CCU4_SLICE_SR_ID_2);
// Set NVIC priority
NVIC_SetPriority(CCU40_0_IRQn, 3U);
NVIC_SetPriority(CCU40_2_IRQn, 3U);
// Enable IRQ
NVIC_EnableIRQ(CCU40_0_IRQn);
NVIC_SetPriority(CCU40_2_IRQn, 3U);
// Enable CCU4 PWM output
XMC_GPIO_Init(SLICE0_OUTPUT, &SLICE0_OUTPUT_config);
// Enable clock
XMC_CCU4_EnableClock(MODULE_PTR, COMPARE_SLICE_NUMBER);
XMC_CCU4_EnableClock(MODULE_PTR, CAPTURE_SLICE_NUMBER);
// Start the Timer
XMC_CCU4_SLICE_StartTimer(COMPARE_SLICE_PTR);
XMC_CCU4_SLICE_StartTimer(CAPTURE_SLICE_PTR);
4. 資料來源:
(1) Peripheral - Capture and Compare Unit 4 (CCU4)
(2) AP32287 - XMC1000/XMC4000 - Capture Compare Unit 4 (CCU4)
(3) XMC4700 XMC4800 Reference Manual