1

I have a board, which is the host for several different sensors. All sensors have the same 4 pin plug with the following pin-out:

  1. Pin: VDD
  2. Pin: Signal
  3. Pin: Free
  4. Pin: VSS

Means, I got 1 free pin, on each plug.

All plugs / sensors should be interchangeable and the MCU should be able to determine, which sensor is plugged in.

My MCU, does not have enough analog pins left, otherwise I could so something like put a voltage divider on each board and read the analog value.

I have still enough digital pins left.

I would like to be able to determine at least 20 different kinds of sensors, better 32.

Is there a neat little trick, to achieve this?


Some other SE questions, that are on a similar topic, but did not solve my issue:

What is a good way for the mcu to determine which hardware version it is running on?

Encoding version or configuration on PCB

KarlKarlsom
  • 1,792
  • 2
  • 13
  • 26

3 Answers3

4

Dallas 1wire memory or Very small microcontroller or RC circuit. Measure charge/discharge time. Set pin low for X time to discharge. Set pin hi for Y time. Make pin input - test state. Rinse and repeat until high. Then do the same in reverse - charge hi, then discharge whilst testing the pin. Based on the time for charge/discharge gives you a value.

Kartman
  • 5,930
  • 2
  • 6
  • 13
  • 1
    Note: the 1wire memory is probably the ‘best’ in terms of ease and simplicity but be aware that it can get a bit picky if there are other digital signals in the cable. The RC method would be unreliable with random lengths of cable due to cable capacitance and interference. – Kartman Apr 07 '21 at 04:45
  • 1 wire memory is a good idea. Would they have to be programmed by me, or can you get with a defined value? – KarlKarlsom Apr 08 '21 at 04:58
  • You can get them with unique ids or memory that you can program. There’s even an adc and a temperature sensor. Also multiple devices can exist on the one wire. – Kartman Apr 08 '21 at 05:42
1

The voltage divider is still the simplest option. You only need one resistor on each sensor board, the second resistor is on the main.

Just because you have no available ADC inputs does not mean you cannot use it. There are hundreds of ADC chips available in tiny 5/6-pin packages, like ADC081S021 with SPI interface or MCP3021 with I2C interface. They also use supply as a reference, which makes them ideal to read voltage dividers.

I'd go with SPI because it does not need pull-ups. Unless you already use I2C on board, in which case you won't even need any additional MCU pins.

We actually use this method for setting CANOpen node IDs. The carrier boards have resistors and when we plug MCU board into carrier the application can easily find out its ID. The resistors calculated in such a way that simple dividing of ADC value by some constant produces actual ID. If same carrier board can be used for nodes with different IDs we put DIP switches on them to easily change resistance without soldering.

Alternatives

You did not specify what kind of "signal" you have. But if you design sensors yourself you have multiple options available for you. Some examples:

  • If your interface is digital you can add "sensor type" data to your protocol;
  • if your interface is analog you can add simple multiplexor controlled by the free pin - if the pin is high the "signal" is sensor output, if the pin is low then the "signal" is sensor type encoded as voltage from divider on board.
Maple
  • 11,755
  • 2
  • 20
  • 56
0

Kartman provided a good answer, but there is also another simple way.

  • Capacitance, work but fairly complex to implement and reliability might not be the best.
  • EEPROM is good, but then you need to program all of them, which is time-consuming.

A simpler way in my opinion, if your pin has an ADC (most MCU has), is to simply do different voltage dividers between VCC and GND, and sense the voltage on the pin. You simply need 2 resistors and change them for different hardware versions to have different voltage output, for instance, 0.5V steps.

The cost is low and you can visually see what is ID "programmed" aka which resistors are soldered.

Damien
  • 7,827
  • 1
  • 12
  • 29