Go Down

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

Robin2

#75
Aug 31, 2017, 12:13 amLast Edit: Aug 31, 2017, 12:14 am by Robin2
How would it check the YELLOW pin? The yellow pin and red pin overlap but there is a time lag. A rising edge would check immediately, and that moment yellow will be low. So there will be an error?
Because it is a long time I may have forgotten stuff.

If there is a possibility that the yellow pulse will begin after the red pulse starts and before a valid short red pulse ends then you need code in the yellow ISR to set a variable that will invalidate the otherwise valid short red pulse.

(I'm getting the feeling that I am being left to do all the thinking for this project)

Quote
Does this require finding out the length of Short RED pulse apriori?
I have been assuming all along that you have a clear definition of what you mean by "short" for the purpose of deciding if a pulse is short or long. Have I been labouring under a misapprehension?

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

kenwood120s

#76
Aug 31, 2017, 06:42 am
Sometimes priorties change sir.
Of course, but I was just making the point that you shouldn't expect a 30 minute turnaround this time, now that this project has found its way back to your front burner.

[gumby]I've got my head stuck in the cupboard[/gumby]

Juraj

#77
Aug 31, 2017, 08:47 am
did you try my simple approach from answer #56 ? It may not be good enough because of sampling speed, but it is very simple and worth trying I think
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

bitoff_arduino

#78
Aug 31, 2017, 12:28 pmLast Edit: Aug 31, 2017, 12:40 pm by bitoff_arduino
So here is something i have tried and it kinda works. In the code below the rising edge of red pulse fires an interrupt.
In the interrupt routine i put an arbitrary delay (not the best solution), and check whether yellow pulse is HIGH, if it is high then it is not the
pulse of my interest otherwise it is.

I am not happy with the delay thing because it requires me to arbitrarily find a delay time so that the red and yellow pulses overlap.

Code: [Select]
`const byte  ChannelB = 8;           // the pin that receives yellow pulsesconst byte  OutputPin = 5;         // Output to labview const byte  interruptPin = 2;      // pin that receives red pulsesint ChannelBstate; void setup() {    pinMode(ChannelB, INPUT);  pinMode(OutputPin, OUTPUT);         pinMode(interruptPin, INPUT_PULLUP);  attachInterrupt(digitalPinToInterrupt(interruptPin), detect, RISING);  } void loop() {     } void detect() { delayMicroseconds(5200); //random delay so that when red isr fires, a yellow overlap can be detected   ChannelBstate  = digitalRead(ChannelB); if (ChannelBstate == LOW) {      digitalWrite(OutputPin, HIGH);      delayMicroseconds(2000);      digitalWrite(OutputPin, LOW);      }} `

dougp

#79
Aug 31, 2017, 02:02 pm
The waveform in post #78 is more than a little different from the original (post #5).
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!

bitoff_arduino

#80
Aug 31, 2017, 02:06 pm
The waveform in post #78 is more than a little different from the original (post #5).
It always is, changes due to different background noise, experimental conditions. But problem stays the same; sort out the short red pulses and generate an output.

Juraj

#81
Aug 31, 2017, 02:22 pm
In the interrupt routine i put an arbitrary delay (not the best solution), and check whether yellow pulse is HIGH, if it is high then it is not the pulse of my interest otherwise it is.
try it in loop() like in your original post
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

bitoff_arduino

#82
Aug 31, 2017, 02:40 pmLast Edit: Aug 31, 2017, 02:46 pm by bitoff_arduino
try it in loop() like in your original post
Could you please explain what this does, this is from your proposed solution:

if (PinAstate != PinBstate && syncToleranceCountdown > 0) {
syncToleranceCountdown--;
return;
}
syncToleranceCountdown = SYNC_TOLERANCE_RESET;

Juraj

#83
Aug 31, 2017, 06:17 pmLast Edit: Aug 31, 2017, 06:24 pm by Juraj
It is a patch to handle the small out-of-sync in your code in the original post. It skips max SYNC_TOLERANCE_RESET loops if the inputs do not match.

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;       const int  SYNC_TOLERANCE_RESET = 10; int PinAstate;int PinBstate;int syncToleranceCountdown = 0; 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 (PinAstate != PinBstate && syncToleranceCountdown > 0) {    syncToleranceCountdown--;    return;  }  syncToleranceCountdown = SYNC_TOLERANCE_RESET; if (PinBstate == LOW) {    if (PinAstate  == HIGH){      digitalWrite(PinC,HIGH);     delayMicroseconds(100);       digitalWrite(PinC,LOW);}  } }`
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Robin2

#84
Aug 31, 2017, 06:44 pm
I am not happy with the delay thing because it requires me to arbitrarily find a delay time so that the red and yellow pulses overlap.
Neither am I.

Can't you use a separate ISR triggered by the yellow pin? - then there is no need for an arbitrary time.

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

Brian_v

#85
Feb 22, 2019, 05:15 am
come guys, any pointers?
Here, i will give you the logic, Just make Pulse 2 equals to Pulse 1, And that's it,you could see the effects by adding 2 leds, each for one button. And Keep using if statement.

Go Up