2024-09-16 09:27 PM - last edited on 2024-09-16 10:04 PM by Peter BENSCH
I have STM32G070RBT6, a timer is set to give interrupt every 1 second, in interrupt i am incrementing a variable timer_var1 then in main file while loop i am dividing this by 10 and assigning this value to another variable TIMER_NOW.
Now when timer_var1 hits value 389(decimal) it rolls over to 255(dec).
there is nothing else in the while loop.
i am not able to figure out how is it possible.
code:
volatile uint16_t timer_var1=0,TEMP,TIMER_PREV=0,TIMER_NOW=0;
while (1)
{
TIMER_NOW=timer_var1/10;
// if(TIMER_NOW>TIMER_PREV){
// COR_Y[TIMER_NOW]=270-TEMP-TIMER_NOW*2;
// COR_X[TIMER_NOW]=TIMER_NOW*7;
// TIMER_PREV=TIMER_NOW;}
// DWIN_DRAW_LINE(0x5000, COR_X,COR_Y, TIMER_NOW);
// HAL_UARTEx_ReceiveToIdle_IT(&huart1, RX_BUFF_LCD, 16);
HAL_Delay(300);
HAL_GPIO_TogglePin(STATUS_GPIO_Port, STATUS_Pin);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
In interrupt file:
/* USER CODE BEGIN PV */
extern volatile unsigned int DataPos;
extern volatile unsigned char RX_BUF[256u];
extern volatile uint16_t timer_var1;
/* USER CODE END PV */
void TIM1_BRK_UP_TRG_COM_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 0 */
timer_var1++;
/* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 0 */
HAL_TIM_IRQHandler(&htim1);
/* USER CODE BEGIN TIM1_BRK_UP_TRG_COM_IRQn 1 */
/* USER CODE END TIM1_BRK_UP_TRG_COM_IRQn 1 */
}
Solved! Go to Solution.
2024-09-17 07:34 AM
Yes it was the size of TX_BUFF_LCD... which was overflown and writing to memory space where timer_var1 might be defined
i changed the size of TX_BUFF_LCD and problem solved completely
2024-09-17 07:39 AM
You are right about the overflow.. resolved the issue.. thank you
You also advised not to use upper case variables and routine why is that an issue??
didnt get this point i am using these since years..