Skip to main content
Associate III
September 18, 2023
Question

STM32CO11 DELAYS NOT WORKING

  • September 18, 2023
  • 2 replies
  • 685 views

 

 if(Mains>0.1)

	 	 	 	{
	 	 	 		if((Mains<1) &&(Vbat>0.9))
	 	 	 		 	 {
	 	 	 			TIM1->CCR4=TIM1->ARR;
	 	 	 			 HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_4);
	 	 	 			 Set_LED(0);
	 	 	 			 Batt_Chrge(0);
	 	 	 		HAL_Delay(1000);
	 	 	 		 	 }
	 	 	 		 else
	 	 	 		 	 {
	 	 	 			TIM1->CCR4=0;
	 	 	 		 HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_4);
	 	 	 		 Batt_Chrge(0);
	 	 	 		 	 }
	 	 	 		if((Mains<0.1)&&(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_6)==GPIO_PIN_SET))
	 	 	 		 {
	 	 	 		 	 TIM1->CCR4=TIM1->ARR/2;
	 	 	 		 	 HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_4);
	 	 	 		Batt_Chrge(0);
	 	 	 		 }

	 	 	 		else if((Mains<0.1)&&(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_6)==GPIO_PIN_RESET))
	 	 	 		 	 {

	 	 	 		 	 TIM1->CCR4=TIM1->ARR;
	 	 	 		 	 HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_4);
	 	 	 		 	 Batt_Chrge(0);

	 	 	 		 	 }
	 	 	 	}
	 	 	 	/*REST OF MY CODE*/
	 	 if((Mains<0.1)&& (TIM1->CCR4 == 0))
	 	 {
	 		 	count++;
	 			 if(count>=50)

	 			 {
	 				 Enter_sleep();
	 			 }

	 	 }

hi can anyone please let me what is wrong ,these code should be worked only detecting the mains as after Mains>0.1 if interruptions occur it should start again only after mains>0.1.I have also configured SYSTICK but I am not  sure why my delay is not working .

 

This topic has been closed for replies.

2 replies

TDK
September 18, 2023

What isn't working about the code in particular? Perhaps break it into smaller sections and try those. If delay isn't working, move that logic into a simpler block.

Consider debugging and stepping through the code to find out what isn't working as expected and why.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
September 18, 2023

Lacking a lot of context here.

Are you doing this in an interrupt/callback ? Going to be priority/preemption issues there if relying on SysTick, etc, to advance the software tick counter.

You'd need to differ execution using other methods, so you can leave the callback immediately.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..