0
\$\begingroup\$

I am trying to read data from a circuit I created recently. But I do not understand if there's something I have missed in the same, since everytime I read data on my microprocessor, it always tells me that all inputs are LOW. I am using few opto-couplers PC817 for reading signals that are in terms of 24VDC.

I tested the optocouplers after activating them and it is working as expected, however I read nothing on the 165's. To test, I supplied 24v to one of my opto-couplers, and on the output I could read a resistance (using a multimeter) of 122 ohm when active.

I can share the code (Arduino - C) if needed, but I think this is more related to circuit/connections not the code.

Below is my circuit diagram.

enter image description here

Note: I have shown 4xPC817 optocouplers and 2x74HC165 in daisy chain configuration (to keep schematic simple). But I have 3 such 74HC165 and all data input pins have one optocoupler connected, so it means there are 24 such opto-coupler.

Update

I checked the voltages and below are the numbers on testing:

  • Between optocoupler Pin 1 and 2 - 1.14 VDC (Resistance 122 ohm)
  • (Active) Between 74HC165 Pin GNT and Data Input Pin - 0.02 VDC
  • (Inactive) Between 74HC165 Pin GND and Data Input Pins - 4.02 VDC
\$\endgroup\$
15
  • 1
    \$\begingroup\$ S1,2,.. need about >=10k pullup not down and not less R \$\endgroup\$ Mar 14 '21 at 14:40
  • \$\begingroup\$ I think I have attached them on the 74HC165s - those are 10K. \$\endgroup\$ Mar 14 '21 at 14:42
  • \$\begingroup\$ @TonyStewartSunnyskyguyEE75, can you please elaborate (maybe add as answer)? I have added 10K resistors and connected all of them to 5v. From what I understand (please correct me if I'm wrong), these work as pull-ups? \$\endgroup\$ Mar 14 '21 at 14:51
  • 1
    \$\begingroup\$ "however I read nothing on the 165's" - in digital logic 'nothing' means tristate or open-circuit. Do you mean it's stuck at one logic level (0 or1)? What voltages do you read on PL and CP when they are high? \$\endgroup\$ Mar 14 '21 at 16:29
  • 1
    \$\begingroup\$ So which ESP32 model is it? I highly doubt it has 5V IO. \$\endgroup\$
    – Justme
    Mar 14 '21 at 16:49
0
\$\begingroup\$

Check the inputs D4..7 with a voltmeter. Then you can see if your circuits is working or your software is wrong.

\$\endgroup\$
0
\$\begingroup\$

The usual method of debugging is Check the input after error in output and measure intermediate voltage states for valid logic then move in the direction of the error to isolate the fault. CE, CP? Or IN off current.

\$\endgroup\$
1
  • \$\begingroup\$ Have added voltage potentials after testing, in above question, it that helps. \$\endgroup\$ Mar 17 '21 at 13:51
0
\$\begingroup\$

Finally the above comments and answers helped with the solution. Credits to all!

Isolating the issues and taking them one by one helped me figure out the issue.

Seems like some random optocouplers are messed up and somehow I ended up testing on those.

The hardware is completely fine. I am able to read data from most optos.

Adding software code below, just in case it helps someone, with a similar issue.

// Code taken from: https://playground.arduino.cc/Code/ShiftRegSN74HC165N/
#define NUMBER_OF_SHIFT_CHIPS   3
#define DATA_WIDTH   NUMBER_OF_SHIFT_CHIPS * 8
#define PULSE_WIDTH_USEC   5
#define POLL_DELAY_MSEC   1
#define BYTES_VAL_T unsigned int
int ploadPin        = 18;  // Connects to Parallel load pin the 165
int dataPin         = 23; // Connects to the Q7 pin the 165
int clockPin        = 19; // Connects to the Clock pin the 165
BYTES_VAL_T pinValues;
BYTES_VAL_T oldPinValues;

BYTES_VAL_T read_shift_regs()
{
    long bitVal;
    BYTES_VAL_T bytesVal = 0;
    digitalWrite(ploadPin, LOW);
    delayMicroseconds(PULSE_WIDTH_USEC);
    digitalWrite(ploadPin, HIGH);
    for(int i = 0; i < DATA_WIDTH; i++)
    {
        bitVal = digitalRead(dataPin);
        bytesVal |= (bitVal << ((DATA_WIDTH-1) - i));
        digitalWrite(clockPin, HIGH);
        delayMicroseconds(PULSE_WIDTH_USEC);
        digitalWrite(clockPin, LOW);
    }
    return(bytesVal);
}
void display_pin_values()
{
    Serial.print("Pin States:\r\n");
    for(int i = 0; i < DATA_WIDTH; i++)
    {
        Serial.print("  Pin-");
        Serial.print(i);
        Serial.print(": ");
        if((pinValues >> i) & 1)
            Serial.print("HIGH");
        else
            Serial.print("LOW");
        Serial.print("\r\n");
    }
    Serial.print("\r\n");
}

void setup()
{
    Serial.begin(115200);
    pinMode(ploadPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, INPUT);
    digitalWrite(clockPin, LOW);
    digitalWrite(ploadPin, HIGH);
    pinValues = read_shift_regs();
    display_pin_values();
    oldPinValues = pinValues;
}

void loop()
{
    pinValues = read_shift_regs();
    display_pin_values();
    delay(POLL_DELAY_MSEC);
    delay(2000);
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.