Slide 1: Analogue to Digital Conversion
Analogue to Digital Conversion
Lecture 12
Uli Raich
UCC semester 2017/2017
Slide 2: Analogue to Digital Conversion Printed Circuit Boards
In our sensor kit we have 2 different small printed circuit boards
with
Analogue to
Digital
Converters (ADCs) on board:
- The PCF8591 4 channel, 8 bit successive approximation ADC
- The ADS1115 4 channel 16b bit ΣΔ ADC
As you can already see here, different techniques
(successive approximation and ΣΔ) are used.
Both devices use the
I2C interface and are rather slow.
Slide 3: The MCP3004 ADC
In my treasure box I also have a few mcp3004 ADC chips,
which are 10 bit converters providing sampling rates of up to
200ksps (kilo samples per second)
These devices use the SPI interface which will not be explained in this course.
However, you are invited to read the data sheet and to try them.
If you want to play on higher frequency ADCs, then we have a
48 MHz ADC, which is employed in the Hantek 6022BE DSO
(
Digital
Storage
Oscilloscope)
Today we have 14 bit ADCs with sampling rate in the GHz range.
Slide 4: The PCF8591
Why do we use the PCF8591 ADC, which is the device with
the worst characteristics?
- Only 8 bit resolution
- Conversion rate determined by I2C bus frequency (100 kbps)
- Has four multiplexed input channels
- Has one 8 bit DAC channel
Slide 5: Reasons to use the PCF8591
- We do not need a high precision or super fast AD conversion,
which gives us a resolution of better than 1/2 % full range
- We are only interested to understand the principle of A to D conversion
- Having analogue devices on the PCB allowing us
to test our setup is and important asset
Slide 6: The YL-40 board
Slide 7: Problems with the YL-40 board
There were 2 problems with the YL-40 board I bought from China:
- The connection of one end of the thermistor to ground was
missing and had to be added by soldering a short connection.
- The DAC output does not reach Vdd of full scale because
the LED connected to it draws too much current.
Slide 8: The YL-40 board (2)
Slide 9: YL-40 corrected
Slide 10: YL-40 devices
As we can see from the photos and from the circuit diagrams,
the YL-40 has already 3 devices that can be connected
to the PCF8591 inputs through jumpers:
- a photo resistor (AIN0)
- a thermistor (AIN1)
- a potentiometer (AIN3)
AIN2 is unused and can be connected to the DAC output
The potentiometer is particularly useful as any change in resistivity
created when turning it, can immediately be observed on the
ADC values read back from the board.
Slide 11: The PCF8591 block diagram
Slide 12: Successive Approximation
Set the DAC value to Vcc/2 (½ of 0-Vcc interval)
and compare with analogue signal level
If signal level > DAC, set bit 7 to 1 and set DAC level to ¾ Vcc
else set bit 7 to 0 and set DAC level to ¼ Vcc
If signal level > DAC level set bit 6 to 1 and
set DAC level to ½ of the upper interval
else
set bit 6 to 0 and DAC leve to ½ of lower interval
After 8 approximations we have the converted 8 bit value
Slide 13: The PCF8591 control byte
Slide 14: An include file to describe the ADC
Slide 15: Reading the ADC
Once you have initialized the pigpio library with
and opened the
I2C bus with
you must set the control byte:
- controlByte =PCF8591_CHANNEL_C | PCF8591_4_SINGLE_ENDED;
i2c_write_byte(pi,handle,controlByte;
You can read the channel:
- adcValue=i2c_read_byte(pi,handle);
Slide 16: A bit more C programming
Students typically have problems with
- Pointers
- Parameter passing
Therefore I tried to write a few demo programs
to show how to use these correctly
Slide 17: Pointers
Slide 18: De-reference pointers
Slide 19: Change in pointer value after the loop
What has happened to the pointer during the loop?
It has advanced and now points to the zero string terminator.
Subtracting the old value (hello) from the
new helloPtr value yields the string length
Slide 20: Printing the remaining string
If instead of printing the character pointed to by the helloPtr wit "%c"
we print the (remaining) string with "%s"
this is what we will see:
Here is the source code of the example programs:
https://afnog.iotworkshop.africa/pub/Embedded_Systems/Lecture12:AnalogueToDigitalConversion/pointers.tar.gz
--
Uli Raich - 2017-11-21
Comments