2018.12.20 22:02

Base Timer 인터럽트 사용 안하고 설정하기 


uint32_t timers = 0;


TIM_HandleTypeDef    TimHandle;


void main(void)

{

  HAL_Init();

  /* Configure the system clock to 48 MHz */

  SystemClock_Config();


  /* Compute the prescaler value to have TIMx counter clock equal to 10000 Hz */

  uwPrescalerValue = (uint32_t)(SystemCoreClock / 1000000) - 1;//48000000


UART1_printf("SystemCoreClock : %d, uwPrescalerValue %d\r\n", SystemCoreClock, uwPrescalerValue);  


  /* Set TIMx instance */

  TimHandle.Instance = TIMx;


  /* Initialize TIMx peripheral as follows:

       + Period = 10000 - 1

       + Prescaler = (SystemCoreClock/10000) - 1

       + ClockDivision = 0

       + Counter direction = Up

  */

  TimHandle.Init.Period            = 2000000; // about 1000000 = 1s, 100000 = 0.1s 10000 = 0.01s, 1000 = 0.001s, 100 = 0.0001s, 10 = 0.00001s, 1 = 0.000001s  

  TimHandle.Init.Prescaler         = uwPrescalerValue;

  TimHandle.Init.ClockDivision     = 0;

  TimHandle.Init.CounterMode       = TIM_COUNTERMODE_UP;

  TimHandle.Init.RepetitionCounter = 0;

  if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK)

  {

    /* Initialization Error */

    Error_Handler();

  }


__HAL_TIM_SetCounter(&TimHandle, 0);

HAL_TIM_Base_Start(&TimHandle);

uint32_t beforetime=0;

while(1){

if(__HAL_TIM_GetCounter(&TimHandle) >= 1000000){

__HAL_TIM_SetCounter(&TimHandle, 0);

UART1_printf("%d, ", timers);

timers++;

}

}

}


Posted by 로망와니

티스토리 툴바