CC4 Timer w/ XMCLib

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
atvmainiac
Level 1
Level 1
5 questions asked 10 sign-ins First solution authored

Im using the XMC1100 boot kit board, and attempting to toggle the on board leds with an interrupt generated by the CC4 timers. While using the XMClib rather than the Dave Apps. im not 100% sure where im going wrong in my code, and still a bit confused on all of the functions required to get a simple timer , and interrupt generated. Could someone go through my code, maybe point out where im going wrong, and also point out the bare min for a simple timer/ interrupt generation while im learning how to use the CC4?

The current code compiles with no errors, but the LED will turn on, but never toggles, so im assuming the interrupt is never being called.

Code below.

 

#include "stdio.h"
#include "DAVE.h" //Declarations from DAVE Code Generation (includes SFR declaration)
#include <xmc_ccu4.h>
#include <xmc_gpio.h>
#include <xmc_scu.h>


#define MODULE_PTR CCU40 //Module
#define MODULE_NUMBER (0U) //Unsure
#define SLICE0_PTR CCU40_CC40 //Specific Slice in module CCU 40
#define SLICE0_NUMBER (0U) //Slice #?
#define SLICE0_OUTPUT P0_0
#define LED P0_5
#define LED2 P0_6

// APP START

 


void toggle(void){
XMC_GPIO_ToggleOutput(LED2);
XMC_GPIO_ToggleOutput(LED);
}


// SYSTEM CLOCK CONFIG
XMC_SCU_CLOCK_CONFIG_t sclk =
{
.pclk_src=XMC_SCU_CLOCK_PCLKSRC_DOUBLE_MCLK,
.rtc_src=XMC_SCU_CLOCK_RTCCLKSRC_DCO2,
.fdiv = 0,
.idiv = 4,
};

 

XMC_CCU4_SLICE_COMPARE_CONFIG_t timer = {
.timer_mode = (uint32_t)XMC_CCU4_SLICE_TIMER_COUNT_MODE_EA,
.monoshot = (uint32_t)XMC_CCU4_SLICE_TIMER_REPEAT_MODE_REPEAT,
.shadow_xfer_clear = false,
.dither_timer_period = false,
.dither_duty_cycle = false,
.prescaler_mode = (uint32_t)XMC_CCU4_SLICE_PRESCALER_MODE_NORMAL,
.mcm_enable = false,
.prescaler_initval = XMC_CCU4_SLICE_PRESCALER_4096,
.float_limit = 0,
.dither_limit = 0,
.passive_level = XMC_CCU4_SLICE_OUTPUT_PASSIVE_LEVEL_LOW,
.timer_concatenation = false
};

XMC_CCU4_SLICE_EVENT_CONFIG_t SLICE0_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
};

int main(void)
{

XMC_SCU_CLOCK_Init(&sclk);


XMC_CCU4_Init(CCU40_CC40, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR);
XMC_CCU4_SetModuleClock(CCU40_CC40, XMC_CCU4_CLOCK_SCU);
XMC_CCU4_SLICE_CompareInit(CCU40_CC40, &timer);
XMC_CCU4_SLICE_SetTimerCompareMatch(CCU40_CC40, 10);
XMC_CCU4_SLICE_SetTimerPeriodMatch(CCU40_CC40, 20);
XMC_CCU4_EnableShadowTransfer(CCU40, XMC_CCU4_SHADOW_TRANSFER_SLICE_0);
XMC_CCU4_SLICE_EnableEvent(CCU40_CC40, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP);
XMC_CCU4_SLICE_SetInterruptNode(CCU40_CC40, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP, XMC_CCU4_SLICE_SR_ID_1);
XMC_CCU4_EnableClock(CCU40_CC40, (0U));
NVIC_SetPriority(CCU40_1_IRQn, 3U);
NVIC_EnableIRQ(CCU40_1_IRQn);
XMC_CCU4_SLICE_StartTimer(CCU40_CC40);

 

//On Board LED Config
XMC_GPIO_CONFIG_t OBL =
{
OBL.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
OBL.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH,
};

//Pin Initialize
XMC_GPIO_Init(LED, &OBL);
XMC_GPIO_Init(LED2, &OBL);
XMC_GPIO_SetOutputLow(LED);
}
void IRQ_Hdlr_22(void)
{
toggle();
};

 

0 Likes
1 Solution
atvmainiac
Level 1
Level 1
5 questions asked 10 sign-ins First solution authored

Turns out, i had my math values all wrong(knew they couldnt have been right from the get go) when i set up my timer slice up, after i did some reading turns out i just needed to change some of my math around. Kept thinking I didnt set the functions up right for the XMC library. Turns out i got it all right minus the shadow register location. The proper values are below.

 

.prescaler_initval = 11

Period Math = 31249

Compare match = 15625

This is the math i chose, loaded the file and it worked as it should. Just needed the right math to accomplish the job.

View solution in original post

0 Likes
3 Replies
atvmainiac
Level 1
Level 1
5 questions asked 10 sign-ins First solution authored

I realized i had quite a few initialization function parameters wrong for the CCU, so I changed them, and corrected my original errors, plus cleaned up the code a little bit and got rid of the parts that were not being used. with that said, i still have the original problem where the LED will turn on, but never toggles, like the interrupt is not being called. heres an updated copy.

 

#include "stdio.h"
#include "DAVE.h" //Declarations from DAVE Code Generation (includes SFR declaration)
#include <xmc_ccu4.h>
#include <xmc_gpio.h>
#include <xmc_scu.h>

#define LED P0_5
#define LED2 P0_6

// APP START

// SYSTEM CLOCK CONFIG
XMC_SCU_CLOCK_CONFIG_t sclk =
{
.pclk_src=XMC_SCU_CLOCK_PCLKSRC_DOUBLE_MCLK,
.rtc_src=XMC_SCU_CLOCK_RTCCLKSRC_DCO2,
.fdiv = 0,
.idiv = 1,
};


//Slice Config
XMC_CCU4_SLICE_COMPARE_CONFIG_t timer = {
.timer_mode = (uint32_t)XMC_CCU4_SLICE_TIMER_COUNT_MODE_EA,
.monoshot = (uint32_t)XMC_CCU4_SLICE_TIMER_REPEAT_MODE_REPEAT,
.shadow_xfer_clear = false,
.dither_timer_period = false,
.dither_duty_cycle = false,
.prescaler_mode = (uint32_t)XMC_CCU4_SLICE_PRESCALER_MODE_NORMAL,
.mcm_enable = false,
.prescaler_initval = XMC_CCU4_SLICE_PRESCALER_1,
.float_limit = 0,
.dither_limit = 0,
.passive_level = XMC_CCU4_SLICE_OUTPUT_PASSIVE_LEVEL_LOW,
.timer_concatenation = false
};


int main(void)
{

XMC_SCU_CLOCK_Init(&sclk);

XMC_CCU4_EnableModule(CCU40);
XMC_CCU4_Init(CCU40, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR);
XMC_CCU4_StartPrescaler(CCU40);
XMC_CCU4_SetModuleClock(CCU40, XMC_CCU4_CLOCK_SCU);
XMC_CCU4_EnableShadowTransfer(CCU40, XMC_CCU4_SHADOW_TRANSFER_SLICE_0);
XMC_CCU4_SLICE_CompareInit(CCU40_CC41, &timer);

XMC_CCU4_SLICE_SetTimerCompareMatch(CCU40_CC41, 200u);
XMC_CCU4_SLICE_SetTimerPeriodMatch(CCU40_CC41, 210u);

XMC_CCU4_SLICE_EnableEvent(CCU40_CC41, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP);
XMC_CCU4_SLICE_SetInterruptNode(CCU40_CC41, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP, XMC_CCU4_SLICE_SR_ID_0);
NVIC_SetPriority(CCU40_0_IRQn, 3U);
NVIC_EnableIRQ(CCU40_0_IRQn);
XMC_CCU4_EnableClock(CCU40, 1);
XMC_CCU4_SLICE_StartTimer(CCU40_CC41);

 

//On Board LED Config
XMC_GPIO_CONFIG_t OBL =
{
OBL.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
OBL.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH,
};

//Pin Initialize
XMC_GPIO_Init(LED, &OBL);
XMC_GPIO_Init(LED2, &OBL);
XMC_GPIO_SetOutputLow(LED);
}


void toggle(void){
XMC_GPIO_ToggleOutput(LED2);
XMC_GPIO_ToggleOutput(LED);
}

 

void IRQ_Hdlr_21(void)
{
toggle();
};

0 Likes
atvmainiac
Level 1
Level 1
5 questions asked 10 sign-ins First solution authored

Turns out, i had my math values all wrong(knew they couldnt have been right from the get go) when i set up my timer slice up, after i did some reading turns out i just needed to change some of my math around. Kept thinking I didnt set the functions up right for the XMC library. Turns out i got it all right minus the shadow register location. The proper values are below.

 

.prescaler_initval = 11

Period Math = 31249

Compare match = 15625

This is the math i chose, loaded the file and it worked as it should. Just needed the right math to accomplish the job.

0 Likes
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

Thanks for sharing your solution to the community. It could help community members who could have faced a similar issue.

Best Regards,
Vasanth

0 Likes