Adding ICU support for TIM10 and TIM11

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

genosensor
Posts: 65
Joined: Thu Oct 03, 2013 1:06 am
Location: Santa Cruz, California
Has thanked: 1 time
Been thanked: 1 time

Adding ICU support for TIM10 and TIM11

Postby genosensor » Fri Sep 08, 2017 5:19 am

I've added support for TIM10 and TIM11 to the ICU driver.
Because TIM10 and TIM11 lack the 2nd compare register the ICU driver normally uses,
I've also had to add support for an additional input mode:

Code: Select all

/**
 * @brief   ICU driver mode.
 */
typedef enum {
  ICU_INPUT_ACTIVE_HIGH,        /**< Trigger on rising edge.            */
  ICU_INPUT_ACTIVE_LOW,         /**< Trigger on falling edge.           */
  ICU_INPUT_EDGE,               /**< Trigger on either edge.            */
  ICU_INPUT_MODES
} icumode_t;


The new INPUT_EDGE mode configures the counter to generate events on both edges of the input PWM signal.
It uses only one IC register and so is compatible with TIM10 and TIM11
This technique is documented in a couple ST app notes.
It works well so long as the minimum pulse width is longer than the interrupt response time.
Note that the ACTIVE_HIGH and ACTIVE_LOW modes require only that the period of the PWM be longer than the interrupt response time. Thus, very low or high duty cycles may cause a capture overflow when using INPUT_EDGE mode.

When using ICU_INPUT_EDGE, only the period callback is supported. The width callback should be configured as NULL.
The period callback will be called at each edge of the input signal.
It will typically have to check the signal's polarity to determine whether it is current servicing a rising or falling edge.

You may also find the revised driver in my git repo's esp3g-2.6.10 branch:

https://github.com/brentr/ChibiOS-RT/tree/esp3g-2.6.10

All relevant changes are here:
https://github.com/brentr/ChibiOS-RT/blob/esp3g-2.6.10/os/hal/platforms/STM32/TIMv1/icu_lld.c
https://github.com/brentr/ChibiOS-RT/blob/esp3g-2.6.10/os/hal/platforms/STM32/TIMv1/icu_lld.h

Note:
I would really like the API to support both signal "high" and "low" callbacks, but I cannot find a way to check the current state of a counter's input. No bit in the STM32's TIMx registers seem to return this :-(
Without a generic way to check the input state, one must resort to different solutions depending on the specific signal routing.
In my test case, I have the output of COMP2 routed to TIM10. In the period_cb, I must check the COMP2 output rather than the TIM10 input.
- brent

User avatar
Cesare
Posts: 36
Joined: Tue Jul 11, 2017 11:51 am
Location: Milan, Italy
Has thanked: 3 times
Been thanked: 3 times

Re: Adding ICU support for TIM10 and TIM11

Postby Cesare » Fri Sep 15, 2017 9:21 am

What a nice surprise, just these days I was looking for this feature, the pinout combinations on STM32 is quite restricted IMHO comparing to other brands, so I had to use TIM10/TIM11.

Thank you


Return to “STM32 Support”

Who is online

Users browsing this forum: Google [Bot] and 19 guests