create a 2ms delay in xmc4200

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

cross mob
lila_young
Level 1
Level 1
25 sign-ins 5 questions asked 5 replies posted

Hello expert,

 

how can I generate a 2ms delay in XMC4200-F64K256 BA # before I transmit data use UART

Because It seems that the bus will have competition between receive and transmit. So I want to add a 2ms delay before transmit.

 

0 Likes
1 Solution
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @lila_young ,

There are many ways to add an delay.

1)Directly using the API   XMC_Delay()

The above function delays by the specified number of milliseconds.
The number of cycles to delay is calculated based on the ref SystemCoreClock.

This API is defined in the latest versions of the XMC_LIB so if you are not using the latest version please download the latest version from the below link.

Link : https://github.com/Infineon/mtb-xmclib-cat3/

2)The other way of doing it is configuring the Timer in DAVE APPS and let the timer count up to your required delay and generate an interrupt when the required delay is achieved.

For reference of above implementation please refer to the below thread.

Link : https://community.infineon.com/t5/XMC/XMC-4700-simple-single-shot-timer-for-delay-funtion/td-p/30942...

3) The below function can help you create an delay but for configuring the exact delay necessary calculations should be done based on the clock frequency.

#define FREQ_1MHZ (1000000UL)

void Delay1(uint32_t delay)
{
uint32_t i;

SystemCoreClockUpdate();
delay = delay * (uint32_t)(SystemCoreClock / FREQ_1MHZ);

for (i = 0U; i < delay; ++i)
{
__NOP();
}
}

Hope this helps and let me know if you have any further queries.

Best Regards
Pradeep.

 

 

View solution in original post

0 Likes
1 Reply
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @lila_young ,

There are many ways to add an delay.

1)Directly using the API   XMC_Delay()

The above function delays by the specified number of milliseconds.
The number of cycles to delay is calculated based on the ref SystemCoreClock.

This API is defined in the latest versions of the XMC_LIB so if you are not using the latest version please download the latest version from the below link.

Link : https://github.com/Infineon/mtb-xmclib-cat3/

2)The other way of doing it is configuring the Timer in DAVE APPS and let the timer count up to your required delay and generate an interrupt when the required delay is achieved.

For reference of above implementation please refer to the below thread.

Link : https://community.infineon.com/t5/XMC/XMC-4700-simple-single-shot-timer-for-delay-funtion/td-p/30942...

3) The below function can help you create an delay but for configuring the exact delay necessary calculations should be done based on the clock frequency.

#define FREQ_1MHZ (1000000UL)

void Delay1(uint32_t delay)
{
uint32_t i;

SystemCoreClockUpdate();
delay = delay * (uint32_t)(SystemCoreClock / FREQ_1MHZ);

for (i = 0U; i < delay; ++i)
{
__NOP();
}
}

Hope this helps and let me know if you have any further queries.

Best Regards
Pradeep.

 

 

0 Likes