Timer input capture mode
hi, i am working with an example from the book Mastering STM32 written by Carmine Noviello.
The example is the 6th of chapter11, it is about Input capture mode.
I have a nucleo board STM32F401RE and i am building examples with STM32CUBEIDE tool.
I have configured two timers:
i use TIM1 in DMA circular mode to blink the LED PA5, which is high every 50khz.
i want detect this frequency by connecting the led to channel 1 of TIM3 in input capture mode.
TIM3 clock is connected to LSE through the MCO pin, which is running at 32768 hz.
I configured TIM3 in DMA circular mode so that when the LED is high, the content of CCR is trasferred to a 16bit Captures array of two elements(Captures[2]).
The DMA transfer is of halfword size since the CCR1 is a 16 bit register.
The global variable captureDone is set to 1 by the HAL_TIM_IC_CaptureCallback() callback function, which is invoked at the end of the capture process.
When this happens the frequency of the sample signal is computed using the following equation:
if (captureDone != 0) {
if (captures[1] >= captures[0]) {
diffCapture = (captures[1] - captures[0]);
}else{
diffCapture = (htim3.Instance->ARR - captures[0]) + captures[1];
}
frequency = LSE_VALUE/ (htim3.Instance->PSC + 1);
frequency = (float) frequency / diffCapture;
sprintf(msg, "Input frequency: %.3f\r\n", frequency);
HAL_UART_Transmit(&huart2, (uint8_t*) msg, strlen(msg), HAL_MAX_DELAY);
while (1);
}
The problem is that is executed the ELSE statement even if from the debugging i read that captures[1] has a value greater than captures[0].
Can you help with this exercise please?
