16
\$\begingroup\$

I designed a small sensor PCB for my master thesis with an ATtiny44 microcontroller. I need about 200 of these boards for my application and 16 are always locally connected to controller board. The whole network looks like this:

Enter image description here

To communicate between the controller and the sensor boards I wrote my own 1 pin bus (timing based). The only problem is the sensor board must have an address to know its location in the network, when I send its data to the controller board.

As I only had 1 pin left on the ATtiny I came up with a jumper based DAC circuit which should generate an analog voltage based on the setting of four jumpers. As the sensor circuitry uses the values (47, 470, 1k, 3k, 4k7, 10k, 100k, and 220k) and I wanted to optimize for production I used the below values for the DAC (basically 100k, 50k, 20k, and 10k). Which should give me a nice value between 0 V and 760 mV based on the jumper setting. Exactly what I needed to read as an analog voltage with the internal 1.1 V reference of the ATtiny. On start-up the ATtiny reads this voltage and should know its position.

schematic

simulate this circuit – Schematic created using CircuitLab

In theory this works fine. I even did a Monte Carlo analysis in LTspice to confirm I get no overlapping areas, when considering the tolerance of the resistors (all are 1% BTW). Below you can find the pictures of this analysis.

Enter image description here Enter image description here

Now I produced several (luckily not 200) of these boards and yet some failed to get correct readings on their address (specially in the higher address regions where all tolerances come to play at once). I measured all possible solutions and finally figured out my problem. My original analysis did not include the the tolerance of the 5 V supply voltage, which is locally generated from 12 V with an MC7805 on each controller board. Per datasheet, the MC7805 has an output voltage between 4.8 and 5.2 V.

After I figured this out I modified the Monte Carlo analysis. It now looks like this:

Enter image description here Enter image description here

As you can see there are nice overlapping areas, where I can not definitely say this voltage can only mean this address. Basically all addresses starting with no. 8 can get a false reading (with higher possibilities for false readings for higher addresses).

I would not like to add different resistor values than the one already used on the board (as for the thesis I want to optimize for production).

I would not like to add a voltage reference (e.g, Zener diode) to feed the DAC resistor network.

I cannot modify the controller board any more (and use there a more precise voltage regulator).

I can still modify the PCB design / schematic of the sensor board!

How can I make sure to get always correct readings on the address (either by program or by changing the circuit)?

\$\endgroup\$
  • 3
    \$\begingroup\$ +1 Nice question. Can you provide the last LTspice asc file in a pastebin somewhere? So we can test other combinations? \$\endgroup\$ – dim Jun 14 '16 at 14:54
  • 2
    \$\begingroup\$ Great question, nice work on figuring out what actually caused it before asking for guidance here. Now the question and answer are a good read for anyone passing by instead of just you :-) \$\endgroup\$ – Mast Jun 15 '16 at 9:01
19
\$\begingroup\$

According to your simulations, your addressing scheme works fine as long as only uncertainties in resistor values are considered. It's the uncertainty on the voltage that makes it fail.

My advice is to cancel out the fluctuations on VCC by using it as a reference to the ADC. You can do so by programming the REFS bits in the ADMUX register, as explained in the datasheet:

enter image description here

Once you switch to VCC as a reference voltage for ADC, you will not be measuring voltage anymore, but a ratio between resistor values, and those are precise to 1%. No changes are required in the schematic (though you may want to increase the value of R7 to get your measurements in the middle of ADC's conversion range), only the firmware of Attiny has to be updated.

If you're still willing to rework the sensor board, you can replace your schematic by an R-2R ladder as Cano64 suggested:

schematic

simulate this circuit – Schematic created using CircuitLab

This will optimize the resolution by making all steps in the ladder equal. 1% resistors are precise enough to build monotonic ladders of up to 5 bits.

\$\endgroup\$
  • \$\begingroup\$ Doh! I didn't see the forrest for the trees. I was so fixated on that 1.1V... Thanks a lot! I will try that. \$\endgroup\$ – KarlKarlsom Jun 15 '16 at 11:05
  • 1
    \$\begingroup\$ Tested it and it works. Great! \$\endgroup\$ – KarlKarlsom Jun 15 '16 at 13:39
  • \$\begingroup\$ I tested it with VCC as AREF and a 220k resistor for R7. I might later try and simulate 100k, 220k R-2R ladder and see if it gives me even better results. Thanks again! \$\endgroup\$ – KarlKarlsom Jun 15 '16 at 13:45
3
\$\begingroup\$

I had to solve a similar problem once. I needed to connect 4 buttons to one analog pin on arduino, however I needed to recognize simultaneous presses (all combinations). I came up with the same circuit as you, then I wrote a program to search all possible resistor value combinations so the final values when you press the buttons, are as much apart as possible. Guess what? We are screwed, it cannot be done. That's it, have a nice day.

I learned that the optimal resistor values for switches are close to R, 2R, 4R, 8R and the bottom part of the divider has a value of R. Your circuit is already close to the optimal one, you just need to replace R7 with 10k resistor.

But there is a good news for you. Since you just need to set an address (you won't operate the switch while the device is running) I recommend to use SPDT switches and R2R ladder instead.

\$\endgroup\$
  • \$\begingroup\$ Why couldn't it be done? What happened when you connected your switches to (R, 2R, 4R, 8R) resistors? What combinations didn't work? \$\endgroup\$ – Dmitry Grigoryev Jun 15 '16 at 8:19
  • \$\begingroup\$ R-2R ladder is an excellent suggestion by the way! \$\endgroup\$ – Dmitry Grigoryev Jun 15 '16 at 8:53
  • \$\begingroup\$ +Dmitry I meant same of the output voltages are too close to distinguish them reliably. \$\endgroup\$ – Cano64 Jun 15 '16 at 13:50

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.