I am trying to measure a 1kHz PWM Signal on Pin PB5 on a STM32F407 Discovery Board (I checked the 1kHz signal with a scope).
So I copied the example from HAL-STM32F407-DISCOVERY Demo folder and adapted it.
I expect to get a period of 1ms but instead I get a 10ms (see variable "too_slow_period") instead.
Which setting do I have to adjust to get correct measurement ?
Here is my code:
Code: Select all
icucnt_t last_period, too_slow_period;
static void Thread1(void const *arg)
{
(void)arg;
while (true)
{
too_slow_period = last_period;
osDelay(1000);
}
}
/*
* Thread definition block.
*/
osThreadDef(Thread1, osPriorityAboveNormal, 128, "blinker");
static void icuperiodcb(ICUDriver *icup) {
last_period = icuGetPeriodX(icup);
}
static ICUConfig icucfg = {
ICU_INPUT_ACTIVE_HIGH,
10000, /* 10kHz ICU clock frequency. */
NULL,
icuperiodcb,
NULL,
ICU_CHANNEL_2,
0U,
0xFFFFFFFFU
};
/* Application entry point. */
int main(void) {
halInit();
chSysInit();
osKernelInitialize();
osThreadCreate(osThread(Thread1), NULL);
osKernelStart();
// ---------------------ICU Measuring----------------------
icuStart(&ICUD3, &icucfg);
palSetPadMode(GPIOB, 5, PAL_MODE_ALTERNATE(2));
icuStartCapture(&ICUD3);
icuEnableNotifications(&ICUD3);
// ---------------------ICU Measuring----------------------
while (true) {
/* Doing nothing. This thread can be used for any other
user activity.*/
chThdSleepMilliseconds(1000);
}
}