Skip to main content
AE104
Associate III
Jan 23, 2020 9:44 PM UTC
Question

Switch-case function two interrupt timer controlled Elapsed Call Back Function

Hello,

I activated TIM6 and TIM7 in interrupt mode. In the elapsed call back function, I checked TIM7 with toggle function, and it works. But when I place switch-case related functions. It didn't work. Could you check it what I missing?

Thank you

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if(htim->Instance==TIM6)
	{
	HAL_ADC_Start(&hadc1);
	HAL_ADC_Start(&hadc2);
	
	HAL_ADC_PollForConversion(&hadc1,1);
	ADC_of_VoltageTransients[i]=HAL_ADC_GetValue(&hadc1);
	testdata_in_1[i]= ((float)ADC_of_VoltageTransients[i]*(3.3/4096.0));
		
	HAL_ADC_PollForConversion(&hadc2,1);
	ADC_of_EvokedRecordings[i]=HAL_ADC_GetValue(&hadc2);
	testdata_in_2[i]= ((float)ADC_of_EvokedRecordings[i]*(3.3/4096.0));
	
	HAL_ADC_Stop(&hadc1);
	HAL_ADC_Stop(&hadc2);
	
	i++;
	
		if(i>=1000){
			HAL_TIM_Base_Stop_IT(&htim6);
			}
	}
	if(htim->Instance==TIM7)
	{
		//HAL_GPIO_TogglePin(Led_GPIO_Port,Led_Pin);
			switch (count)
		{
		case 0:
			break;
		case 50:
			HAL_GPIO_WritePin(Phase_1st_GPIO_Port, Phase_1st_Pin, GPIO_PIN_SET);
			break;
		case 70:
			HAL_GPIO_WritePin(Phase_2nd_GPIO_Port, Phase_2nd_Pin, GPIO_PIN_SET);
			break;
		case 80:
			HAL_GPIO_WritePin(Phase_1st_GPIO_Port, Phase_1st_Pin, GPIO_PIN_RESET);
			break;
		case 100:
			HAL_GPIO_WritePin(Phase_2nd_GPIO_Port, Phase_2nd_Pin, GPIO_PIN_RESET);
			count=-1;
		}
			count++;
}
}

This topic has been closed for replies.

7 replies

waclawek.jan
Super User
Jan 23, 2020 10:15 PM UTC

Specify "didn't work".

Are global variables declared as volatile?

JW

AE104
AE104Author
Associate III
Jan 23, 2020 10:22 PM UTC

HAL_GPIO_WritePin functions in the switch-case structure didn't respond.

All global variables or 'count' variable only?

waclawek.jan
Super User
Jan 23, 2020 10:26 PM UTC

Mainly "count".

Can't you uncomment the pin toggle and observe that pin?

JW

AE104
AE104Author
Associate III
Jan 23, 2020 10:29 PM UTC

Toggle function works. But when I uncomment it and call switch-case function, switch-case didn't run the GPIO_WritePin functions.

berendi
Principal
Jan 24, 2020 9:42 AM UTC

Place a breakpoint on the switch statement, and observe the count variable.

AE104
AE104Author
Associate III
Jan 24, 2020 2:55 PM UTC

I placed it then I run the debug session. The 'count' variable is always zero.