handling multiple interrupt sources?

Started by arhodes19044 March 27, 2005

I have gotten the basics done on the rally computer.

I would like to have the timer generate an interrupt. I COULD do
this the crude way and have the PWM generator make something that
ticks at about one Hz, or a simple multiple thereof.

I could route the output of that to Pin 11 and trigger an
interrupt. However, I am already using Pin 11 for the wheel tick
interrupt.

So, I need to have either the wheel and/or the timer set off the
interrupt. But then I need to decide what one (or both) did it.

I am pretty sure this would be a simple TTL logic problem. But I
need to keep the source flagged (even if it goes off in the
interim) Until I have read it and then reset it. I assume I would
need a BX pin to reset each all the flags simultaneously [this might
need the use of an AND to reset only if the reset pin is high AND
the flag is high], and one other (pin 11) to create the interrupt.
Probably need another pin to read which interrupts actually need
servicing.

Is this a use of a "latch". I never used them or knew their actual
function. Maybe?? a 2 input XOR (inputs being the reset pin, and
its own output OR'ed with the interrupt. The reset pin probably
needs to be AND'ed with the XOR output so it does not toggle.

I don't know all the permutations of TTL devices. I bet there is
one device that does all this stuff internally!

-Tony I knew I kept those TTL DIPs around for a reason

-Tony



--- In basicx@basi..., "arhodes19044" <spamiam@c...> wrote:
> So, I need to have either the wheel and/or the timer set off the
> interrupt. But then I need to decide what one (or both) did it.

The external hardware that you need to combine input signals depends
on the nature of the signals. Are the levels important or is it the
edges.

If both signals are levels, you can use an S-R latch to "capture" the
fact that the level of interest has occurred. These are simple to
make using 2 NAND gates or 2 NOR gates cross connected. Which you
use depends on the level you're looking for. The NAND form is
activated by an active low signal, NOR for active high. Here is a
link showing a NOR S-R latch.

http://www.allaboutcircuits.com/vol_4/chpt_10/2.html

After you set up the two latches, you can then OR the signals
together and feed the output to pin 11 of the BX. You would probably
use a NOR and then use bxPinLow for the WaitForInterrupt() value.
You also have to feed the output of each S-R latch to a separate BX
input. That way, the interrupt task can read each input and discover
which input caused the interrupt (perhaps both did). After
determining which latch(es) are set, you need to reset them in
preparation for the next cycle. You do this by using two BX outputs,
one to each latch, connected to the other of the latches input (the
one not being used by your input signal).

If your input signals are edges (instead of levels as just discussed)
you probably want to used edge-triggered flip flops (e.g. 74xx109)
and wire them so that when they receive the edge of interest, they
get set. As before, you need one and one output per FF to be able to
read its state and reset it.


Tony, I've started a number of messages - and bailed out of each -
asking if you really want to do this. Each message provided anecdotes
of why you might not. In this message, I'll just summarize: it can be a
PITA.

FWIW, you will gain no more accuracy after bolting Timer1 to pin 11,
shared or not, because of the OS's time granularity. It's true that
you'll be notified when some time event occurs (not related to the OS's
RTC tick), but you can't assign any more resolution or accuracy to when
that happened than you can in software much more easily already.

Still, it'll be a great learning experience to go through the exercise
and learn all that you'll encounter, but it will not make you a better
rally computer, at least not yet, I'll bet. Sure you really want to try
this? Tom
Tom Becker
--... ...--
GTBecker@GTBe... www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700



Hey, that is so much help! I have a bunch of TTL gates in my bin,
and I can probably whip up the stuff I need. No flip-flops though.

Edge detection is OK, but level is ok too. As long as it gets
latched high when it GOES high and stays there even if the input
goes low, then I can talk a LITTLE time and process the interrupt.
Preferably before the next one strikes.

I have the PWM timer set to 3.5hz, and It will be used as the timer
interrupt. It will trigger a display update every 4th time it
fires. The wheel-tick interrupt will trigger an increment an
odometer and Calculated time readings.

I will try the TTL gates tonight If I have a chance.

Thanks again!

I will read that reference too!!! I bet is just the sort of thing I
need.

-TOny

--- In basicx@basi..., "Don Kinzer" <dkinzer@e...> wrote:
>
> --- In basicx@basi..., "arhodes19044" <spamiam@c...> wrote:
> > So, I need to have either the wheel and/or the timer set off the
> > interrupt. But then I need to decide what one (or both) did it.
>
> The external hardware that you need to combine input signals
depends
> on the nature of the signals. Are the levels important or is it
the
> edges.
>
> If both signals are levels, you can use an S-R latch to "capture"
the
> fact that the level of interest has occurred. These are simple to
> make using 2 NAND gates or 2 NOR gates cross connected. Which you
> use depends on the level you're looking for. The NAND form is
> activated by an active low signal, NOR for active high. Here is a
> link showing a NOR S-R latch.
>
> http://www.allaboutcircuits.com/vol_4/chpt_10/2.html
>
> After you set up the two latches, you can then OR the signals
> together and feed the output to pin 11 of the BX. You would
probably
> use a NOR and then use bxPinLow for the WaitForInterrupt() value.
> You also have to feed the output of each S-R latch to a separate
BX
> input. That way, the interrupt task can read each input and
discover
> which input caused the interrupt (perhaps both did). After
> determining which latch(es) are set, you need to reset them in
> preparation for the next cycle. You do this by using two BX
outputs,
> one to each latch, connected to the other of the latches input
(the
> one not being used by your input signal).
>
> If your input signals are edges (instead of levels as just
discussed)
> you probably want to used edge-triggered flip flops (e.g. 74xx109)
> and wire them so that when they receive the edge of interest, they
> get set. As before, you need one and one output per FF to be able
to
> read its state and reset it.




Well, It is mostly an exercise to see if I can reproduce the rally
computer. It would be hard to make it a BETTER computer, that is
for sure. The Alfa Elite is really really good.

I do not know what that Alfa's granularity is, but 1/512 isn't bad.
Imprecise measurement of Real Time, whatever its granularity, is
bad. While the granularity if only 1/512 of a second is not great,
as long as the precision of the granularity is good, then it is OK.
You know the old issue of resolution versus precision.

I decided that it is not too important to trigger the update at the
exact top of the second. It just needs to be done about every
second. This is because there is a separate readout of the time
error in seconds. Therefore it is "exact" at the moment of
display. The RTC and CTC readouts are for general info.

regarding interrupt timer vs. polled timer: There are circumstances
where the navigator is busy doing some important data entry and the
CPU is occupied in a different loop. But some updates for the
driver are still necessary, Hence the need for a non-polled timer
routine.

Yes, this is all just an academic exercise in the end. But I want
to try to test the limits of the BX and myself.

-Tony
--- In basicx@basi..., "Tom Becker" <gtbecker@r...> wrote:
> Tony, I've started a number of messages - and bailed out of each -
> asking if you really want to do this. Each message provided
anecdotes
> of why you might not. In this message, I'll just summarize: it
can be a
> PITA.
>
> FWIW, you will gain no more accuracy after bolting Timer1 to pin
11,
> shared or not, because of the OS's time granularity. It's true
that
> you'll be notified when some time event occurs (not related to the
OS's
> RTC tick), but you can't assign any more resolution or accuracy to
when
> that happened than you can in software much more easily already.
>
> Still, it'll be a great learning experience to go through the
exercise
> and learn all that you'll encounter, but it will not make you a
better
> rally computer, at least not yet, I'll bet. Sure you really want
to try
> this? > Tom >
> Tom Becker
> --... ...--
> GTBecker@R... www.RighTime.com
> The RighTime Clock Company, Inc., Cape Coral, Florida USA
> +1239 540 5700




--- In basicx@basi..., "Don Kinzer" <dkinzer@e...> wrote:

It occurred to me after posting the earlier response that:

a) I should have changed the subject line as I did this time.

b) I should have quantized the positive and negative ranges to 127
levels not 128. 128 represents the waveform zero, 129 to 255 is the
positive range and 127 to 1 is the negative range. You would still
add 128 after scaling, though to center the wave.

Your converter should check the result and limit the positive value
to, at most, 255. A similar check should be made on the negative side
to ensure that it doesn't go "below 0" and end up wrapping to the
other end of the byte value range.

Don




Don, thanks so much for that link. I learned a few definite tricks
and issues. I had already designed the basic R-S Latch on my own,
but I was not sure if it would really work that way. I had never
actually played much with logic and feedback.

I then was trying to figure out how to latch the trigger pulse and
then also do a reset even if the trigger is still active, and do it
without "manually" (BX-24's manually) holding the reset until the
trigger signal goes low. The logic for this could get complex, I
think.

Anyway, I saw the "pulse detector" in the reference and it solved my
problems completely! I had known that you can use the latency of an
inverter for useful purposes, but had never considered it further.
As you know, but maybe someone else reading this post may not, the
rising edge pulse detector uses 3 inverters (half of a hex inverter
DIP) feeding into an AND gate along with the original signal
itself. The delay in the signal by cascading through 3 inverters
will allow the AND gate to see both inputs high for a brief
moment.

I use this momentary pulse (how long is it? Maybe 3000 nanoseconds
total latency plus capacitance? I could not tell from the
datasheets for sure, and I have no oscilloscope.) from the "pulse
detector" to trigger the latch. The reset signal can then just be
active for a brief moment as well. No need to hold reset for a
while.

It works perfectly in my test setup.

I had also asked about timing issues and Tom had been helpful to me
for this. I decided that I could use a 555 timer circuit set to
give close to 1 hz instead of using the on-board BX-24 timer2. I
can set the 555 to give me something really close to 1hz easily.

This timer plus the pulse coming from the hall effect wheel rotation
detector. Both of these will have their own pulse detector and
latch. The output of the latch is OR'd together and that goes to
the interrupt pin on the BX. When the BX gets the interrupt it
checks both possible sources, services them and resets their
respective latch. When all flags sources are cleared then the
interrupt routine exits.

This ought to work quite well. That is, notwithstanding Tom's
reservations about using the BX-24's own clock to measure split
second timing with adequate granularity and accuracy. The
sufficiency of that will have to be determined! I might have to get
some other high resolution timer or clock for that purpose.

Another post on that question

-Tony

--- In basicx@basi..., "Don Kinzer" <dkinzer@e...> wrote:
>
> --- In basicx@basi..., "arhodes19044" <spamiam@c...> wrote:
> > So, I need to have either the wheel and/or the timer set off the
> > interrupt. But then I need to decide what one (or both) did it.
>
> The external hardware that you need to combine input signals
depends
> on the nature of the signals. Are the levels important or is it
the
> edges.
>
> If both signals are levels, you can use an S-R latch to "capture"
the
> fact that the level of interest has occurred. These are simple to
> make using 2 NAND gates or 2 NOR gates cross connected. Which you
> use depends on the level you're looking for. The NAND form is
> activated by an active low signal, NOR for active high. Here is a
> link showing a NOR S-R latch.
>
> http://www.allaboutcircuits.com/vol_4/chpt_10/2.html
>
> After you set up the two latches, you can then OR the signals
> together and feed the output to pin 11 of the BX. You would
probably
> use a NOR and then use bxPinLow for the WaitForInterrupt() value.
> You also have to feed the output of each S-R latch to a separate
BX
> input. That way, the interrupt task can read each input and
discover
> which input caused the interrupt (perhaps both did). After
> determining which latch(es) are set, you need to reset them in
> preparation for the next cycle. You do this by using two BX
outputs,
> one to each latch, connected to the other of the latches input
(the
> one not being used by your input signal).
>
> If your input signals are edges (instead of levels as just
discussed)
> you probably want to used edge-triggered flip flops (e.g. 74xx109)
> and wire them so that when they receive the edge of interest, they
> get set. As before, you need one and one output per FF to be able
to
> read its state and reset it.




--- In basicx@basi..., "arhodes19044" <spamiam@c...> wrote:
> [...] the rising edge pulse detector uses 3 inverters (half of
> a hex inverter DIP) feeding into an AND gate along with the
> original signal itself. The delay in the signal by cascading
> through 3 inverters will allow the AND gate to see both inputs
> high for a brief moment.
>
> I use this momentary pulse (how long is it? Maybe 3000 nanoseconds
> total latency plus capacitance? I could not tell from the
> datasheets for sure, and I have no oscilloscope.) from the "pulse
> detector" to trigger the latch.

The pulse width for a circuit like this is going to be equal to
approximately N times the propagation delay for the inverter, where N
is the number of inverters in series. You didn't mention which
technology you're using but as an example, the prop delay for a
74HCT04 is given in the datasheet as 9ns typical and 17ns maximum at
Vcc=4.5V and 25*C ambient temperature. The prop delay will rise with
temperature and will vary from package to package but will be nearly
identical among the gates in a single package.

Although it requires a few more components, a better solution to
generate a pulse is to use a monostable multivibrator (also called a
one-shot) like the 74HCT123. There are two of these per package and
you set the output pulse width with one resistor and one capacitor.
You can trigger them with either a rising edge or a falling edge and,
depending on your needs, you can arrange to re-trigger them (to extend
a pulse) or terminate a pulse early. One other advantage is that the
'123 has Schmitt-trigger inputs giving you better noise immunity.

I have drawn up a quick schematic showing how to use a '123 with a
'109 to create two positive edge triggered latches with manual reset.
You can get the image at
http://www.kinzers.com/don/BX24/pulseCapture.jpg

Depending on the trigger signals, you may be able to omit the
one-shots and clock the flip-flops directly. They are positive edge
triggered. The flip-flops are wired so that when they are clocked the
Q output will go high and stay high until an active low signal is
applied to the respective clear input.

Don



--- In basicx@basi..., "Don Kinzer" <dkinzer@e...> wrote:
> [...] the '123 has Schmitt-trigger inputs giving you better
> noise immunity.

Speaking of Schmitt inputs, I have often found it beneficial to
condition input signals by running them through a 74HCT14. These are
regular inverters that have Schmitt trigger inputs.

With a regular inverter, if you feed it a signal with a slow
transition time from logic 0 to logic 1 or vice versa, the output may
toggle several times as the input signal is passing through the region
between the guaranteed high and guaranteed low input levels. The
Schmitt inputs prevent this problem.

Don



A schmitt trigger. I can do that.

The clock pulse coming off the 555 timer probably has a reasonably
fast rise time.

I have no idea about the hall effect sensor on the axle. Sometimes I
would just KILL for an oscilloscope.

Do you have any idea about the waveform from a hall effect sensor? I
bet it depends on the sensor. I do not know the specifics of the one
I have except to say it needs power/ground and an output wire.

I figured I would Have to do some signal conditioning and that might
also provide some gain to "square-up" the signal.

-Tony

--- In basicx@basi..., "Don Kinzer" <dkinzer@e...> wrote:
>
> --- In basicx@basi..., "Don Kinzer" <dkinzer@e...> wrote:
> > [...] the '123 has Schmitt-trigger inputs giving you better
> > noise immunity.
>
> Speaking of Schmitt inputs, I have often found it beneficial to
> condition input signals by running them through a 74HCT14. These are
> regular inverters that have Schmitt trigger inputs.
>
> With a regular inverter, if you feed it a signal with a slow
> transition time from logic 0 to logic 1 or vice versa, the output may
> toggle several times as the input signal is passing through the
region
> between the guaranteed high and guaranteed low input levels. The
> Schmitt inputs prevent this problem.
>
> Don