Content originally posted in LPCWare by mathseng on Thu Jun 18 17:41:36 MST 2015
Hi
I think the most effective answer can be found by looking in the NXP Application note AN11242, which gives details of two of the approaches I would think of using - count number of transitions in a gate time, and count number of cpu cycles in a transition. It also shows the errors to be expected with both of these approaches, and sample code is provided.
Querying this site with 'counter' shows a number of results which may be helpful.
Presuming that duty cycle is not required, then I would probably use one of the following:
With only one interrupt permitted, then I would probably go for the count of transitions in a gate time. Make the gate time 1S (1000 timer interrupts). With a 100/120MHz cpu, there should be enough cycles to do a simple if/then test for changes on each of the 5 pins, and update counters on change. Maybe even enough to have 2 counters, offset by 0.5S giving an update rate of 0.5S with a good resolution. This should also allow enough time to send data down a serial line without impacting on accuracy at these rates. Advantage is the don't care of edge timing, only looking at levels.
Another option could be to connect the 5 inputs to the 4 timer capture inputs. Unfortunately, this won't allow all 5 inputs concurrently - only 4. Read the length of a pulse using the capture feature, then change the timer with 2 inputs to respond to the second pin. This approach allows higher frequencies to be measured - the only error being the jitter of the input edges to the cpu clock. The 1mS timer is still needed to allow timeout when the inputs have a too-low frequency.
Another option, but with a possibly greater error (due to interrupts and other code getting in way) is to have a loop reading the edges. On change, read the System Tick Timer, beware of the reload value. For long cycle periods, there will be many reloads (1 per timer tick). Lots of housekeeping required. I treat the timer value as an offset from the count of 1mS ticks - the error being the varying time to read after the desired edge.