cancel
Showing results for 
Search instead for 
Did you mean: 

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

AE104
Senior

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++;
}
}

7 REPLIES 7

Specify "didn't work".

Are global variables declared as volatile?

JW

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

All global variables or 'count' variable only?

Mainly "count".

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

JW

AE104
Senior

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

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

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

Try declaring count as

static int count;

inside the function. If it gets better, find out if it is accidentally getting used elsewhere.