Periodic microsecond timer

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

cross mob
User6383
Level 1
Level 1
Hello,
I need for me projekt a periodic microsecond timer (32 bit) to get the time between two calls or to generate a delay.
Is there a app which provide this function?
According to the datasheet for the XMC4500 the module CCU4 and CCU8 should do this.
But there is no app which provide only the function from this modules to generate a periodic timer.
What can i do now ?

Best regards,
Max_Rock
0 Likes
9 Replies
elegantk
Employee
Employee
Hi,

I should like to understand more about the requirement of periodic microsecond timer (32-bit).
Do you mean:
1. From 0 to 0xFFFF FFFFF count, the time taken is 1us... (Period)
2. Or From 0 to 1 count, the time taken is 1us.... (Resolution)

As the CPU clock is 120Mhz, using the smallest resolution, it take 118 count for 1us.. which is only 7-bit..
Thus, a 32-bit container for the period value seem to be an overkill...
0 Likes
User6383
Level 1
Level 1
Hi elegantk,
i need the resolution option, every 1us the timer increments.
0 Likes
elegantk
Employee
Employee
Hi,

As the CPU clock is 120Mhz. Each CPU cycle is 8.33ns.
The prescaler divider is1,2,4,... 64,128...
If divider is 64... Each resolution is 8.33ns x 64 = 5.33us
If divider is 128... Each resolution is 8.33ns x 128 = 1.066us

Thus, there is no suitable prescaler divider option which will result in the resolution of 1us
0 Likes
elegantk
Employee
Employee
Hi,

Alternative solution = PWMSP001 (for 1us trigger pulse) + CNT001 (to count the number of 1us)

Setup PWMSP001 to 1Mhz frequency... We will be using the PWMSP001 period match (Falling edge) to trigger the increment of count of CNT001.
Signal Connection: PWM Status -> CNT001 -> Input

Setup CNT001 Active Edge for counting = "Falling edge".

**************************************************************************
If you need 200us timer interrupt interval:
Setup Event Count match to "200", count match enable at initialization, start during initialization.
Connect the NVIC002 signal.
0 Likes
User6383
Level 1
Level 1
Hi,

i have tested and it works.
For a 32bit Timer i add a second CNT001 app.
Signal Connection from CNT001/0: Status -> CNT001/1 -> Input.
Setup CNT001/0:
Active Edge for counting = "Falling edge".
Enable Rollover Interrupt at initialization
Setup CNT001/1:
Active Edge for counting = "Falling edge".
0 Likes
Not applicable
Hello everybody,
i need a timer for my project , that could replace the NOP() function , which is not very accurate. Everywhere i look on the internet i see many examples that use the NOP() function.I haven't found so far an example that would use only the CCU4 module. I don't need to use PWMSP001 or CNT001 app as max_rock did . Basically , i need a simple and accurate timer that uses the CC4 module . For example if i have this program:


#include
void delay(unsigned long int i)
{
while(i--)
{
__NOP();
}
}

int main(void)
{

DAVE_Init(); // Initialization of DAVE Apps


while(1)
{
IO004_TogglePin(IO004_Handle0);
IO004_TogglePin(IO004_Handle1);
delay(1000000);
}
return 0;
}


How could i use the CC4 (or what other module) to replace the delay function? i have also read this topic:http://http://www.infineonforums.com/threads/397-CCU4-Modul-PWM?highlight=ccu4 but the user wanted to get a PWM working . I don't need that. All i need is a simple and accurate delay timer.

Thank you
Best regards ,
Alex
0 Likes
User6412
Level 4
Level 4
Use the PWM App and disable on that App the outputs (see the pins configuration). Configure the PWM in edge aligned single shot mode and set the period to the desired time delay. Enable the appropriate interrupt on Period match or just poll the value of the timer in the while loop. It's really easy! To start the timer - just set the run bit.
0 Likes
Not applicable
Thank you for your quick answer Dmitry Podobedov. I did what you told me to do.I selected PWMSP001 app , i configured the pwm in edge aligned single shot mode , but i can't set the period . I mean , that option(set period) , resolution , and compare are locked. They can't be modified.I attached a screenshot below.224.attach.
The program seems to be working , but i can't modify the period. Also , what should i do if i want to use an interrupt ? I tried to set the period using this command: CCU40_CC40->PRS=0xFFFF; still, no efect.
0 Likes
Not applicable
Years later, but hey 🙂

"Slice x shadow transfer set enable"
GCSS.SxSE = 1
0 Likes