ICU problem.

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

Moderator: RoccoMarco

Post Reply
DerpySanta
Posts: 4
Joined: Sun Aug 10, 2014 3:28 pm

ICU problem.

Post by DerpySanta »

Hello, i am new to chibios and trying to get ICU to capture the pulse width generated by external source(button for now), i am trying to use timer 4 but it doesnt seem to work at all. I enabled icu in halconf.h and mcuconf.h and use the following code as implementation. Note that print_number() function works as intended. Version of chibios i use is 2.6.3.


Code: Select all

static const ICUConfig icumyconfig = {
       ICU_INPUT_ACTIVE_HIGH,
       100,
       myicucb,
       icuperiodcb,
       NULL,
       ICU_CHANNEL_1,
       0
};
icucnt_t width;

static void myicucb(ICUDriver *icup) {



   width = icuGetWidth(icup);
   print_number(width,&SD1);
}
icucnt_t  last_period;
static void icuperiodcb(ICUDriver *icup) {

   last_period = icuGetPeriod(icup);
}
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Activates the serial driver 1 using the driver default configuration.
   */
  sdStart(&SD1, NULL);

  palSetPadMode(GPIOB, PAL_PORT_BIT(6), PAL_MODE_STM32_ALTERNATE_PUSHPULL);
    icuStart(&ICUD4, &icumyconfig);
    icuEnable(&ICUD4);

}
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ICU problem.

Post by Giovanni »

Hi,

Are you using an F1 device? if so ICU inputs must be programmed as inputs not alternate, alternate is for outputs. In the PWM-ICU demo that palSetPadMode() is for the PWM part.

Note also that the ICU driver could be not the best choice for that because the internal counter overflows after a while if no signal is detected. For slow inputs you could work with the EXT driver and system time.

Giovanni
DerpySanta
Posts: 4
Joined: Sun Aug 10, 2014 3:28 pm

Re: ICU problem.

Post by DerpySanta »

Yes i use STM32F100RB as part of STM32VLDiscovery board.
I changed pad setup to

Code: Select all

palSetPadMode(GPIOB, PAL_PORT_BIT(6), PAL_MODE_INPUT);

but still nothing happened.
I plan to use ICU to get values from sonic range sensor, polling it with 10Hz frequency, will icu work in that case?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ICU problem.

Post by Giovanni »

Hi,

Enable debug options in chconf.h, you specified 100hz as counter frequency but it is unlikely you will be able to obtain that frequency using the timer prescaler, assertions would catch an invalid frequency settings.

Yes, ICU would work in your use case, make sure to use frequencies physically obtainable by timer prescalers.

Giovanni
DerpySanta
Posts: 4
Joined: Sun Aug 10, 2014 3:28 pm

Re: ICU problem.

Post by DerpySanta »

Well i enabled debug and it printed out the following message, but i dont see what it has to do with anything.

Code: Select all

$1 = 0xff
The target endianness is set automatically (currently little endian)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ICU problem.

Post by Giovanni »

Never seen that, it is not something coming out of ChibiOS for sure.

What did you do exactly?

Giovanni
DerpySanta
Posts: 4
Joined: Sun Aug 10, 2014 3:28 pm

Re: ICU problem.

Post by DerpySanta »

Gotta be the gdb server then.
Post Reply