Analog inputs

From BitWizard WIKI
Jump to: navigation, search

Analog inputs

Several boards can be configured to use analog inputs. The registers 0x70-0x78 specify the value for the multiplexer register in the ADC module of the used chip. The value is not santiy checked. Any value you specify will be used. It is not expected that things will break if you send a value that is not documented here, but why risk it?

Reference

The top two bits specify the reference. Possible values are:

0x80: internal 1.1V 0x00: 5V (or 3.3V) powersupply line.

Other values are not applicable (0x40 = use aref pin, which is connected elsewhere on the bitwizard boards, 0xc0 is "reserved").

Normal measurements

Normal measurements would return a value of 0 for 0V up to 1023 for the reference value.

value dio pin temp thermo
0x00 6 S2 T4
0x01 4 S1 T3
0x02 3 S3 T2
0x03 1 S4 T1
0x07 0 - -


The values 4, 5 and 6 would measure analog values on the pins required for I2C or SPI communication. Interesting to do once, but not particularly useful. These values are added to the "reference selection" value in the previous section.

There are also some special values internal to the chip:

value what
0x20 AGND
0x21 1.1V reference
0x22 temp sensor

You should get "about 0" if you use mux value 0x20. Maybe this can be used to measure the offset of the ADC module. By measuring the 1.1V reference with the power rails as the reference, you can get a measurement of the power supply value.

The temp sensor should give you the temperature in C with about 275 added. The datasheet mentions a typical value of 300 at 25C. The coefficient is documented as "close to 1.0", but a few lines up it is documented (indirectly) as "typically 1.077". The offset is apparently quite variable. So don't count on any absolute accuracy. You'll need to calibrate the offset if you want any kind of accuracy. (If the real temp is 21 degrees (comfortable), the reading could easily end up at 16 or 26, which are clearly too cold and too hot for comfort).

Differential measurements

Differential measurements use one pin as the positive input and another as the negative. In the bitwizard boards only "single sided" measurements are supported. This means that if your signal can go both ways, you have to switch to the other polarity once your measured value is below a certain value. Note that you cannot count on the value becoming zero if the polarity reverses. There will always be a little bit of noise resulting in non-zero ADC conversions even if the input polarity is reversed. You could also request both conversion values, and decide what to do with them in your software. The hardware does not support all combinations. So it might be possible that sometimes you cannot measure a polarity. Casual inspection shows that this does not happen in the subset of inputs available on the bitwizard boards.

In the table below you'll see for instance 6-4 in the dio column, this means that the ADC value represents the voltage of dio pin 6 minus dio pin 4.

This table was difficult to figure out.... It may still contain errors. Please report them if you see one.

value dio pins temp thermo
0x08 6 - 4 S2 - S1 T4 - T3 *
0x0a 6 - 1 S2 - S4 T4 - T1
0x28 4 - 6 S1 - S2 T3 - T4 *
0x0c 4 - 3 S1 - S3 T3 - T2
0x0e 4 - 1 S1 - S4 T3 - T1
0x2c 3 - 4 S3 - S1 T2 - T3
0x10 3 - 1 S3 - S4 T2 - T1 *
0x2a 1 - 6 S4 - S2 T1 - T4
0x2e 1 - 4 S4 - S1 T1 - T3
0x30 1 - 3 S4 - S3 T1 - T2 *
0x24 1 - 1 S4 - S4 T1 - T1
0x18 1 - 0 - -
0x38 0 - 1 - -
0x26 0 - 0 - -

Thermo lines marked with the asterisk are the intended use for the thermocouple board.

Hmm. Maybe a different table is more useful / easier to read in our application. Let me try this:

DIO6
S2
T4
DIO4
S1
T3
DIO 3
S3
T2
DIO 1
S4
T1
DIO 0
DIO6
S2 T4
0x22* 0x08 - 0x0a -
DIO4
S1 T3
0x28 - 0x0c 0x0e -
DIO3
S3 T2
- 0x2c - 0x10 -
DIO1
S4 T1
0x2a 0x2e 0x30 0x24 0x18
DIO0 - - - 0x38 0x26

The 0x22* value only works in "x20" mode with "1" added as described below.

The "DIO0" indication means IO 0 on the DIO board. In the pinout of the DIO board, you can see that this is pin 3 on the connector. and so on.

The "S1" indication means the "sensor 1" input on the "temp" board (which is the middle pin of the 3-pin connector marked S1).

The rows describe a positive input, the columns a negative one. So row "S1", column "S3" describes the value to use for S1-S3.

Differential x20 measurements

For measuring small differences, there is a x20 gain mode. The measurements are very similar to the above differential measurements, but the analog value is multiplied by 20 before being measured. The datasheet for the chip doesn't clearly describe how accurate the "20" here is.

Add one to the values in the above table to obtain the x20 measurements.

Adding and averaging

By setting a value into the <samples-to-add> register (0x81), you can add samples together. By setting a value in the <number-of-bits-to-shift-the-result> register (0x82) you can divide down (but only by powers of two) to get an average.

Statistics have shown that under certain circumstances, adding a number of samples together will provide a higher resolution than the underlying ADC. In the BitWizard boards, those circumstances are almost always present. One thing to remember is that when you add together say 64 ten-bit samples, you get a 16-bit result. Almost all 16-bit values are possible. However your measurement has not become 16-bits. In practise, you need to average 2^2n samples, to get n more bits of resolution. So to get a full 16-bit result, you need 6 more bits of resolution (n=6), so you need to add 2^12 (4096) samples together.