I'm a little confused by your requirements.
You state it is a mechanical system - suggesting some debounce might be necessary(?), or is this part of the fault condition to be counted? You worry for the speed of the system and capturing every event, but then state the count need not be too accurate... The requirements are likely very clear in your mind, but reading... it leaves me wondering, just how fast an event you wish to capture and what constitutes an event?
Here we go into areas I'm not qualified to speak with much expertise...
I had imagined some level of filtering to eliminate the tiniest of glitches - capacitors, as used on power supply, to eliminate noise and other such tiny perturbances and measuring events in the range of a few milliseconds - maybe less, I hadn't really thought of minimal times possible, only to make a stable system that reacts reliably and consistently rather than to every stray passing gamma ray. Henrik's suggestion to use ORs is much better... I thought to use latching flip-flops to maintain state until the PIC could read and reset in a tight loop/ interrupt. My idea being that mechanical systems are typically pretty slow and messy, and accuracy at the level I work is typically limited to what I can see and measure. This seems not to be the case for your requirements.
Well, in any case it has been an interesting read - and you have determined an answer suitable... back to the bench for me!
Oh, as to your question... I'd likely stack all the flags into a bit array and then loop through as:
For LOOP = 0 to 8 'For each flag
If BIT[LOOP] Then 'If bit is set
CounterWord[LOOP] = CounterWord[LOOP] + 1 'Add one to count
EndIf
Next
...unless, as I was typing, Henrik posted a more artful method in the post following.![]()
Bookmarks