hello everyone,
I am using a turbine which generate pulses with (approx45 degree) phase shift for forward and backward direction {images have been attached}
now the output pulses have been attached to the two different interrupts of arduino uno on pin2 and pin3
and now when the turbine moves in forward direction pin2 interrupt activates and starts function written on interrupt but then second interrupt on pin3 comes and interrupt the functioning of first interrupt.
Now What i want to do is that when turbine moves in forward direction then only pin2 interrupt will activate and when the trubine moves in reverse direction then only pin3 interrupt will activate for the no of pulses...
plz help... i shall be very thankful to you..
Take a look at the implementation of quadrature encoder interrupt handlers.
Pieter
then second interrupt on pin3 comes and interrupt the functioning of first interrupt.
Interrupts are disabled by default when an ISR is running, so unless you have deliberately enabled them in the first ISR then the second interrupt will not be interrupt the first one. What proof do you have that it is happening ?
Post your program so that we can see what you have done. The code in ISRs should be sort, very, very short.
int interruptPin = 2;
int interruptPin1 = 3;
int a;
int c;
volatile int count = 0;
volatile int count2 = 0;
void setup() {
pinMode(interruptPin, INPUT);//Sets the pin as an input
pinMode(interruptPin1, INPUT);//Sets the pin as an input
attachInterrupt(digitalPinToInterrupt(2), Flow, RISING);
attachInterrupt(digitalPinToInterrupt(3), check, RISING);
Serial.begin(115200);
}
void loop()
{
}
void Flow()
{
count++; //Every time this function is called, increment "count" by 1
Serial.print("pulse1=");
Serial.println(count);
}
void check()
{
count2++;
Serial.print("pulse2=");
Serial.println(count2);
}
now i want that whenever turbine moves in clockwise direction then only interrupt on pin2 will activate
and serial print only pulse1 and count.
And when turbine moves in counterclockwise then only interrupt on pin3 will activate and serial print only pulse2 and count2.
How will you know which direction the turbine is moving in by reading only 1 pin ?
By the way, Serial.print() should not be used in ISRs because it uses interrupts and they are disabled.
because when i blow air though turbine it moves in clockwise direction and when i inhale air through that turbine it moves in counterclockwise direction..
so please suggest what should i do..
a) answer all questions
b) remove the print()'s 
And if you want a print, move them to loop() and just check if count changed (hint, state change example)
vinod0786:
so please suggest what should i do..
I suggested what you should do in reply #1, but you seem to have completely ignored what I expect to be the solution to your problem ...
Please provide the link for example
I'm guessing that the execution of the first ISR is not being interrupted. Rather, the second interrupt is being queued and then serviced after the first ISR exits.
I asked
How will you know which direction the turbine is moving in by reading only 1 pin ?
you replied
because when i blow air though turbine it moves in clockwise direction and when i inhale air through that turbine it moves in counterclockwise direction.
that is not an answer to the question.
so you mean to say that i have to check condition in both interrupts and then make combinations for forward and reverse direction.
vinod0786:
so you mean to say that i have to check condition in both interrupts and then make combinations for forward and reverse direction.
Yes.
One way to do it is to save the time an interrupt occurs. That allows you to determine in which order they occur and hence the direction of rotation.
What you have is a simple quadrature encoded signal. It doesn't matter if they are 45° or 90° out of phase. The principle is exactly the same.
Just get yourself an Encoder library to do the hard work for you, or at least look at other people's implementations, there are plenty to be found online.
There's a link on the playground with literally dozens of links providing detailed explanation on how it works, many libraries, many more examples, and further discussions on the topic.
https://playground.arduino.cc/Main/RotaryEncoders
Either decide that you want to reinvent the wheel, or just use the code of people that tried it before you.
In either way, please do your research, and answer the questions asked.
Thank you UKHelibob , PieterP and everybody else for you support and help...
i will try to resolve it with your advice but if i got any other problem than i will come back to you for help..
ThankYou once again