This is an old revision of the document!


Timer Compare




The code snippet bellow shows how to configure and use a GPIO pin as input.

#include "reg_stm32f4xx.h"
 
RCC->AHBENR[0] |= (0x1 << 0u);          /* Enable GPIOA clock */
RCC->APBENR[0] |= (0x1 << 0u);          /* Enable TIM2 clock */
 
/* configure output */
GPIOA->MODER |= (0x2 << 0u);          /* Set pin 0 to Alternate Function */
GPIOA->AFR[0] |= (0x1 << 0u);         /* Set pin 0 to AF1 (TIM2) */
 
/* configure basic timer */
TIM2->PSC = 84000u - 1u;              /* Counting with f = 84MHz / 84000 = 1MHz */
TIM2->ARR = 512u;                     /* Count to 512 */
 
/* configure timer output */
TIM2->CCMR1 |= (0x6 << 4u);           /* Enable PWM mode 1 on channel 1 */
TIM2->CCER |= (0x1 << 0u);            /* Enable output on channel 1 */
 
TIM2->CR1 |= (0x1 << 0u);             /* Start timer */


Hardware Abstraction Layer
Register Types
InES Timer HAL Interface


Capture/compare mode register 1/2




DMA / Interrupt enable register




CCxDE0CCx DMA request disabled (reset state)
1CCx DMA request enabled
CCxIE0CCx interrupt disabled (reset state)
1CCx interrupt enabled

Capture/compare enable register




CCxE0Capture/compare output x disabled (reset state)
1Capture/compare output x enabled




  • stm32/peripherals/timer_compare.1491811596.txt.gz
  • Last modified: 2017/04/10 08:06
  • by kesr