Skip to main content
Associate III
November 19, 2024
Solved

GetTick() and HAL_Delay(xxx);

  • November 19, 2024
  • 14 replies
  • 2264 views

When I give the delay time greater than 300 for the code below (500ms or 1000ms), GetTick or HAL_Delay(500); functions do not work.

If I make the time 100ms, 200ms or 300ms, it works.

When I want to control the delay at longer times, the program does not work.

Where should I look for the problem?
I am using STM32F030C6T6.

	 if(PA10_On==0)
	 {
		 Tick_PA10_On = HAL_GetTick();
		 PA10_On=1;
	 }

	 if ( PA10_On==1 &&(HAL_GetTick() - Tick_PA10_On) >= 300)
	 	 {
		 	 HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_14);
		 	 PA10_On=0;
	 	 }

For example, this code below does not work.

HAL_GPIO_WritePin(PA10_GPIO_Port,PA10_Pin,GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin(PB14_GPIO_Port,PB14_Pin,GPIO_PIN_RESET);
HAL_Delay(500);

But this below code works.

HAL_GPIO_WritePin(PA10_GPIO_Port,PA10_Pin,GPIO_PIN_SET);
HAL_Delay(200);
HAL_GPIO_WritePin(PB14_GPIO_Port,PB14_Pin,GPIO_PIN_RESET);
HAL_Delay(200);

 Waits of 300ms and below work.

This topic has been closed for replies.
Best answer by gbm

Show the declarations of all the variables used in your code, like Tick_PA10_On.

Show all the warnings you get while compiling the code. Correct your code to remove all the warnings.

Is the watchdog activated? If yes, then turn it off.

14 replies

Andrew Neil
Super User
November 19, 2024

@XooM wrote:

When I give the delay time greater than 300 for the code below (500ms or 1000ms), GetTick or HAL_Delay(500); functions do not work.


What do you mean by, "do not work"?

  • Don't give any delay at all?
  • Give an excessive delay?
  • Crash?
  • Other??
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
XooMAuthor
Associate III
November 19, 2024
HAL_GPIO_WritePin(PA10_GPIO_Port,PA10_Pin,GPIO_PIN_SET);
HAL_Delay(200);
HAL_GPIO_WritePin(PB14_GPIO_Port,PB14_Pin,GPIO_PIN_RESET);
HAL_Delay(200);

If I write the code above, the PA10 pin goes HIGH and LOW at 200ms intervals.

but the duration is a larger value like 400ms 500ms. It remains in the HIGH position.

Andrew Neil
Super User
November 19, 2024

Still not clear what is actually happening.

Are you saying that, with a delay value over ~ 400, your code just "stops" at the HAL_Delay() call?

ie, your code becomes equivalent to:

HAL_GPIO_WritePin(PA10_GPIO_Port,PA10_Pin,GPIO_PIN_SET);
while(1); // Code "sticks" here ?

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
gbm
gbmBest answer
Super User
November 19, 2024

Show the declarations of all the variables used in your code, like Tick_PA10_On.

Show all the warnings you get while compiling the code. Correct your code to remove all the warnings.

Is the watchdog activated? If yes, then turn it off.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice