Main Site Documentation

Project - Using signalCapture to measure frequency


#1

I just posted Using signalCapture to measure frequency on Codeshare. Feel free to discuss and make suggestions here.


#2

Hi Hagster

I need to measure a low frequency signal (1 to 20Hz) and tried your code on a cobra board, it is working ok. In your example you are creating a PWM signal and feeding it th the same pin for reading.
I need to read the signal on pin 3 of socket 4 (GPIO with interrupt capabilities) that is mapped to pin P0_25 of the G120, so i did:

  • wired pin 3 of the socket 4 to P1_5 (pwm signal)
  • changed this line of code to:


but when running, the code hangs... I am doing something wrong?

Thanks

#3

Have you checked there are no conflicts for that pin/socket 4?

Try setting P0_25 as a regular input and check that it is changing state. SIgnalCapture is a blocking function if the pin doesn’t change it will freeze.


#4

Well, after a good night sleep your code is working ok, i’m generating a signal at PWM2 and reading it at pin3 of socket 4.

Thanks


#5

I tried your code in 4.3 and i had precise readings.
I need to use this in 4.2 but now i have differences about 1,5Hz between generated signal (10Hz) and readed signal (11,5Hz), it is about 15% error…

The only major change in 4.2 code is the read function that has more arguments:



0 is the offset;
3 is the count (3 readings)
100 is the timeout

Any ideas about this difference?

#6

Sounds like it’s triggering on different edges or the PWM signal is different. Do a longer capture and plot out the waveform. If you have an oscilloscope the check the PWM signal.


#7

That’s it, i changed timeout to 1000 and now it is working ok.

Now i have another problem… when disconecting input signal it should read 0Hz, but it is showing bigger values like 50Hz…

I try checking signalPulseInput content but it seems that even it has no input signal it continues reading some values…

Any ideas?


#8

what is about the “Port.ResistorMode.Disabled” if you only disconnect the signal, then you have no defined level on the pin.


#9

As Daniel says if the input is floating anything could be happening. Also if the timeout times out I’m not sure the output is meaningful.

There function should return the number of pincaptures. You might be able to use this to detect timeouts.
Parameters
initialState
Type: OnlineSystem.Boolean
The initial state of the pin.

buffer
Type:OnlineSystem.UInt32[]
The buffer to into which to read the pin transition times in microseconds.
offset
Type: OnlineSystem.Int32
To offset into the buffer at which to begin reading.
count
Type: OnlineSystem.Int32
The number of transitions to read.
Return Value
Type: OnlineInt32
The number of pin transitions


#10

@ VB-Daniel - tried Port.ResistorMode.PullDown but still shows some noisy values…

@ hagster - it worked, i’m checking returning value of pinPulseInput.Read() and if is not equal to 3, it means no PWM…

Thank you guys!