Page 1 of 3
STMF4 get frequency of a signal on a input pin.
Posted: Sun Aug 11, 2013 10:15 am
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
Re: STMF4 get frequency of a signal on a input pin.
Posted: Sun Aug 11, 2013 10:20 am
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
Re: STMF4 get frequency of a signal on a input pin.
Posted: Sun Aug 11, 2013 11:29 am
by Joerg-SH
The signal is round about 7000 KHz
I will have a look for ICU now.
Re: STMF4 get frequency of a signal on a input pin.
Posted: Sun Aug 11, 2013 12:39 pm
by Joerg-SH
I found in testhal F4 the PWM-ICU sample... not sure If that is suitable for me...
Re: STMF4 get frequency of a signal on a input pin.
Posted: Sun Aug 11, 2013 6:04 pm
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 ???
Re: STMF4 get frequency of a signal on a input pin.
Posted: Sun Aug 11, 2013 8:06 pm
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
Re: STMF4 get frequency of a signal on a input pin.
Posted: Mon Aug 12, 2013 7:01 am
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);
Re: STMF4 get frequency of a signal on a input pin.
Posted: Mon Aug 12, 2013 7:25 am
by Giovanni
You need to enable ICUD3 in mcuconf.h.
Giovanni
Re: STMF4 get frequency of a signal on a input pin.
Posted: Mon Aug 12, 2013 8:01 am
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.
Re: STMF4 get frequency of a signal on a input pin.
Posted: Mon Aug 12, 2013 8:20 am
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