Page 1 of 1

Using wiringPiISR

Posted: Mon Feb 24, 2014 11:28 am
by MichaW
Hello all, I'm the first time here in this forum and I hope there is anybody who can help me.

I try to use the wiringPiISR function. A first simple example is working fine. Now I try to use this function to analyze the transition from high to low and from low to high on the same pin. That means I wrote two calls of wiringPiISR.
wiringPiISR(0, INT_EDGE_RISING, &myfirstfunction) and wiringPiISR(0, INT_EDGE_FALLING, &mysecondfunction)
Only one call is working (seems to be random).
Has anybody a hint for me, what I do wrong?

Re: Using wiringPiISR

Posted: Fri Feb 28, 2014 8:52 pm
by CaptainMadman
Unfortunately, I don't have an appropriate answer to your question. Still, it seems we are working on the same issue.
I'm trying to trigger a photo flash bulb with a GPIO. The GPIO is connected to an opto coupler with triac output, the triac in its turn is connected to the input of the flash. According to my multimeter, the triac is triggered; voltage is dropping from 260 V to 0. Still, the bulb does not flash. Manually shorting the triac will ignite the flash- operating the opto triac on a breadbord works as well- no wiring problems. So I'm wondering whether the GPIO, loaded with about 10 mA is transiting to slow proper operation of the triac.
Do you have any advice?
Cpt. Madman

Re: Using wiringPiISR

Posted: Tue Mar 04, 2014 7:45 am
by Ahmadian
MichaW wrote:Hello all, I'm the first time here in this forum and I hope there is anybody who can help me.

I try to use the wiringPiISR function. A first simple example is working fine. Now I try to use this function to analyze the transition from high to low and from low to high on the same pin. That means I wrote two calls of wiringPiISR.
wiringPiISR(0, INT_EDGE_RISING, &myfirstfunction) and wiringPiISR(0, INT_EDGE_FALLING, &mysecondfunction)
Only one call is working (seems to be random).
Has anybody a hint for me, what I do wrong?
Hi
You must use wiringPiISR(0, INT_EDGE_BOTH , &mysecondfunction) instead.

Re: Using wiringPiISR

Posted: Tue Mar 04, 2014 7:48 am
by Ahmadian
CaptainMadman wrote:Unfortunately, I don't have an appropriate answer to your question. Still, it seems we are working on the same issue.
I'm trying to trigger a photo flash bulb with a GPIO. The GPIO is connected to an opto coupler with triac output, the triac in its turn is connected to the input of the flash. According to my multimeter, the triac is triggered; voltage is dropping from 260 V to 0. Still, the bulb does not flash. Manually shorting the triac will ignite the flash- operating the opto triac on a breadbord works as well- no wiring problems. So I'm wondering whether the GPIO, loaded with about 10 mA is transiting to slow proper operation of the triac.
Do you have any advice?
Cpt. Madman
You can use a BJT for buffering GPIO port.
see below image:
http://www.sonelec-musique.com/images/e ... c_001d.gif

Re: Using wiringPiISR

Posted: Tue Mar 04, 2014 7:49 pm
by MichaW
Ahmadian wrote:
MichaW wrote:Hello all, I'm the first time here in this forum and I hope there is anybody who can help me.

I try to use the wiringPiISR function. A first simple example is working fine. Now I try to use this function to analyze the transition from high to low and from low to high on the same pin. That means I wrote two calls of wiringPiISR.
wiringPiISR(0, INT_EDGE_RISING, &myfirstfunction) and wiringPiISR(0, INT_EDGE_FALLING, &mysecondfunction)
Only one call is working (seems to be random).
Has anybody a hint for me, what I do wrong?
Hi
You must use wiringPiISR(0, INT_EDGE_BOTH , &mysecondfunction) instead.
Thank you. I tried it, but it does not work. Now I get the same result on both transitions. I can't distinguish the rising or falling flank. Here is my code ...

Code: Select all

    if (wiringPiSetup () < 0) {
		fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
		return 1;
    }

    if (wiringPiISR (ONOFF_PIN, INT_EDGE_FALLING, &fallingInterrupt) < 0) {
		fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
		return 1;
    }
    
    if (wiringPiISR (ONOFF_PIN, INT_EDGE_BOTH, &risingInterrupt) < 0) {
		fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
		return 1;
    }

Re: Using wiringPiISR

Posted: Tue Mar 04, 2014 10:32 pm
by Paul Moir
Ints are binary and your ISR will have to deduce if it was the rising edge or the falling edge that caused the interrupt. So the first thing you would want to do in your ISR code is to read the GPIO pin and determine if it's high or low and therefore whether it was a low-high or high-low transition that caused it.
An alternative is to wire your signal into two GPIO pins, and configure one for rising and one for falling. That would be a little more deterministic since there would be no deduction (and on a fast pulse you might miss it). Also that way you could have two separate routines for rising or falling which is what you appear to want to have.

In your initialization code you posted, you're setting up the ISR for a falling transition, then immediately telling it, no I don't want you to trigger on a falling, I want you to trigger on both. It's binary, it can't be both.

EDIT: CaptainMadMan: your issue is quite a bit different. Please start a new post so we can stay on-topic. Also, if you can post a schematic or a picture of what you're doing. A photo of a hand-drawn schematic is fine (and often the fastest way, even in this day and age!)

Re: Using wiringPiISR

Posted: Wed Mar 05, 2014 8:51 am
by joan
For timing critical stuff it is probably better to use pigpio. The callback will give you the gpio, level, and tick at which the level change was detected. It will also handle level changes in rapid succession.

Re: Using wiringPiISR

Posted: Thu Mar 06, 2014 1:07 am
by Ahmadian
As Paul said, Interrupts must be defined just in the begin of the program.
Example:
wiringPiISR (pinx, INT_EDGE_BOTH, &my_intr_function);

Then, in the my_intr_function you can read pinx as normal GPIO to find its rising or falling.
Example:
if ( digitalRead(pinx) == 1) rising_edge_Interrupt_function(); else falling_edge_Interrupt_function();

joan: Upon my studies, wiringPI is great work of Gordon Henderson that may be used in professional works.

Re: Using wiringPiISR

Posted: Mon Mar 17, 2014 2:38 pm
by 360manu
Hello

From the code, we can see that you can only register one interupt for a given PIN.
"interupts" are stored in a table indexed by the pin number (isrFunctions)

if you use : INT_EDGE_BOTH, It seems that you can't know the initial state.
Try using pigpio as mentioned by Joan.

Emmanuel