cancel
Showing results for 
Search instead for 
Did you mean: 

timer1 Interrupt Is not generating

Ajadh.1
Associate II

I am using stm8s105c6 discovery board. I want to generate timer 1 interrupt and toggle led. But I am not able to generate timer interrupt.

void delay_cycles(uint16_t cy)

{

  do{

    --cy;

  }while(cy);

}

 //void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void)

 void TIM1_CAP_COM_IRQHandler(void)

{

  GPIO_WriteHigh(GPIOB, GPIO_PIN_6);

  if(flag == 0){

    flag = 1;

   // GPIO_WriteHigh(GPIOB, GPIO_PIN_4);

  }

  //TIM1_ClearITPendingBit(TIM1_IT_UPDATE);

  TIM1_ClearITPendingBit(TIM1_IT_CC4);

  TIM1_ARRPreloadConfig(ENABLE);

}

void main (void)

{

  // CLK_DeInit();

  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

  CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART2, ENABLE);

  CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, ENABLE);

  GPIO_DeInit(GPIOC);

  GPIO_DeInit(GPIOB);

  GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_FAST); //PC4 CHANNEL 4 TIMER1

  GPIO_Init(GPIOB, GPIO_PIN_6, GPIO_MODE_OUT_PP_LOW_FAST); //GPIO

  TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_DOWN,4095, 0); //timer freq = (clock CPU/16) -> 1bit = 1uS -> 92*1uS=92uS

  TIM1_OC4Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,2047,

               TIM1_OCPOLARITY_HIGH, TIM1_OCIDLESTATE_SET);

    TIM1_CtrlPWMOutputs(ENABLE);

    TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);

    // TIM1_ITConfig(TIM1_IT_CC4, ENABLE);

    TIM1_Cmd(ENABLE);

 // GPIO_WriteHigh(GPIOD,GPIO_PIN_6);

  GPIO_WriteHigh(GPIOB,GPIO_PIN_6);

  GPIO_WriteLow(GPIOB,GPIO_PIN_6);

  enableInterrupts();

  while(1) {

if(flag == 1){

  flag = 0;

}

  }

please guide me.

thanks in advance

}

1 REPLY 1
WilkoL
Senior

You enable the interrupt on UPDATE

TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);
// TIM1_ITConfig(TIM1_IT_CC4, ENABLE);

but the interrupt routine is on CAPTURE COMPARE

void TIM1_CAP_COM_IRQHandler(void)
{
	GPIO_WriteHigh(GPIOB, GPIO_PIN_6);
	if(flag == 0)
	{
		flag = 1;
	}
	TIM1_ClearITPendingBit(TIM1_IT_CC4);
	TIM1_ARRPreloadConfig(ENABLE);
}