Is it possible to measure the frequency of a PWM using the U3-LV? | LabJack
 

Is it possible to measure the frequency of a PWM using the U3-LV?

4 posts / 0 new
Last post
Francesc Paradell
Francesc Paradell's picture
Is it possible to measure the frequency of a PWM using the U3-LV?

Is it possible to measure the frequency of a PWM using the U3-LV? The idea is to connect the PWM output to an input of the U3-LV and scan the input to measure the PWM frequency. The PWM has a frequency range of 90KHz to 200KHz. If possible ... Where can I find an example of how to do it? Thanks in advance.

LabJack Support
labjack support's picture
The following is a general

The following is a general old forum topic discussing ways to measure frequency:

https://forums.labjack.com/index.php?showtopic=1105

Since your frequency is quite high, up to 200 kHz, I suggest you use the count-over-time technique.  You will want to configure a digital input (FIO4 would be typical) as a hardware counter and then read that counter at some software timed interval:

https://labjack.com/support/datasheets/u3/hardware-description/timers-co...

I suggest you try it first using the test panel in LJControlPanel.  Once you see it working there, then try it in Python.  I'm sure we have a counter/timer example for Python, but let us know if you need more help with that.

Francesc Paradell
Francesc Paradell's picture
Thank you for the support!

Thank you for the support!

I have tried first with LJControlPanel, configuring Timer0 in Mode2=RisingEdge (default pin FIO4), and TimerClockBase 48Mhz.

When my PWM frequency is 90KHZ it works fine, I read the counter value=535 so PWM period is 535/4800000=11uS ==> F=90Khz

When I increase my PWM frequency to 200KHz I have some errors, some times the counter give me the correct value 241, but some times give me an error value 482 its (2x241) so when I calculate the frequency sometimes give me the wrong value of 100Khz. 

How can I avoid this error?

For an other test, i need to measure the Duty Cycle of My PWM, I know its 50%.

For this test I configure Timer0 in mode4 DutyCycle (default pin FIO4), and TimerClockBase 48Mhz.

For the frequency of 90Khz (DutyCycle 50%)  the LJControlPanel give me a distintc value on every Timer read, giving a scaled value of 100% or 0% ¿?

How can I read the correct DutyCycle?

Thanks in advance!

LabJack Support
labjack support's picture
Your signal is too fast for

Your signal is too fast for the firmware based timer modes such as modes 2 &4:

https://labjack.com/support/datasheets/u3/hardware-description/timers-co...

To measure the frequency you will need to use the hardware Counter as I described in post #2.  The U3 is not capable of measuring the duty cycle of your signal.  Only the T7 can do that as it has hardware based duty-cycle measurement:

https://labjack.com/support/datasheets/t7/digital-io/extended-features/p...