Page 1 of 1

ICU problem.

Posted: Sun Aug 17, 2014 11:16 am
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);

}

Re: ICU problem.

Posted: Sun Aug 17, 2014 11:39 am
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

Re: ICU problem.

Posted: Sun Aug 17, 2014 11:50 am
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?

Re: ICU problem.

Posted: Sun Aug 17, 2014 12:02 pm
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

Re: ICU problem.

Posted: Sun Aug 17, 2014 12:59 pm
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)

Re: ICU problem.

Posted: Sun Aug 17, 2014 2:47 pm
by Giovanni
Never seen that, it is not something coming out of ChibiOS for sure.

What did you do exactly?

Giovanni

Re: ICU problem.

Posted: Sun Aug 17, 2014 3:32 pm
by DerpySanta
Gotta be the gdb server then.