We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello all. I have been looking at the ccu4_timer sample program and decided to upload it to my xmc4500 hexagon board. Now I am trying to output the ccu4 timer onto a gpio on the extension card that comes with this xmc4500 kit. The reason I want to output this timer to an external gpio pin is because I want to stick a logic analyzer probe on it and measure the period to see how often the interrupt is triggering. Is it operating at 1ms? 10ms? 100ms?...etc. I will be using pin 41 of the extension card.
My setup: http://imgur.com/0ue0MRt
Related MCU pin: http://imgur.com/p4mDG0o
The code in main.c of ccu4_timer:
/********************************************************************************************************************* * HEADER FILES ********************************************************************************************************************/ #include <xmc_ccu4.h> #include <xmc_scu.h> #include "stdio.h" #include "XMC4500.h" /********************************************************************************************************************* * MACROS ********************************************************************************************************************/ #define SLICE_PTR CCU42_CC43 #define MODULE_PTR CCU42 #define MODULE_NUMBER (2U) #define SLICE_NUMBER (3U) #define CAPCOM_MASK (SCU_GENERAL_CCUCON_GSC42_Msk) /**< Only CCU42 */ /********************************************************************************************************************* * GLOBAL DATA ********************************************************************************************************************/ XMC_CCU4_SLICE_COMPARE_CONFIG_t g_timer_object = { .timer_mode = XMC_CCU4_SLICE_TIMER_COUNT_MODE_EA, .monoshot = true, .shadow_xfer_clear = 0U, .dither_timer_period = 0U, .dither_duty_cycle = 0U, .prescaler_mode = XMC_CCU4_SLICE_PRESCALER_MODE_NORMAL, .mcm_enable = 0U, .prescaler_initval = 0U, .float_limit = 0U, .dither_limit = 0U, .passive_level = XMC_CCU4_SLICE_OUTPUT_PASSIVE_LEVEL_LOW, .timer_concatenation = 0U }; /* CCU Slice Capture Initialization Data */ XMC_CCU4_SLICE_CAPTURE_CONFIG_t g_capture_object = { .fifo_enable = false, .timer_clear_mode = XMC_CCU4_SLICE_TIMER_CLEAR_MODE_NEVER, .same_event = false, .ignore_full_flag = false, .prescaler_mode = XMC_CCU4_SLICE_PRESCALER_MODE_NORMAL, .prescaler_initval = 0, .float_limit = 0, .timer_concatenation = false }; /* Interrupt counters */ volatile uint32_t g_num_period_interrupts; volatile uint32_t g_num_compare_interrupts; volatile bool period_match; /********************************************************************************************************************* * MAIN APPLICATION ********************************************************************************************************************/ /* Interrupt handlers */ void CCU42_0_IRQHandler(void) { g_num_period_interrupts++; XMC_CCU4_SLICE_ClearEvent(SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH); period_match = true; } void CCU42_1_IRQHandler(void) { g_num_compare_interrupts++; XMC_SCU_SetCcuTriggerLow(CAPCOM_MASK); XMC_CCU4_SLICE_ClearEvent(SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP); } int main(void) { /* Local variable which holds configuration of Event-1 */ XMC_CCU4_SLICE_EVENT_CONFIG_t config; config.duration = XMC_CCU4_SLICE_EVENT_FILTER_5_CYCLES; config.edge = XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_RISING_EDGE; config.level = XMC_CCU4_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_HIGH; /* Not needed */ config.mapped_input = XMC_CCU4_SLICE_INPUT_I; /* Ensure fCCU reaches CCU42 */ XMC_CCU4_SetModuleClock(MODULE_PTR, XMC_CCU4_CLOCK_SCU); XMC_CCU4_Init(MODULE_PTR, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR); /* Get the slice out of idle mode */ XMC_CCU4_EnableClock(MODULE_PTR, SLICE_NUMBER); /* Start the prescaler and restore clocks to slices */ XMC_CCU4_StartPrescaler(MODULE_PTR); /* Initialize the Slice */ XMC_CCU4_SLICE_CompareInit(SLICE_PTR, &g_timer_object); /* Enable compare match and period match events */ XMC_CCU4_SLICE_EnableEvent(SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH); XMC_CCU4_SLICE_EnableEvent(SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP); /* Connect period match event to SR0 */ XMC_CCU4_SLICE_SetInterruptNode(SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH, XMC_CCU4_SLICE_SR_ID_0); /* Connect compare match event to SR1 */ XMC_CCU4_SLICE_SetInterruptNode(SLICE_PTR, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP, XMC_CCU4_SLICE_SR_ID_1); /* Configure NVIC */ /* Set priority */ NVIC_SetPriority(CCU42_0_IRQn, 10U); NVIC_SetPriority(CCU42_1_IRQn, 10U); /* Enable IRQ */ NVIC_EnableIRQ(CCU42_0_IRQn); NVIC_EnableIRQ(CCU42_1_IRQn); /* Program a very large value into PR and CR */ XMC_CCU4_SLICE_SetTimerPeriodMatch(SLICE_PTR, 65500U); XMC_CCU4_SLICE_SetTimerCompareMatch(SLICE_PTR, 32000U); /* Enable shadow transfer */ XMC_CCU4_EnableShadowTransfer(MODULE_PTR, XMC_CCU4_SHADOW_TRANSFER_SLICE_3); /* Configure Event-1 and map it to Input-I */ XMC_CCU4_SLICE_ConfigureEvent(SLICE_PTR, XMC_CCU4_SLICE_EVENT_1, &config); /* Map Event-1 to Start function */ XMC_CCU4_SLICE_StartConfig(SLICE_PTR, XMC_CCU4_SLICE_EVENT_1, XMC_CCU4_SLICE_START_MODE_TIMER_START_CLEAR); /* Generate an external start trigger */ XMC_SCU_SetCcuTriggerHigh(CAPCOM_MASK); period_match = false; while(1U) { while(false == period_match); period_match = false; /* Generate an external start trigger */ XMC_SCU_SetCcuTriggerHigh(CAPCOM_MASK); } }
Any help is greatly appreciated.
Hi Per. Please give complete detail this time. Can you send me the code.