2020-01-23 01:44 PM
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++;
}
}
2020-01-23 02:15 PM
Specify "didn't work".
Are global variables declared as volatile?
JW
2020-01-23 02:22 PM
HAL_GPIO_WritePin functions in the switch-case structure didn't respond.
All global variables or 'count' variable only?
2020-01-23 02:26 PM
Mainly "count".
Can't you uncomment the pin toggle and observe that pin?
JW
2020-01-23 02:29 PM
Toggle function works. But when I uncomment it and call switch-case function, switch-case didn't run the GPIO_WritePin functions.
2020-01-24 01:42 AM
Place a breakpoint on the switch statement, and observe the count variable.
2020-01-24 06:55 AM
I placed it then I run the debug session. The 'count' variable is always zero.
2020-01-24 08:26 AM
Try declaring count as
static int count;
inside the function. If it gets better, find out if it is accidentally getting used elsewhere.