【Infineon XMC 应用笔记】 XMC1000 and XMC4000 CCU4 捕获比较单元 Part 2

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)

https://www.infineon.com/dgdl/Infineon-IP_CCU4_XMC-TR-v01_02-EN.pdf?fileId=5546d4624ad04ef9014b0780bb082263

(2) AP32287 - XMC1000/XMC4000 - Capture Compare Unit 4 (CCU4)

https://www.infineon.com/dgdl/Infineon-CCU4-XMC1000_XMC4000-AP32287-AN-v01_01-EN.pdf?fileId=5546d4624e765da5014ed8dd0f4614c0

(3) XMC4700 XMC4800 Reference Manual

https://www.infineon.com/dgdl/Infineon-ReferenceManual_XMC4700_XMC4800-UM-v01_03-EN.pdf?fileId=5546d462518ffd850151904eb90c0044

★博文内容均由个人提供,与平台无关,如有违法或侵权,请与网站管理员联系。

★博文作者未开放评论功能