Announcements

Help us improve the Power & Sensing Selection Guide. Share feedback

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

cross mob
Odri
Level 2
Level 2
First solution authored Welcome! 5 replies posted
Hi

got one question with ccu4 timer config. I need to generate two timers, one that counts microseconds and the second one counting miliseconds. Is this possible using CCU40 and CCU41 slices?

thanks
0 Likes
7 Replies
DRubeša
Employee
Employee
First solution authored First like received
Hi Xabi,

sure it is. And I guess there are multiple of ways and I will suggest one of them. You can use CCU4_SLICE_CONFIG APPs and use two instances (CCU4_SLICE_CONFIG_0 & CCU4_SLICE_CONFIG_1) and you define prescaler initial value until you don´t achieve necessary Tick resolution [ns]. For example, for resolution of 1 us you need to set prescaler to 64 and for 0.512ms you need to set it to 32768. Prescaler value cannot be higher than 32768. BUT if it´s really necessary to be 1ms or greater than you need to set value for "Compare Mode" so you´ll achieve that period of 1ms. In this case timer concatenation will also be necessary so you can check also "CCU4_SLICE_CONFIG_EXAMPLE_XMC47".

Best regards,
Deni
0 Likes
Odri
Level 2
Level 2
First solution authored Welcome! 5 replies posted
Hi Deni

Im configuring firstly the microsecond timer. I did the following config but the timer reg it is not counting...


#define MODULE_PTR CCU40
#define MODULE_NUMBER (0U)

#define SLICE0_PTR CCU40_CC40
#define SLICE0_NUMBER (0U)

XMC_CCU4_SLICE_COMPARE_CONFIG_t SLICE0_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) 6, /* in this case, 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
};

/* Ensure fCCU reaches CCU42 */
XMC_CCU4_SetModuleClock(MODULE_PTR, XMC_CCU4_CLOCK_SCU);

i forgot something?

thanks,

/* Enable clock, enable prescaler block and configure global control */
XMC_CCU4_Init(MODULE_PTR, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR);

/* Start the prescaler and restore clocks to slices */
XMC_CCU4_StartPrescaler(MODULE_PTR);

/* Initialize the Slice */
XMC_CCU4_SLICE_CompareInit(SLICE0_PTR, &SLICE0_config);

/* Get the slice out of idle mode */
XMC_CCU4_EnableClock(MODULE_PTR, SLICE0_NUMBER);

/* Map Event-1 to Start function */
XMC_CCU4_SLICE_StartConfig(SLICE0_PTR, XMC_CCU4_SLICE_EVENT_1, XMC_CCU4_SLICE_START_MODE_TIMER_START_CLEAR);

/* Start the TImer*/
XMC_CCU4_SLICE_StartTimer(SLICE0_PTR);
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi Xabi,

just a quick question so there is not any misunderstanding.

2914.attach

You need to have 1us for as resolution, so like these pulses in red circles that will generate some interrupt or level change of the output pin after certain amount of the occurred (this value is known as Period match value), or you need 1us to be difference between timer start and Period Match value (on the picture this is the blue difference)? I just want to be sure we´re speaking about the same things 🙂

P.S how have you concluded that it´s not counting...not expected output pin change or some register bit?

Best regards,
Deni
0 Likes
Odri
Level 2
Level 2
First solution authored Welcome! 5 replies posted
HI Deni,

I need the pulses as in the red example.

I concluded that it's not counting looking the TIMER register and calling "XMC_CCU4_SLICE_GetTimerValue" function.

Thanks
0 Likes
Odri
Level 2
Level 2
First solution authored Welcome! 5 replies posted
HI Deni,

I need the pulses as in the red example.

I concluded that it's not counting looking the TIMER register and calling "XMC_CCU4_SLICE_GetTimerValue" function.

Thanks
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi Xabi,

I´ve done some changes to your code 😉

#include 
#include

#define SLICE_PTR CCU40_CC40
#define MODULE_PTR CCU40
#define MODULE_NUMBER (0U)
#define SLICE_NUMBER (0U)

XMC_CCU4_SLICE_COMPARE_CONFIG_t SLICE0_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) 6, /* in this case, 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
};

int main(void)
{
/* Ensure fCCU reaches CCU40 */
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, &SLICE0_config);

/* Program a very large value into Period Match register*/
XMC_CCU4_SLICE_SetTimerPeriodMatch(SLICE_PTR, 65535U);

/* Enable shadow transfer */
XMC_CCU4_EnableShadowTransfer(MODULE_PTR, XMC_CCU4_SHADOW_TRANSFER_SLICE_0);

/* Start timer*/
XMC_CCU4_SLICE_StartTimer(SLICE_PTR);

while(1U)
{

}
}


Try it for yourself and let me know how it went.

Best regards,
Deni
0 Likes
Odri
Level 2
Level 2
First solution authored Welcome! 5 replies posted
Hi Deni,

that code works.

Thanks for the help.
0 Likes