STMF4 get frequency of a signal on a input pin.
Moderator: RoccoMarco
STMF4 get frequency of a signal on a input pin.
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
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
- 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.
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
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.
The signal is round about 7000 KHz
I will have a look for ICU now.
I will have a look for ICU now.
Re: STMF4 get frequency of a signal on a input pin.
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.
I did not understand how to use only ICU
In the sample pwm and icu is mixed. There is no simple ICU sample available ???
In the sample pwm and icu is mixed. There is no simple ICU sample available ???
- 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.
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
Giovanni
Re: STMF4 get frequency of a signal on a input pin.
I think this I need?
but this is called by
and I don´t need I think.
This I need but get error (ICU3 undeclared)
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);
- 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.
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.
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.
- 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.
Its the code you posted:
This is how you get the period.
Giovanni
Code: Select all
static void icuperiodcb(ICUDriver *icup) {
last_period = icuGetPeriod(icup);
}This is how you get the period.
Giovanni