ICU and timer channel?
Moderators: RoccoMarco, lbednarz, tfAteba
ICU and timer channel?
Hi
How can I select which channel to read in ICU? I would like to read channel 4 of the timer 1.
Thanks.
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?
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?
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.
- 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?
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
Supporting other inputs would require more configuration options and extensive changes.
Giovanni
Re: ICU and timer channel?
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:
But that's for STM32F1. You'll need to check the registers
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
- 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?
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
Giovanni
Re: ICU and timer channel?
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.
Thanks for the comments.
- 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?
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
Giovanni
Re: ICU and timer channel?
Quite cryptic registers for me..
The current code has this:
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?
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?
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.