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

XMC™ Forum Discussions

User18865
Level 1
Level 1
First solution authored
Hello,

I'm trying to change the duty cycle of CCU4 Timer by changing the compare match value.
I could manage to confirm that the timer toggles the LED1 and the GPIO output pin (P3.9) at every 1 second, but the duty cycle did not change as I tried to set it to 50%.

Could someone advise me regarding this?
I attached my code below. Any help would be greatly appreciated.





#include //Declarations from DAVE Code Generation (includes SFR declaration)

#define TIMER1_MODULE CCU40
#define TIMER1_SLICE 1
#define TIMER1 CCU40_CC41
#define TIMER1_IRQ IRQ_Hdlr_45

#define LED1 P5_9
#define TESTPIN1 P3_9



XMC_CCU4_SLICE_COMPARE_CONFIG_t TIMER1_config =
{
.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_GPIO_CONFIG_t GPIO_config =
{
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
.output_level = XMC_GPIO_OUTPUT_LEVEL_LOW,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM
};


/**

* @brief main() - Application entry point
*
* Details of function

* This routine is the application entry point. It is invoked by the device startup code. It is responsible for
* invoking the APP initialization dispatcher routine - DAVE_Init() and hosting the place-holder for user application
* code.
*/

int main(void)
{
DAVE_STATUS_t status;
uint32_t TIMER1_period = 144000000/4096;


status = DAVE_Init(); /* Initialization of DAVE APPs */

XMC_CCU4_Init(TIMER1_MODULE, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR);
XMC_CCU4_SLICE_CompareInit(TIMER1, &TIMER1_config);
//XMC_CCU4_SLICE_CaptureInit(TIMER1, &TIMER1_config);
XMC_CCU4_SLICE_SetTimerCompareMatch(TIMER1, 17578);
XMC_CCU4_SLICE_SetTimerPeriodMatch(TIMER1, TIMER1_period);

XMC_CCU4_EnableShadowTransfer(TIMER1_MODULE, XMC_CCU4_SHADOW_TRANSFER_SLICE_1);

//XMC_CCU4_SLICE_EnableEvent(TIMER1, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
//XMC_CCU4_SLICE_SetInterruptNode(TIMER1, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH, TIMER1_SLICE);

XMC_CCU4_SLICE_EnableEvent(TIMER1, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP);
XMC_CCU4_SLICE_SetInterruptNode(TIMER1, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP, TIMER1_SLICE);


XMC_CCU4_EnableClock(TIMER1_MODULE, TIMER1_SLICE);
XMC_CCU4_SLICE_StartTimer(TIMER1);

NVIC_SetPriority(CCU40_1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0,0));
NVIC_EnableIRQ(CCU40_1_IRQn);

XMC_GPIO_Init(LED1, &GPIO_config);
XMC_GPIO_Init(TESTPIN1, &GPIO_config);

if(status != DAVE_STATUS_SUCCESS)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}

/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{

}
}

void TIMER1_IRQ(void)
{
XMC_CCU4_SLICE_ClearEvent(TIMER1, XMC_CCU4_SLICE_IRQ_ID_COMPARE_MATCH_UP);

XMC_GPIO_ToggleOutput(LED1);
XMC_GPIO_ToggleOutput(TESTPIN1);

}
0 Likes
1 Solution
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked
Hi,

Could you try calling XMC_CCU4_EnableShadowTransfer API just after XMC_CCU4_SLICE_SetTimerCompareMatch call. Any call to XMC_CCU4_SLICE_SetTimerPeriodMatch(), XMC_CCU4_SLICE_SetTimerCompareMatch(),
,XMC_CCU4_SLICE_SetPrescaler(),XMC_CCU4_SLICE_CompareInit(), XMC_CCU4_SLICE_CaptureInit() must be succeeded by XMC_CCU4_EnableShadowTransfer API.

Best Regards,
Vasanth

View solution in original post

0 Likes
2 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked
Hi,

Could you try calling XMC_CCU4_EnableShadowTransfer API just after XMC_CCU4_SLICE_SetTimerCompareMatch call. Any call to XMC_CCU4_SLICE_SetTimerPeriodMatch(), XMC_CCU4_SLICE_SetTimerCompareMatch(),
,XMC_CCU4_SLICE_SetPrescaler(),XMC_CCU4_SLICE_CompareInit(), XMC_CCU4_SLICE_CaptureInit() must be succeeded by XMC_CCU4_EnableShadowTransfer API.

Best Regards,
Vasanth
0 Likes
User18865
Level 1
Level 1
First solution authored
Hi Vasanth,

Thank you for your comments. I will give it a try.
0 Likes