MichaW
Posts: 2
Joined: Mon Feb 24, 2014 10:58 am

Using wiringPiISR

Mon Feb 24, 2014 11:28 am

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?

CaptainMadman
Posts: 3
Joined: Fri Feb 28, 2014 6:48 pm

Re: Using wiringPiISR

Fri Feb 28, 2014 8:52 pm

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

Ahmadian
Posts: 12
Joined: Wed Aug 28, 2013 4:19 pm

Re: Using wiringPiISR

Tue Mar 04, 2014 7:45 am

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.
Last edited by Ahmadian on Tue Mar 04, 2014 8:12 am, edited 1 time in total.

Ahmadian
Posts: 12
Joined: Wed Aug 28, 2013 4:19 pm

Re: Using wiringPiISR

Tue Mar 04, 2014 7:48 am

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

MichaW
Posts: 2
Joined: Mon Feb 24, 2014 10:58 am

Re: Using wiringPiISR

Tue Mar 04, 2014 7:49 pm

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;
    }

Paul Moir
Posts: 46
Joined: Wed Dec 04, 2013 7:25 pm
Location: Nova Scotia, Canada

Re: Using wiringPiISR

Tue Mar 04, 2014 10:32 pm

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!)

User avatar
joan
Posts: 14074
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using wiringPiISR

Wed Mar 05, 2014 8:51 am

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.

Ahmadian
Posts: 12
Joined: Wed Aug 28, 2013 4:19 pm

Re: Using wiringPiISR

Thu Mar 06, 2014 1:07 am

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.

360manu
Posts: 1
Joined: Mon Mar 17, 2014 2:14 pm

Re: Using wiringPiISR

Mon Mar 17, 2014 2:38 pm

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

Return to “Beginners”