Main Site Documentation

SPI Pulse Counting


#1

I was thinking today (and no I didn’t hurt myself), would it be possible to determine the frequency of a pulse train (pwm) via the SPI bus. The idea is to connect the PWM to the MISO pin and do a short read of around 1kilo byte of data. that would equal 8K clock cycles. Then we would look for values that are greater than zero to determine when the pulse starts. We then subtract that index from the index where the values fall to zero and then back. After that we count all the bits between them and divide the clock frequency by that number. This answer should tell us approximately the frequency of the pulse train.

Does anyone see a problem with this approach?

Also, when a Fez (any type) is sending and receiving data via the SPI bus is the processor involved in that transfer process or is it handled by some sort of subsystem?


#2

Why not simply using an interrupt input pin and count the number of events?
In RLP it would even work with precise time measurement.


#3

Most MCU’s can be configured to use their internal Counter/Timers to be clocked from an external IO pin. With a bit of REGISTER hackery you shout be able to do this all in the background.

For instance from the G120 NXP user manual

[quote]The Timer/Counter is designed to count cycles of the peripheral clock (PCLK) or an
externally-supplied clock
, and can optionally generate interrupts or perform other actions
at specified timer values, based on four match registers. It also includes four capture
inputs to trap the timer value when an input signal transitions, optionally generating an
interrupt.[/quote]


#4

Does the .NETMF have this ability?


#5

It depends if the Timers are being used elsewhere.

But, I just remembered there is a built in class that probably does what you need.

https://www.ghielectronics.com/docs/106/pincapture


#6

I’m really into this idea as well. I’ve been looking for a solid and easy to implement solution to calculate frequency of a pulsed input.


#7

So the PinCapture .Read method returns when the array is full. Therefore you have to wait the specified amount of time before it’s completed.

With this method it should be possible to create a Delta Sigma ADC by creating a voltage controlled oscillator which generates a frequency and then using pin capture to measure that frequency?


#8

@ John Smith - Is this for a G400? I have an object-oriented class that uses registers to perform pulse counting to very high (MHz range, theoretically) frequencies. It’s not polished up enough for Codeshare just yet, but if you need it, I can put a rough version up.


#9

@ iggmoe, nah, it’s for the STM32F4