Detect presence 5V square wave on five pins simultaneously

Hi,

Detect presence 5V square wave on five pins simultaneously

The subject says everything I need, the duty ratio is 50%.

I only need to know if the signal is present or not.

How could I do this from software on five pins?

Thank you!

More info gets you better help.

What have you tried so far? What sort of signals are they? In syn? Not in sync? Random phase? Some fixed elationship with each other? Define your idea of simultaneously. How close together do you need the tests? What sort of frequency are the signals?

Search for "Arduino Pin Change Interrupt" - it is likely this is what you want to do.

Note that this is -not- the same as an "external interrupt".

With a pin change interrupt, you can detect when the change occurs - but you can't (easily) detect which pin of the port you are monitoring caused it. There are libraries available that make using pin change interrupts simpler.

Hope this helps...

augre: Detect presence 5V square wave on five pins simultaneously

How could I do this from software on five pins?

Take a look in the Arduino reference. http://www.arduino.cc/en/Reference/PortManipulation

It may be what you are talking about.

Isnt there a frequency library? Run 5 instances of it

The problem isn't well formed. If I have 5 square waves present on 5 pins, but with a frequency of 0.000001Hz, I can't "detect" it (any time soon).

Similarly if the waves were 50MHz I might not be able to detect it either as the hardware can't go that fast.

What frequencies are we talking, it matters, and it affects what techniques work well.

augre: Detect presence 5V square wave on five pins simultaneously

What is the criteria for a 5V square wave being present on one pin? If you can explain that, then determining when all five pins meet that condition should be a doddle.

augre: The subject says everything I need

Actually, from my perspective you have left out a lot of detail which we would need to know to answer your question properly.

Start a flowchart :) IF your hardware doesnt allow simultaneous sampling, you might have to make sure the pulses will be there when you "need them. You would have to sample them at a fifth of the total duration of half cycle (time of the half duty that they will be on... give some overhead, maybe?!) IF the hardware allows for it, capture the 5 bits in the port register and check the bits set/cleared ?! All the rest in inherent to the board you might be using, itself ! Higher frequencies will surely require much more optimization than just digital read(), (and similar arduino functions) , though

Hi,

Really sorry for leaving the details out, I'm an idiot.

So 500Hz square wave Board is arduino uno

So I am using 5 IR detectors, which output a 500Hz square when they get signal. A continuous High when no signal.

I would like to know which one/ones get signal.

Thank you for the posts!

Run the signals thru an inverter, and then each thru a low pass RC filters. If the frequency is there, the signal out will be high - and if not, will be low. The amount of filtering will determine the level out.

Perhaps this will do:

int i;

void setup() {
  Serial.begin (9600);
  pinMode(3,INPUT_PULLUP);
  pinMode(4,INPUT_PULLUP);
  pinMode(5,INPUT_PULLUP);
  pinMode(6,INPUT_PULLUP);
  pinMode(7,INPUT_PULLUP);
  }

void loop() {
  for (i = 3; i < 8; i++) {
    if (digitalRead(i) == 0) {
      Serial.println(i);
    }
  }
  delayMicroseconds(100);
}

Best way to check it is at half point of where you expect the square wave to be, otherwise you risk drifting out of range. so it would have to check 50Hz after the rising edge being detected( aim at the middle of the positive side of the sqr wave), for example.

Of course this simplicity will only work if you are only expecting them to be there at same time. If its a time-varying signal, you might have to dig for more precision.
I helped expand one of the initial IR libraries to use several receivers… Im not sure if that would help you ( Was more from a code side, but if you think suitable might be a starting point ).
PS- Hadnt read the detail of the sqr when signal , and continuous when no signal.
Thats different. :slight_smile: Some of the idea still works but on the low edge instead. and allow for the other pins reading within the interrupt?!
Not quite sure how its best to go about it.

Waveforms.svg.png

Poll each input at regular intervals shorter than your expected pulse length. Use edge detection to determine whether the input has changed state. Each time the input changes state, record the current time (as supplied by millis()). If the last changed time for an input is recent enough then the input is active, otherwise it is inactive. 'Recent enough' means that the difference between the current time and the last change time is smaller than some threshold value. I'd suggest setting the threshold to some small multiple of the expected pulse length.

This approach would determine whether you were receiving pulse on a given input regardless of the frequency or duty cycle. If you wanted to be more selective, you'd need to use a different approach.

As mentioned earlier the pin change interrupt is good approach... http://playground.arduino.cc/Main/PinChangeInt

In the interrupt routine just do a direct port read. If you have all 5 signals on the same PORT this is just one relatively quick instruction.

Then pass this info to your main loop (using a 'volatile' variable) which should do the processing to see which of the 5 signals have changed value/state. At 500Hz you should have plenty of clock cycles available to do other things.

CrossRoads: Run the signals thru an inverter, and then each thru a low pass RC filters. If the frequency is there, the signal out will be high - and if not, will be low. The amount of filtering will determine the level out.

Thank you! This is a very simple way to solve the problem, I love it. I think above a voltage level of 2V the arduino will see it as High, so it should be fine after the filter.

I think above a voltage level of 2V the arduino will see it as High, so it should be fine after the filter.

On a 3.3V Arduino, yes. On a 5V Arduino, no. HIGH is about 60% of the nominal voltage.

pin change interrupt is your best bet.

you can detect which pin changed and from high to low or low to high in the interrupt handler. not only that, you can even determine how many microseconds the pulse length is.

That is how flight controllers (like quadcopters), a lot of which are still based on atmega cpus, read signals from RC receivers.