ICU and timer channel?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

ICU and timer channel?

Post 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.
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: ICU and timer channel?

Post 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.
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: ICU and timer channel?

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: ICU and timer channel?

Post 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
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: ICU and timer channel?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: ICU and timer channel?

Post 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
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: ICU and timer channel?

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: ICU and timer channel?

Post 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
User avatar
kulve
Posts: 86
Joined: Mon Nov 28, 2011 8:36 pm

Re: ICU and timer channel?

Post 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?
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: ICU and timer channel?

Post 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.
Post Reply