STMF4 get frequency of a signal on a input pin.

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

Moderator: RoccoMarco

Joerg-SH
Posts: 29
Joined: Mon Feb 20, 2012 9:00 pm

STMF4 get frequency of a signal on a input pin.

Post by Joerg-SH »

Hello
I want to use a HH10D humidity Sensor. The I2C works fine.

Now I must get the frequency of the Output.

For the moment I have no idea how to do that.

I hope someone could help me please.

regards

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

Re: STMF4 get frequency of a signal on a input pin.

Post by Giovanni »

Hi,

The ICU driver is able to measure the period of a signal, of course you must verify that it is usable in your scenario because I don't know that device.

You should make sure that the signal is applied to one of the IC1 or IC2 inputs of internal timers in order to be able to measure it.

Giovanni
Joerg-SH
Posts: 29
Joined: Mon Feb 20, 2012 9:00 pm

Re: STMF4 get frequency of a signal on a input pin.

Post by Joerg-SH »

The signal is round about 7000 KHz
I will have a look for ICU now.
Joerg-SH
Posts: 29
Joined: Mon Feb 20, 2012 9:00 pm

Re: STMF4 get frequency of a signal on a input pin.

Post by Joerg-SH »

I found in testhal F4 the PWM-ICU sample... not sure If that is suitable for me...
Joerg-SH
Posts: 29
Joined: Mon Feb 20, 2012 9:00 pm

Re: STMF4 get frequency of a signal on a input pin.

Post by Joerg-SH »

I did not understand how to use only ICU

In the sample pwm and icu is mixed. There is no simple ICU sample available ???
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STMF4 get frequency of a signal on a input pin.

Post by Giovanni »

In the demo PWM generates a signal, ICU measures the signal generated by the PWM, the two things are well separated. If you remove the PWM references what is left is about what you need.

Giovanni
Joerg-SH
Posts: 29
Joined: Mon Feb 20, 2012 9:00 pm

Re: STMF4 get frequency of a signal on a input pin.

Post by Joerg-SH »

I think this I need?

Code: Select all

static ICUConfig icucfg = {
  ICU_INPUT_ACTIVE_HIGH,
  10000,                                    /* 10kHz ICU clock frequency.   */
  icuwidthcb,
  icuperiodcb,
  NULL,
  ICU_CHANNEL_1
};



but this is called by

Code: Select all

icucnt_t last_width, last_period;

static void icuwidthcb(ICUDriver *icup) {

  palSetPad(GPIOD, GPIOD_LED4);
  last_width = icuGetWidth(icup);
}

static void icuperiodcb(ICUDriver *icup) {

  palClearPad(GPIOD, GPIOD_LED4);
  last_period = icuGetPeriod(icup);
}


and I don´t need I think.


This I need but get error (ICU3 undeclared)


Code: Select all

 icuStart(&ICUD3, &icucfg);
  palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(2));
  icuEnable(&ICUD3);
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STMF4 get frequency of a signal on a input pin.

Post by Giovanni »

You need to enable ICUD3 in mcuconf.h.

Giovanni
Joerg-SH
Posts: 29
Joined: Mon Feb 20, 2012 9:00 pm

Re: STMF4 get frequency of a signal on a input pin.

Post by Joerg-SH »

ok I forget to do that.

then I only need that? And how I will get periodic ?

Sorry I still works more right than wrong with StdLibs from ST and chibios is absolutely different for me.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STMF4 get frequency of a signal on a input pin.

Post by Giovanni »

Its the code you posted:

Code: Select all

static void icuperiodcb(ICUDriver *icup) {

  last_period = icuGetPeriod(icup);
}


This is how you get the period.

Giovanni
Post Reply