AnsweredAssumed Answered

Digital input timing

Question asked by grossi.marco on Sep 27, 2017
Latest reply on Sep 27, 2017 by waclawek.jan

I work on a STM32F334 Nucleo board featuring the STM32F334R8 microcontroller.

I have the need to check the value of the lowest 8 bits of two digital ports (only PC0-7 is used in this example) as quick as possible.

 

I tried the following code

 

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_SET);
if ((uint8_t)((GPIOC)->IDR) > 250)
my_port = my_port+1;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET);

 

and monitored PA7 (digital output) with an oscilloscope. The result is two pulses: the first of width about 900 ns and the second of about 700 ns. Since the second pulse is only from setting and resetting PA7, I assume that the code

 

if ((uint8_t)((GPIOC)->IDR) > 250)
my_port = my_port+1;

 

takes about 200 ns to complete and only the first instruction is executed since (GPIOC)->IDR) is lower than 250.

Since the clock frequency is set to 64 MHz (8 MHz internal oscillator with PLL) this means that about 12 clock cycles are needed only for the first instruction. Since I need to make the comparison on two different ports then I need a minimum of 400 ns for the execution and that means that the whole operation can have a maximum frequency of about 2 MHz.

Is there any way to increase such frequency (faster digital port acquisition and compare)?

Thanks.

 

Outcomes