View previous topic :: View next topic |
Author |
Message |
arrow
Joined: 17 May 2005 Posts: 213
|
Interrupts on two lines?-- Easy Question |
Posted: Fri Jun 24, 2005 7:15 am |
|
|
Hi
I have two signals going from 0 to Vss and back to 0.
Can someone please tell me how I can determine when the signals go L-H and H-L? The two signals have no sequence and either can go H first.
Can I use two external interrupts?
Thank you for your help.
arrow |
|
|
valemike Guest
|
|
Posted: Fri Jun 24, 2005 8:50 am |
|
|
Okay, for one of the interrupts, you may use Rb0:
Code: |
/* Set up RB0 as an interrupt */
ext_int_edge(H_TO_L); // init interrupt triggering for limit switch
enable_interrupts(INT_EXT);
|
As for the other interrupt, when i have time (or someone else can answer it), i'll look at the documentation for how to set up interrupt on change on the other portB pins. Off hand, i'm not aware if i can set H_TO_L or L_TO_H on the other interrupts.
Your application sounds very much like an encoder. Depending on the direction the shaft is turning, one signal will lead the other and vice versa. If this is the case, then you don't need two interrupts; you just need one. If rb0 causes an interrupt, then in your isr, you would look at the state of the other pin.
If your two interrupts are purely independent of each other, then yes, you will still need an answer to your question on how to configure the edge interrupt of the other pin.
-Mike |
|
|
Guest
|
|
Posted: Fri Jun 24, 2005 9:08 am |
|
|
Hi valemike
Thank you for your reply.
Yes I have two trully independent interrupts.
They are comming from a 2 axis accerlometer.
I can check if its H-L or L-H programmatically.
Regards
arrow |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Fri Jun 24, 2005 9:34 am |
|
|
You can also do this with the interrupt on change feature of B4-B7, #int_RB.
About a year ago I posted an interrupt driven keypad routine. It's in the code library. You'll have to go to the 2nd page of postings; I believe it's called "complete listing - interrupt driven keypad routine."
Examine the code and see if you can figure out how it works. It can be quite easily modified to pick up on your two separate lines going L-H and H-L. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jun 24, 2005 10:44 am |
|
|
FYI
Vss is usually 0V
Vdd is usually 5V |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Fri Jun 24, 2005 10:59 am |
|
|
You could use a hardware approach. Take 2 S-R latches such as CD4043 or CDCD4044 and connect your accelerometer signals to the S inputs. Your accelerometer spike will latch in the S-R latches and they you just poll the Qs and reset the buffers with Rs. This approach frees up your interrupts. On the other hand it introduces a delay, a variable one.
Nick |
|
|
sseidman
Joined: 14 Mar 2005 Posts: 159
|
|
Posted: Fri Jun 24, 2005 1:19 pm |
|
|
kender wrote: | You could use a hardware approach. Take 2 S-R latches such as CD4043 or CDCD4044 and connect your accelerometer signals to the S inputs. Your accelerometer spike will latch in the S-R latches and they you just poll the Qs and reset the buffers with Rs. This approach frees up your interrupts. On the other hand it introduces a delay, a variable one.
Nick |
I kind of like the hardware approach for this, but this approach seems dependent upon whether the accelerometer spike can latch the flipflops.
Without going through truth tables to figure out what logic you need to use on channel A and B to generate a pulse on every transition of A and B, you could route both signals to positive and negative edge triggered one shots (for a total of four one shots). You could either OR all of these one shots together and send the result to your external interrupt, an on interrupt poll both A and B, or you can send the output of all four one shots to the high bits of portB, and which line generates the interrupt tells you which transition happened.
This is CLEARLY the brute force approach. |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Fri Jun 24, 2005 7:46 pm |
|
|
Quote: | ...but this approach seems dependent upon whether the accelerometer spike can latch the flipflops. |
You're right - comparators would be highly advisable. Here as well as in the 2 interrupt lines approach. |
|
|
valemike Guest
|
|
Posted: Fri Jun 24, 2005 9:25 pm |
|
|
Anonymous wrote: | Yes I have two trully independent interrupts.
They are comming from a 2 axis accerlometer.
|
There is a rather straightforward circuit that Freescale uses to implement its MC13192 development kit. It has a 2-axis accelerometer and a 1-axis accelerometer. It runs on batteries too.
The code is in C, so you can probably find out how to it. |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Sat Jun 25, 2005 1:35 am |
|
|
Hi Valemike and All
Thank you all for responding. This gives me quite a few lines of approach!
Valemike can you please post the URL where I can find the C code for the MC13192 Freescale accelerometers?
All the best
arrow |
|
|
|