초보의 아웅다웅 설계하기/STM32

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

로망와니 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++;

}

}

}


'초보의 아웅다웅 설계하기 > STM32' 카테고리의 다른 글

PID 제어  (0) 2019.03.02
LSM6DSL, LIS2MDL, LPS22HB  (0) 2019.03.01
STM32F Sleep Mode에서 Uart로 Wakeup하기  (0) 2018.12.06
SoftUart Only TX  (2) 2018.10.22
24LC1025 데이터 Read, Write  (0) 2018.10.16