Page 1 of 6

ICU and timer channel?

Posted: Fri Dec 30, 2011 2:21 pm
by kulve
Hi

How can I select which channel to read in ICU? I would like to read channel 4 of the timer 1.

Thanks.

Re: ICU and timer channel?

Posted: Fri Dec 30, 2011 3:43 pm
by Badger
I dont think that is possible, only channels one and two have capture compare. By default the ICU driver uses channel one, but you can manually set the timer registers to change that to channel two.

Re: ICU and timer channel?

Posted: Fri Dec 30, 2011 8:06 pm
by kulve
Hmm.. By quickly looking the F205 TRM I think the timers 1 and 8 support 4 channels and each of them could be used for input capture.

Re: ICU and timer channel?

Posted: Fri Dec 30, 2011 8:25 pm
by Giovanni
The ICU driver currently only supports capture on input 1 using capture registers 1 and 2.

Supporting other inputs would require more configuration options and extensive changes.

Giovanni

Re: ICU and timer channel?

Posted: Fri Dec 30, 2011 8:26 pm
by Badger
In that case you should be ok, but you'll need to manually configure the timer after calling icuStart. For example, I use channel 1 input to start capture, and channel 2 input to stop it, so my code is:

Code: Select all

  icuStart(&ICUD1, &icucfg);

  ICUD1.tim->CR2 = TIM_CR2_TI1S;

  /* configure ICU to start capture on first pulse, and stop on second */
  /* CCMR1_CC1S = 01 = CH1 Input on TI1.
     CCMR1_CC2S = 01 = CH2 Input on TI2.*/
  ICUD1.tim->CCMR1 = TIM_CCMR1_CC1S_0 |
                     TIM_CCMR1_CC2S_0;

  /* configure trigger on rising edge for both   */
  ICUD1.tim->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC1P | TIM_CCER_CC2P;

  icuEnable(&ICUD1);


But that's for STM32F1. You'll need to check the registers

Re: ICU and timer channel?

Posted: Fri Dec 30, 2011 8:28 pm
by Giovanni
Input 2 is not a big deal as Badger shown but using inputs 3 and 4 is much more difficult because it would require the use of capture registers 3 and 4, this would require changes in all places where capture registers are referenced.

Giovanni

Re: ICU and timer channel?

Posted: Fri Dec 30, 2011 9:02 pm
by kulve
Sounds like the easiest way is to add a jumper wire and change the schema for the next revision. At least that's the easiest way to get forward.

Thanks for the comments.

Re: ICU and timer channel?

Posted: Fri Dec 30, 2011 11:27 pm
by Giovanni
You could also use a customized ICU low level driver, make a customization is easy enough, it is making a driver supporting all possible combinations that is complex.

Giovanni

Re: ICU and timer channel?

Posted: Sat Dec 31, 2011 12:05 pm
by kulve
Quite cryptic registers for me..

The current code has this:

Code: Select all

/* CCMR1_CC1S = 01 = CH1 Input on TI1.
    CCMR1_CC2S = 10 = CH2 Input on TI1.*/

icup->tim->CCMR1 = TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_1;


What does it mean? It enables both channels 1 & 2 as input to TI1? I though only channel 1 is used? What are these TIx-things?

Re: ICU and timer channel?

Posted: Sat Dec 31, 2011 12:17 pm
by Badger
It configures the timer to start counting on an input on TI1, and stop counting again on TI1. A separate register tells the timer whether to start on rising or falling edge. Note that CH1 and CH2 do not refer to the timer channels, but the channel of the counter. In the datasheet there's an example for how to configure it to capture PWM input, have a read of that.