AnsweredAssumed Answered

stm32f4 discovery - strange frequency

Question asked by jedli_ka.petr on Jun 27, 2016
Latest reply on Jun 28, 2016 by Clive One
Hi, I am new at programming ARM microcontrollers and I use stm32f4 discovery board. I have tried to program blinking of the 4 user LEDs on the board so that it should change its state every 10 seconds assuming 16MHz internal oscilator. I have set prescaller to 16000, thus I have got 1000Hz and autoreload register to 10000, but when I run the program, the LEDs change their state every approximately 6 seconds. It behaves like the oscilator is approximately 26.6MHz, but it is impossible. Has anyone experience with similar problem? My code is here:

#include "stm32f4xx.h"
#include "stm32f4xx_conf.h"
#include "misc.h"
#include "core_cmInstr.h"


char state = 0;


void TIM7_IRQHandler(void)
{
    if (state == 0)
        {
            GPIO_SetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); //LEDs on
            state = 1;
        }
    else
        {
            GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);   //LEDs off
            state = 0;
        }
    TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
    return;
}




int main(void)
{
    //timer7 interrupt settings
    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = (uint8_t)1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority =(uint8_t)1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);


    //timer7 settings
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
    TIM_PrescalerConfig(TIM7, (uint16_t)16000, TIM_PSCReloadMode_Immediate);
    TIM_SelectOnePulseMode(TIM7, TIM_OPMode_Repetitive);
    TIM_SetAutoreload(TIM7, (uint32_t)10000);
    TIM_UpdateRequestConfig(TIM7, TIM_UpdateSource_Global);
    TIM_UpdateDisableConfig(TIM7, DISABLE);
    TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);
    TIM_Cmd(TIM7, ENABLE);


    //GPIO settings
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    GPIO_SetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); //LEDs on




  while(1)
  {
      __NOP();
  }
}

Outcomes