Warning
This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

Časovač - Input Capture

#include "stm32f4xx.h"
 
void initInput(void){
  RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
 
  // PA0 - alternate function for Input Capture Mode
  GPIOA->PUPDR |= GPIO_PULLUP << GPIO_PUPDR_PUPD0_Pos;
  GPIOA->MODER |= GPIO_MODE_AF_PP << GPIO_MODER_MODER0_Pos;
  GPIOA->AFR[0] |= GPIO_AF1_TIM2 << GPIO_AFRL_AFSEL0_Pos;
}
 
void initTIM2(void){
  RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;	// povoleni hodin do bloku TIM2
 
  TIM2->PSC = 1600;
  TIM2->ARR = 10000;
 
  // input capture enable for PA1
  TIM2->CCMR1 |= 0x01 << TIM_CCMR1_CC1S_Pos;	// set TI1 as input mode
  TIM2->CCER |= TIM_CCER_CC1P;			// falling edge
  TIM2->CCER |= TIM_CCER_CC1E;			// Capture enabled
}
 
int main(void){
    initInput();
    initTIM2();
    while(1){
      // process data from TIM2->CCR1
    }
}

courses/b2m37mam/priklady/stm32/02c-tmr_input_capture.txt · Last modified: 2023/09/07 15:23 by nentvond