Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are facing a fundamental problem: an ISR is called with no data. In other words, the ISR function is not provided any data that indicates its source of the interrupt. </p> <p>The basic approach is that the person writing the code provides the linkage between input and action by hardcoding a function. The tricky approach you are looking for is a method by which the ISR can figure out what the source was.</p> <p>So you want to have N motors with 2N inputs from quadrature encoders. A single interrupt handler is attached to all the input pins on a CHANGE condition. The same handler gets called for all N motors. It can figure out which Motor to update by comparing the input pins to the values the last time it was called. If the input pins changed, then call that motor. Here is a psuedo code</p> <pre><code>Motor motor1; Motor motor2; onSomethingChanged() { static int in1aprev, in1bprev; static int in2aprev, in2bprev; int in1a, in1b; int in2a, in2b; in1a = digitalRead(.... same for other in's if( (in1a!=in1alast) || (in1b!=in1blast)) { motor1.encoderInput(in1a,in1b); in1alast = in1a; in1blast = in1b; } if( (in2a!=in2alast) || (in2b!=in1blast)) { motor2.encoderInput(in2a,in2b); in1a2ast = in2a; in1b2ast = in2b; } return; } </code></pre> <p>Not so long ago this type of function would be handled in an entire chip (see <a href="http://en.wikipedia.org/wiki/Intel_8259" rel="nofollow">programmable interrupt controller</a> ). The chip implements all the logic to trigger and capture the source of the interrupt. The main CPU just gets a trigger "something happened". The handler polls the chip to ask "what happened".</p> <p>Having offered this method, I'm not sure I would recommend. You cannot <strong>hide</strong> what is going on with your code. The motor must be physically wired to the correct pins. You have consumed a scarce resource -- you have to tell people.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload