Skip to main content
Kumar B
Associate III
October 20, 2019
Question

CCMR1/CCMR2 register in STM32F407 for input Capture mode.

  • October 20, 2019
  • 4 replies
  • 2417 views

Hi,

I want to use input capture mode to detect event at every edge (STM32F407 Discovery board).

I have toggled the LED (Connected to PD12) using Timer4 Channel (TIM4_CH1) Output compare mode. It's working.

The output of LED is given to PD13 to count the events at PD13 pin (TIM4 CH2) (as Input capture).

What is the value to be loaded into TIM4->CCMR2 or TIM4->CCMR1 register for input capture? Which register I have to use and what is the value?

Thanks,

Kumar

This topic has been closed for replies.

4 replies

waclawek.jan
Super User
October 20, 2019

Input capture is not event counting. When a given timer channel is set to input capture, it copies the current value of TIMx_CNT register into respective TIMx_CCRy register, whenever an edge of selected direction on the respective pin occurs.

If you want event counting, you want to use it in one of the external clock modes. You then can't use other channel for the usual PWM output, as there is only one counter (TIMx_CNT) per timer.

Read the timer chapter in RM.

JW

Kumar B
Kumar BAuthor
Associate III
October 21, 2019

Thanks for the reply.

Sorry. my purpose is not event counting. As you said,  whenever an edge of selected direction on the respective pin occurs I need to count.

As my requirement is to count the edges (rising or falling) coming from LED (Connected to PD12) using Timer4 Channel (TIM4_CH1) configured as Output compare mode.

This count is to be captured by the PD13 pin (TIM4 CH2). I have to configure to input capture. For this,

TIM4->CCMR1= ? ;   //What is the value to be set for CH2 to capture at every edge?

TIM4->CCER = ? ;

Let me know this registers value? And what is the status register bit I have to look for capturing edeg?

(TIM4->SR & bit)

Thank you

TDK
October 20, 2019

It varies by what precisely you want to do, but generally setting the CMxR->CCxS bits to 01 is what you want. Different bit positions for each channel.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
October 21, 2019

As TDK said, for input capture you set CCMRx.CCxS bits to 0b01 - in case of CH2 it's CCMR1.CCS. You also need to enable the channel by setting CCER.CC2E=1 and the detection of both edges is set by setting bot CCER.CC2P=1 and CCER.CC2NP=1.

In status register, when capture occurs, SR.CC2IF gets set.

JW