Go Down

### Topic: Sorting digital signals (Read 4431 times)previous topic - next topic

#### bitoff_arduino

##### Jul 20, 2017, 05:46 pmLast Edit: Jul 20, 2017, 05:51 pm by bitoff_arduino
Hello all,

I have two digital pulses and would like to generate an output based on some boolean logic.

Pulse 1 contains some digital pulses.

Pulse 2 contains some of the digital pulses contained in Pulse 1.

Means Pulse 2 is a subset of Pulse 1.

Now i would like to generate an output for the pulses which are exclusive to pulse 1.

Here is what i have done so far, but it doesnt not work because Pulse 1 and Pulse 2 have some time lag.
See attached picture, i would like to generate a digital output for the small red pulse. Not for the overlapping red and yellow.

Code: [Select]
`const int  PinA = 2;            // the pin that receives all digital pulsesconst int  PinB = 3;           // the pin that receives subset of PinA pulsesconst int  PinC = 5;       int PinAstate;int PinBstate; void setup() {  pinMode(PinA, INPUT);         // initialize the  pins as a input:  pinMode(PinB, INPUT);  pinMode(PinC, OUTPUT);    // initialize the Pin as an output:  }void loop() {  PinAstate = digitalRead(PinA);  PinBstate = digitalRead(PinB); if (PinBstate == LOW) {    if (PinAstate  == HIGH){      digitalWrite(PinC,HIGH);     delayMicroseconds(100);       digitalWrite(PinC,LOW);}  } }`

#### bitoff_arduino

#1
##### Jul 20, 2017, 06:33 pm
come guys, any pointers?

#### sterretje

#2
##### Jul 20, 2017, 06:39 pm
Netiquette states that you should wait 24 hours before kicking your post.

Give it some time to go around the world.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

#### J-M-L

#3
##### Jul 20, 2017, 06:56 pmLast Edit: Jul 20, 2017, 07:09 pm by J-M-L
your code has pinA et pinB which one is pulse1 and pulse2 --> use consistent naming

why do you do this?
Code: [Select]
`     delayMicroseconds(100);       digitalWrite(PinC,LOW);`
if you want to mirror one of the signal, based on the truth value of the other (if I understood you correctly), why do you arbitrarily get to LOW after an arbitrary duration?

fill out this table: what do you want to see for PinC value based on the state of pinA and pinB?

 PinC        PinB LOW HIGH PinA LOW ? ? HIGH ? ?
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

#### Robin2

#4
##### Jul 20, 2017, 10:01 pmLast Edit: Jul 20, 2017, 10:02 pm by Robin2
Pulse 1 contains some digital pulses.

Pulse 2 contains some of the digital pulses contained in Pulse 1.

Means Pulse 2 is a subset of Pulse 1.

Now i would like to generate an output for the pulses which are exclusive to pulse 1.
What does all that mean?   Based on ordinary english Pulse 1 is a single pulse and cannot contain "some digital pulses"

Are you talking about a long stream of pulses and a subset of that stream and whenever the pattern in the subset re-occurs in the main stream you want something to happen?

Or what?

If you are talking about streams of pulses it would help if you provide a diagram showing what you mean.
And tell us what is generating the stream of pulses and why you need to match parts of it.
And what is the pulse frequency - is an Arduino fast enough?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### dougp

#5
##### Jul 21, 2017, 01:37 am
Do the waveforms consistently look like this repeating pattern?

If so I'd look for a way to discriminate the width of the narrow pulse. Like, A on for x millibleeps while B is low.

.02

Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

#### J-M-L

#6
##### Jul 21, 2017, 07:48 amLast Edit: Jul 21, 2017, 07:50 am by J-M-L
To OP so you want feedback quick and when you get some you disappear?

Quote
Now i would like to generate an output for the pulses which are exclusive to pulse 1.
That's what we don't get really... filling up the small truth table above would help. You know the values of pinA and pinB if from that you can explain what 'exclusive' means?

Guesswork:

- In the picture yellow is a subset of red so pulse2 is yellow and pulse1 is red by OP definition
- Assuming PIN letters are in same order pinA would be red and pinB would be yellow.

Thus In the initial code the attempt was to say if yellow is low and red is high the output is HIGH so it seems OP wants all the red only when yellow is off.

--> The OP code would then need to set the output at whatever red is when yellow is low and low otherwise? Then the code would simply be
Code: [Select]
`if (PinBstate == LOW) digitalWrite(PinC, PinAstate); else digitalWrite(PinC, LOW);`
This could also be achieved by calculating the output with Boolean arithmetic (the truth table value)

Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

#### bitoff_arduino

#7
##### Jul 21, 2017, 10:08 am
your code has pinA et pinB which one is pulse1 and pulse2 --> use consistent naming

why do you do this?
Code: [Select]
`     delayMicroseconds(100);       digitalWrite(PinC,LOW);`
if you want to mirror one of the signal, based on the truth value of the other (if I understood you correctly), why do you arbitrarily get to LOW after an arbitrary duration?

fill out this table: what do you want to see for PinC value based on the state of pinA and pinB?

 PinC        PinB LOW HIGH PinA LOW ? ? HIGH ? ?

I want PinC to be HIGH for the following:

if PIN A is HIGH and PIN B is LOW: PIN C HIGH

This doesnt work in my case because although PIN B is a subset of PIN A, they are not in sync.

#### J-M-L

#8
##### Jul 21, 2017, 10:11 am
See #7
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

#### bitoff_arduino

#9
##### Jul 21, 2017, 10:14 am
What does all that mean?   Based on ordinary english Pulse 1 is a single pulse and cannot contain "some digital pulses"

Are you talking about a long stream of pulses and a subset of that stream and whenever the pattern in the subset re-occurs in the main stream you want something to happen?

Or what?

If you are talking about streams of pulses it would help if you provide a diagram showing what you mean.
And tell us what is generating the stream of pulses and why you need to match parts of it.
And what is the pulse frequency - is an Arduino fast enough?

...R
Yes its a digital signals of train of Pulses. Diagram is attached with the post, it is also posted above. Frequency is about 500 Hz. The two signals are generated by a camera trigger system.

From the diagram i only need an output when the small red pulse appears. I dont want any output when the red and yellow pulses appear/overlap.

#### bitoff_arduino

#10
##### Jul 21, 2017, 10:26 amLast Edit: Jul 21, 2017, 10:33 am by bitoff_arduino
To OP so you want feedback quick and when you get some you disappear?
That's what we don't get really... filling up the small truth table above would help. You know the values of pinA and pinB if from that you can explain what 'exclusive' means?

Guesswork:

- In the picture yellow is a subset of red so pulse2 is yellow and pulse1 is red by OP definition
- Assuming PIN letters are in same order pinA would be red and pinB would be yellow.

Thus In the initial code the attempt was to say if yellow is low and red is high the output is HIGH so it seems OP wants all the red only when yellow is off.

--> The OP code would then need to set the output at whatever red is when yellow is low and low otherwise? Then the code would simply be
Code: [Select]
`if (PinBstate == LOW) digitalWrite(PinC, PinAstate); else digitalWrite(PinC, LOW);`
This could also be achieved by calculating the output with Boolean arithmetic (the truth table value)

I am sorry for this ambiguity. I posted at EU evening time, and its morning now.

Yes the yellow is a subset of red. But they are out of sync in time. Thats why they dont overlap perfectly.

From the figure, i want output only when a small red pulse appears. Not when the bigger (wider pulse width) red and yellow appear.

Now since the bigger pulses are out of sync, my code doesnt work.

#### bitoff_arduino

#11
##### Jul 21, 2017, 10:45 amLast Edit: Jul 21, 2017, 10:55 am by bitoff_arduino
I hope this picture makes it easy to understand.

#### J-M-L

#12
##### Jul 21, 2017, 11:24 amLast Edit: Jul 21, 2017, 07:22 pm by J-M-L
Then you need a bit of a dynamic wait before deciding of the output to see if yellow arrives or not

A simple state machine will let you achieve this

States are rest, waiting for trigger, false event, active

You start at rest, when you receive a red HIGH you go to waiting for trigger, if yellow appears in a given timeout and red stayed high then you go to active otherwise you go to false event and wait until red goes back down to go to rest again.
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

#### Robin2

#13
##### Jul 21, 2017, 11:35 am
I hope this picture makes it easy to understand
Not really. Or not at all.

First let's deal with "not at all"

If I go back to your Original Post you said that P2 is a subset of P1. But in your diagram you seem to be treating P2 as a single pulse. A single pulse will always be a subset of a stream of pulses so the concept of subset doesn't make much sense.

If you are using a single pulse in P2 as a simplification then I don't think that makes sense. What works for one pulse won't translate to matching a train of pulses.

And now let's deal with "not really" - assuming that your description in the Original Post was wrong and you really only need to make decisions based on a single P2 pulse.

Are you saying that there should be an output if P2 is high and P1 is low? If so that should be easy to program.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

#### MarkT

#14
##### Jul 21, 2017, 01:01 pm
This is definitely a job for a state machine, there is state and time in this decision process as the yellow
pulses do not completely cover the red pulses, so combination logic cannot do the job.

Use micros(), not delay or delayMicroseconds, if you want to be responsive to changing inputs at all
times.

I suspect you need at least these states:

not in a pulse
in a yellow pulse only (is this valid?)
in a red pulse (for a short time only)
in a red pulse for a long enough time without seeing the yellow pulse - output HIGH
in a red + yellow pulse
in a red pulse after a yellow went away

You need to record the time when you transition from not in a pulse to in a red pulse,
and then check the elapsed micros for deciding when to transition to the output HIGH state.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up