Showing results for 
Search instead for 
Did you mean: 

Signal acquisition on GPIO pin with timer on interrupt - STM32G4 discovery board

Associate III



I'am currently working on a project consisting on acquiring a TTL signal which could have a change of frequency for the entire duration of the signal. My plan is to use the Zero Crossing algorithms after taking sample each us of the signal  after 3 separate delays in ms after the signal is starting. The signal will go on a GPIO input pin and I will use a timer for the sample. It goes like that:

waiting delay1 [ms] -> take sample [us], delay2 [ms] -> take sample [us], delay3 [ms] -> take sample [us]

After taking a sample I set the value in a buffer. At the end of my interrupt I have 3 full buffer with the samples and I calculate the frequency with the Zero crossing algorithm, I am using the same TIM20 as internal clock and interrupt to generate my waiting delays and the sampling and during the sampling by modifying the timer prescaler and ARR value and it works so far, I am reading the pin directly with GPIOA->IDR & GPIO_PIN_1 (reading on PA1) To validate my sampling I am experimenting with a square wave of 32KHz as input signal so a period is of 31.25us, all of my sampling buffers are of size 32 in order to have 32 samples each us for only 1 transition. I am expecting to see at least 16 ones and zeros (1 transitions) in my buffers but I count 10 which means that my timer is too slow. My timer runs with a clock of 170MHz so setting the PSC at 16 and the ARR at 9 should do the trick and yet my sample is too slow. I change the ARR value to have a faster frequency but I'm ending up with the same result 

Is there a way to increase the speed of the signal reading ? I feel like, reading the Pin is taking too long. I will try to read on other Pins to see if have similar buffers.