Arduino input board design problem

Thread Starter

Tom544

Joined Mar 14, 2016
29
I'm in a parking lot, but I would use the Arduino pin change interrupt. In the interrupt service routine, I would use the port manipulation commands to save the status of ALL inputs in one statement. Thus, the ISR is totally minimized and you are unlikely to miss a second change.

If this sounds interesting, I can follow up when I'm out of the car and home.
I like the sounds of this, I did look at port manipulation but didn't understand all of it. How would you set the ISR for the eight inputs? Thanks!
 

djsfantasi

Joined Apr 11, 2010
9,237
That's the part I am the weakest on. Others have suggested links showing how it done. I got it to work. Sometimes. I'll post the code tomorrow if anyone wants to look at it and get it to work. Sorry I couldn't take it further.
 

djsfantasi

Joined Apr 11, 2010
9,237
Ok, here is some non-working test code. You will say, "dj, thanks a lot for the broken code", but it almost does what we want. As it turns out, I was wrong about the technique for detecting change on a PORT (group of selected input pins on the Arduino). I was thinking of something else. But I got this to work some of the time.

Maybe if a couple of use look at it, we can get it to work all of the time. Here is the code:

Code:
// Install Pin change interrupt for a pin, can be called multiple times
volatile int myValues;

int nybble0 = 0;
int nybble1 = 0;
int myPins = 0;

void pciSetup(byte pin) {

  *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
  PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
  PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
}

// Use one Routine to handle each group

ISR (PCINT0_vect) { // handle pin change interrupt for pins 4-7
prevPins = myPins; 
nybble0 = PIND & B00001111;
  nybble1 = (PINB & B00001111) << 5; Serial.println(nybble0);
  myPins = nybble1 | nybble0;
}

ISR (PCINT1_VECT) { // handle pin change interrupt for pins 8-11
  nybble0 = (PIND & B00001111) << 5;
  nybble1 = (PINB & B11110000);
  myPins = nybble0 | nybble1;
}



void setup() {
  int i;

  // set pullups, if necessary
  DDRD = DDRD & B00001111; // sets pins 4 to 7 as input
  DDRB = DDRB & B11110000; // sets pins 8 to 11 as input
  PORTD = ((PORTD & B11110000) | B00001111); // sets pins 4 to 7 to HIGH
  PORTB = ((PORTB & B00001111) | B11110000); // setS PINS 8 to 11 HIGH

  Serial.begin(9600);

  // enable interrupt for pin...
  for (int myPin = 4; myPin <= 11; myPin++) {
    pinMode(myPin, INPUT_PULLUP);
    pciSetup(myPin);
  }
}

void loop() {
  volatile int prevValues = 0;

  Serial.print("Beginning ");
  Serial.print(PORTD, BIN);
  Serial.println(PORTB, BIN);
  while (-1) {
    if (prevValues != myValues) {
      Serial.print(prevValues, BIN);
      Serial.print("\t");
      Serial.println(myValues, BIN);
      prevValues = myValues;
    }
  }
}
Ok, I bricked my UNO when testing this. Accidentally plugged Vcc into the wrong pin. Services to be held tomorrow.

The other thought that came to mind is how simple it is to poll the 8 pins. The following four lines of code does it.
Code:
prevPins = myPins; 
nybble0 = PIND & B00001111;
nybble1 = (PINB & B00001111) << 5; Serial.println(nybble0);
myPins = nybble1 | nybble0;
Note that there is not a contiguous grouping which contains 8 data pins, I used contiguous pins from PORTB and PORTD.

There IS someplace in your code, where you can take a quick peek at the input pins. I wrote an interpretive multitasking language totally on this concept, so feel confident in my statement.
 

Thread Starter

Tom544

Joined Mar 14, 2016
29
I can't determine what you want. Since this post has a couple dozen views and no other replies, it appears I'm not alone.

You say you want to monitor status, but you don't want to poll the inputs. Can you monitor your inputs for rising and falling edges, or is it one or the other?

What are you trying to do with the one shots? When an optocoupler is turned on, it triggers the one shot, but you're clamping the timing cap so the one shot will never time out. Direct coupling the trigger is doing the same thing; the one shot won't time out until the monitored device turns off.



You have the 8 one shot outputs NANDed together. That will give you a HIGH output unless all of the inputs are HIGH. Is that what you want?

When you draw schematics, it's better to show the logic. I had to look up what an 'LS30 was... It seems that the schematic editor you're using emphasizes pin order instead of function. That makes for difficult to read schematics.


It's a bad idea to connect the potentiometers the way you have them. If the pot is inadvertently set to 0 ohms, the transistors will short the supply.
I see I should connect the wiper of the potentiometer to the input 1+2 and Q and I would also add 100 ohm resistor in series with Q emitter. Any other thing? Thanks for the reply!
 
Top