cancel
Showing results for 
Search instead for 
Did you mean: 

Counter TIM4

karl246
Associate
Posted on February 13, 2012 at 16:01

Hi! I have a probem with a simple software that I've wrote to learn to use timers.

This is the code that I've used.

&sharpinclude ''stm8l15x.h''

main()

{

  TIM4_DeInit();

TIM4_TimeBaseInit(TIM4_Prescaler_2048, 200);

TIM4_Cmd(ENABLE);

GPIO_DeInit(GPIOC);

GPIO_DeInit(GPIOE);

GPIO_Init(GPIOC, GPIO_Pin_7,GPIO_Mode_Out_PP_High_Fast);

  GPIO_Init(GPIOE, GPIO_Pin_7,GPIO_Mode_Out_PP_High_Fast);     

while(1) {

if (TIM4_GetCounter() == 0) GPIO_SetBits(GPIOC, GPIO_Pin_7);

else GPIO_ResetBits(GPIOC, GPIO_Pin_7);

if (TIM4_GetCounter() > 0) GPIO_SetBits(GPIOE, GPIO_Pin_7);

else GPIO_ResetBits(GPIOE, GPIO_Pin_7);

}

}

Practically the counter do not start, his value is stoped at 0x00.

Can you help me? :)

P.S.= Sorry for my bad english....

#timers-tim4
2 REPLIES 2
np1
Associate II
Posted on February 16, 2012 at 17:47

Hi,

You must enable clk for timer 4 and enable interrupt for system.

     CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE);

    /* Enable general interrupts */

    enableInterrupts();

Good luck

karl246
Associate
Posted on February 17, 2012 at 00:10

Now it works!! Thanks for your suggestion!!!! ;)