Hi there, I am very new in programming micro.I am using stm32f100 discovery board and made a small code to turn the stm board led on for 5 second once hit the user push button.then the led goes off.The partial code below I have to do the work.The program runs my led on for 5 sec only the first time I hit the user button.But next time I hit user it gives me 4 sec, and keep changing everytime to 3s,4s,,like random.I could not figure out what I am doing wrong.Could anyone please help me on this.Thanks in advance.
TIM3->PSC = 23999; // Set prescaler to 24 000 (PSC + 1) TIM3->ARR = 5000; // Auto reload value 1000 while(1) { if(GPIOA->IDR & (1 << 0)) //if user ush button is set { TIM3->CR1 = TIM_CR1_CEN;//enable timer3 TIM3->SR &= ~TIM_SR_UIF;// clear uif bit while (1) { GPIOC->BSRR = (1 << 8); //until UIF flag is not set led 4(pc8) in stm board blinks if(TIM3->SR & TIM_SR_UIF) // if UIF flag is set { GPIOC->BRR = (1 << 8); //clear the pc8 break; } } } }
Thanks a lot. You are right,the clock was still running.I have reset the clock and it works perfect now. That's great!