2
\$\begingroup\$

As part of a project, I'd like to test the correct operation of a set of SPST switch ICs (maybe 8 or 16 or so). Each device contains six independent switches, and they are controlled through an SPI bus. I plan to operate the switches at around 10 or 20 kHz. I'm thinking of using an inexpensive microcontroller (mabye an Arduino MEGA) to exercise the switches and count the number of times they're switching.

I think I could use the Arduino's 16-bit Timer/Counters, clocked externally by the switches under test, to count how many switch cycles are actually occurring. However, most MCUs have a limited number of timer/counter peripherals. The ATmega2560 in the Arduino MEGA has four 16-bit timers, for example (assuming I can use them all).

As I'm monitoring more than four switches (we could be looking at something like 50 individual switches to be monitored across 16 devices, say), I need another solution. This may be a shopping question, and I might just need the name of what I'm looking for, but are there multi-channel event counter ICs that can operate independently, with internal registers or memory to store the counts on each channel and perhaps raise an interrupt when some count is reached or they overflow? Thanks!

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

Your best bet is to use a cheap FPGA development board. Here is a list of them at Digikey, sorted by price. There are several in the $30 range.

Get one with enough I/Os to handle the number of signals that you need to count. For example, the Lattice MACHXO2 board has over 100 I/Os that go to 0.1" pin headers. It is programmable over USB and the development software is free to download.

As for programming the FPGA, instead of trying to have a large number of external clock inputs directly drive a bunch of counters, it would be best to use a fixed clock, sample the external inputs, and increment the counter when a rising edge is detected. A rising edge is detected when a 0 sample is followed by a 1 sample. The clock frequency must be at least ~4X than the input frequency and the sampled inputs should go through a couple levels of registers to avoid any metastability issues.

You can also use the FPGA logic to implement an SPI or I2C interface to read counters and status, reset the counters, etc.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks. This would be my first foray into the world of FPGAs, but your approach sounds like a good one. So it sounds like I should be able to implement everything on the FPGA. I'll have to get up to speed on programming FPGAs, and learn Verilog, I guess. In addition to implementing the overall event loop, would I have to manually bit-bang the SPI protocol, or can I compose my project from pre-built blocks? (I probably just need to do more research at this point.) \$\endgroup\$
    – David
    Commented Apr 12, 2018 at 17:22
  • 1
    \$\begingroup\$ Even though I was a C programmer and Verilog is more C like, I found VHDL easier to learn. It's a bit more verbose, but once you learn the basic structures that synthesize to registers and state machines, it's really not that difficult. In both Verilog and VHDL there are lots of pre-defined functional blocks that you can include in your code, such as SPI and I2C interfaces. The Lattice MACHXO2 chip even has a hard coded I2C interface built in. The development environments support both VHDL and Verilog and you can usually include blocks defined in Verilog in VHDL code and vice versa. \$\endgroup\$
    – crj11
    Commented Apr 12, 2018 at 17:30
2
\$\begingroup\$

If what you are really trying to do is verify correctness as you increase speed for example, then you can take the signature analysis approach.

At each set of new data, latch into shift registers(74hc165)

Shift it all through a CRC generator (74F401).

Repeat until your whole test is done.

Read the signature CRC into arduinos SPI.

(74F401 is obsolete but on ebay) Silego part below could implement an I2C crc generator


Silego / Dialog SLG46824 are a cheap simple logic-ish device that can implement a number of counters (I interpret it as 7x8 bit + 1x16bit, or 4.5x 16 bit) you can read from the I2C port.

They are very easy to get into with schematic type programming, and have 2-5V supply.

They have a dip adaptor version now that is a lot easier than the miserable little qfn to play with.


\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.