I’m hoping someone can suggest the right board or board / module combination to achieve this:-
I need to count pulses from multiple sensors.
There are many of these sensors I need to read (hundreds) but ideally I’d like to deal with them in groups of 8, so at least 8 per board / module is preferred.
The sensors are capable of generating pulses at a rate of up to 250Hz each.
I need to be able to count all the pulses for all sensors even if they are all going at full rate simultaneously
I need to read a delta of the count of these pulses for each of the sensors at an interval of 10 seconds over an Ethernet network, ideally via an IP socket or HTTP. This doesn’t need to be built into the board / module… preferably I would aggregate many of these boards (of 8 inputs each) onto a larger board that has Ethernet and can collect the counts.
What I’ve considered so far:-
Panda II: this has a practical maximum of around 1700 interrupts / second (using managed code)
Pulse InOut module: though promising, from what I can understand this reads pulse width and does not do what I need
I know I could use custom firmware with several of the boards to do this, however I’m hoping to avoid that (as I don’t have the resources) and find something that either does what I need or that I can write for in managed code; hopefully without it costing a lot.
Is there any further information I could supply that would assist in suggesting the best board / modules to use for this?
Hi Aleks,
I know you said you don’t want to do anything too low level, but that’s pretty much where you are at.
You need to count at a frequency of ~2MHz (naive 8 channels x 250kHz). That implies hardware counters, for sure.
There are various solutions ranging from dedicated quadrature encoder to SPI counters (2 channels per IC), older style CMOS shift register counters, or something like a Cortex-M0 with it’s inbuilt counters (has plenty) and UART/SPI comms.
You also need to specify the maximum count per channel (bits of resolution).
Also worth thinking about with any solution is glitch/noise rejection, i.e. using a software and/or hardware filter to cap the maximum count frequency.
Once you have a hardware counter board writing a managed .NETMF driver is a piece of cake.
Propeller and FPGA are massive, massive overkill. 2 MHz (on a single channel, at least) is nothing. An 8-bit XMega running at 32 MHz can manage 16 MHz.
There’s plenty of capture channels on the STM32 for what you’re doing. It has enough horsepower that it wouldn’t even notice.
The Timers in the Cortex parts are more than sufficient (16 bit counter mode) in terms of capability, but you don’t get enough.
I guess you just need to make sure you don’t mess with Timers that are used by NETMF if you go down this path?
Also, you are still deep in processor manual/embedded code land.
@ Gus, can you do any of this in a CMSIS way? Or do you need separate code for each micro?
If I implement using hardware counters via registers per the above link, this will give me the increased performance (i.e. more than an interrupt driven event model that increments a counter)?
Can I use something like the DL04 that Gus originally suggested for this, or what about the Cerb40?
If I use either of these, is the above-mentioned managed code to access the registers all I need, or is there some additional low level code that needs to be implemented?
Overkill is fine as long as it means I can drive more sensors off the same module, or alternatively use higher frequency sensors.
If you use the hardware counters you don’t need to worry about interrupts during counting (it’s all in hardware), but you should be sure to handle over and underflow.
You can just read the counter current value registers at your convenience.
Any board with spare hardware counters/timers can be used.
You don’t need any code (except for interrupts) as you can do everything by register access from managed code.
[em]Up to 17 timers: up to twelve 16-bit and two 32-
bit timers up to 168 MHz, each with up to 4
IC/OC/PWM or pulse counter and quadrature
(incremental) encoder input[/em]
I would guess that should cover your needs. NETMF only uses one timer.
At the risk of beating a dead horse, there’s 32 available input capture channels.
i have used a picaxe microcontroller (<$10 at sparkfun) to do the counting and sent the data over with UART to a Cerbuino.
I have used the conuters via registers on the emx and i just ported that over to the G120HDR it is very simmilar to the wiki page.
I was trying to do it on the STM32 boards as well but i got very confused on how to do it.
here is the g120 register code for timer 2 which i just used the wiki on register as my guide
public static void Main()
{
Debug.Print("Program Started" );
// Pulse counter on timer 2 G120
Register PCONP = new Register(0x400FC0C4);
PCONP.SetBits(1 << 22);//enable timer3
// Select P0[4] T2_CAP0
Register PINSEL0_4 = new Register(0x4002C010);
PINSEL0_4.SetBits((3 << 0));//set bits 0 and 1 ---- enable pin
// To enable timer/counter
Register T2TCR = new Register(0x40090004);
T2TCR.SetBits(1 << 0);
// set prescale to 0
Register T2PR = new Register(0x4009000C);
T2PR.Write(0);
Register T2CTCR = new Register(0x40090070);
T2CTCR.Write(2 << 0 | 0 << 2);//count on falling edge and use CAPn.0
// should be 0 for a counter
Register T2CCR = new Register(0x40090028);
T2CCR.ClearBits(0x07);
// Don't do anything on match
Register T2MCR = new Register(0x40090014);
T2MCR.Write(0);
// To start the counter
T2TCR.SetBits((1 << 1));
T2TCR.ClearBits((1 << 1));
// To read
Register T2TC = new Register(0x40090008);
while (true)
{
uint count = T2TC.Read();
Debug.Print("Total count: " + count);
T2TCR.SetBits((1 << 1));
T2TCR.ClearBits((1 << 1));
Thread.Sleep(1000);
}
}
if someone has this for the STM32 and would care to share that would be great