Electronics > Projects, Designs, and Technical Stuff

Help with STM32duino timers and frequency measurement

<< < (7/9) > >>

timdf911:
Hi Ozcar

I'm not using the DMA code but using my simpler capture compare code I found that it would only work upto 4MHz (using PD2 ETR2 input) but by using the ETPS prescaler to /8 it will work upto 55MHz which is odd as I was only expecting 8 x 4MHz.

The resolution of 1kHz is ok for my needs, now just need to tweak my code as currently the time base signal pops out from TIM2 on PA5 then is hard wired back into PB0 to gate the counter on TIM3.

I still plan on getting DMA going but I was spending too much time on DMA rather than the rest of the project - so for now I'll stick with my capture compare solution.

Regards Tim

ozcar:

--- Quote from: timdf911 on December 14, 2022, 12:53:40 pm ---Hi Ozcar

I'm not using the DMA code but using my simpler capture compare code I found that it would only work upto 4MHz (using PD2 ETR2 input) but by using the ETPS prescaler to /8 it will work upto 55MHz which is odd as I was only expecting 8 x 4MHz.

The resolution of 1kHz is ok for my needs, now just need to tweak my code as currently the time base signal pops out from TIM2 on PA5 then is hard wired back into PB0 to gate the counter on TIM3.

I still plan on getting DMA going but I was spending too much time on DMA rather than the rest of the project - so for now I'll stick with my capture compare solution.

Regards Tim

--- End quote ---

So, if I have got this right, you changed to using TIM2 for the gate time, and TIM3 to count your external signal, with TIM2 output wired externally to one of the TIM3 channels to use input capture?

If so, I'm not sure where the maximum of 4MHz would come from. Maybe show us the actual code.

Using the 16-bit TIM3 to count the external signal, you would have to keep the gate time below about 2ms though to avoid complications with the counter overflowing.

profdc9:
I built an antenna tuner based on the STM32F103 which includes code for measuring the frequency of the RF signal.  I included a 74HC393 so I could cut down the frequency and implement an inverse frequency counter if necessary.

https://github.com/profdc9/ModularTuner

https://github.com/profdc9/ModularTuner/blob/master/code/tuner/frequencyCounter.cpp

There's also circuitry there that helps condition the RF signal for counting that took some effort to get right, as well as circuitry to measure the phase of the reflected RF signal to get the complex phase coefficient.

timdf911:
Hi ozcar

the 4MHz limit was because I had the system clock set to about 8MHz rather than 84MHz.  Yes because the frequency counter is only 16 bits I have to make sure the max count is within limits so I have the ETR2 prescaler set to /8 and use a 8mS gate as this gives more stable results compared to no ETR2 prescaler and a 1mS gate.

The counter easily goes to over 55MHz with 1kHz resolution.

As mentioned above due to HW constraints I'm forced to us PD2 input pin which connects to 16 bit timer.

Certainly has been a good learning exercise and worth the effort and time - I appreciate your help.

Regards Tim

timdf911:
profdc9

Thanks for the links - I'll study them and hopefully learn something.

Looks like an interesting project, has it been published anywhere in full ?

Regards Tim

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod