2019-07-01 09:55 PM
Dear Members,
I have a callback :
void Timer10_Callback()
{
seconds += 1;
if (seconds == 30)
{
minute = 1;
seconds = 0;
rpm=count;
rps=(float)rpm/30;
count=0;
}
}
and main() inside while()
current_rps = rps;
if (minute>=1)
{
printf("============\r\n");
printf("RPS = %f\r\n",current_rps);
bpm = current_rps*60;
printf("RPM = %f\r\n",rpm);
printf("============\r\n");
//HAL_Delay(2000);
minute = 0;
}
can I put my code inside while() into my callback, or it's too long because of printf ?
because the handler already here:
void TIM10_IRQHandler(void)
{
/* USER CODE BEGIN TIM10_IRQn 0 */
/* USER CODE END TIM10_IRQn 0 */
HAL_TIM_IRQHandler(&htim10);
/* USER CODE BEGIN TIM10_IRQn 1 */
Timer10_Callback();
/* USER CODE END TIM10_IRQn 1 */
}
and I want to print out the result when it's finished calculating, it's only printing it when the loop is rotating on that point....
Any clues ?
Thanks
2019-07-01 11:34 PM
Firstly just for clarity, why are you counting minutes with only 30 seconds, not 60 seconds?
I believe rpm is half what it should be, but rps appears correct.
Putting that code into the callback would likely be fine because your timer only triggers once a second and printf would very likely outpace it. The flags are likely cleared by the HAL_TIM_IRQHandler, although thats worth checking and because they are cleared before your callback it shouldn't change the timing.
I don't understand what you meant by "it's only printing it when the loop is rotating on that point...."
2019-07-02 01:26 AM
I don't understand what you meant by "it's only printing it when the loop is rotating on that point...."
.....
on main()
while (1)
{
current_rps = rps;
if (minute>=1)
{
printf("============\r\n");
printf("RPS = %f\r\n",current_rps);
rm = current_rps*60;
printf("RPM = %f\r\n",bpm);
printf("============\r\n");
//HAL_Delay(2000);
minute = 0;
}
.
.
.
.
}
I want it running while it's doing something else on the while() loop....
Thanks