End Presentation


TWiki Slide Show
Next
Analogue to Digital Conversion

Analogue to Digital Conversion

Lecture 12

Uli Raich

UCC semester 2017/2017

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 1 of 20





















TWiki Slide Show
Next
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.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 2 of 20





















TWiki Slide Show
Next
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.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 3 of 20





















TWiki Slide Show
Next
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

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 4 of 20





















TWiki Slide Show
Next
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

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 5 of 20





















TWiki Slide Show
Next
The YL-40 board
yl-40.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 6 of 20





















TWiki Slide Show
Next
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.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 7 of 20





















TWiki Slide Show
Next
The YL-40 board (2)
pcf8591.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 8 of 20





















TWiki Slide Show
Next
YL-40 corrected
pcf8591backcorrected.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 9 of 20





















TWiki Slide Show
Next
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.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 10 of 20





















TWiki Slide Show
Next
The PCF8591 block diagram
pcf8591BlockDiag.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 11 of 20





















TWiki Slide Show
Next
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

successiveAppr.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 12 of 20





















TWiki Slide Show
Next
The PCF8591 control byte
controlByte.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 13 of 20





















TWiki Slide Show
Next
An include file to describe the ADC
includeFile.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 14 of 20





















TWiki Slide Show
Next
Reading the ADC
Once you have initialized the pigpio library with

  • pigpio_start
and opened the I2C bus with

  • i2c_open
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);

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 15 of 20





















TWiki Slide Show
Next
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

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 16 of 20





















TWiki Slide Show
Next
Pointers
pointer_assignment.png

pointerVal.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 17 of 20





















TWiki Slide Show
Next
De-reference pointers
dereference.png

derefRes.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 18 of 20





















TWiki Slide Show
Next
Change in pointer value after the loop
What has happened to the pointer during the loop?

pointerLoop.png

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

strlen.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 19 of 20





















TWiki Slide Show
Next
Printing the remaining string
If instead of printing the character pointed to by the helloPtr wit "%c"

we print the (remaining) string with "%s"

stringLoop.png

this is what we will see:

remainRes.png

Here is the source code of the example programs:

https://afnog.iotworkshop.africa/pub/Embedded_Systems/Lecture12:AnalogueToDigitalConversion/pointers.tar.gz

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 20 of 20





















First slide Previous End Presentation






























-- Uli Raich - 2017-11-21

Comments

I Attachment History Action Size Date Who Comment
PNGpng Screenshot_from_2017-11-14_12-11-57.png r1 manage 215.0 K 2017-11-21 - 08:06 UnknownUser  
PNGpng controlByte.png r1 manage 33.8 K 2017-11-21 - 08:05 UnknownUser  
PNGpng derefRes.png r1 manage 41.6 K 2017-11-21 - 08:05 UnknownUser  
PNGpng dereference.png r1 manage 42.1 K 2017-11-21 - 08:05 UnknownUser  
PNGpng includeFile.png r1 manage 42.4 K 2017-11-21 - 08:05 UnknownUser  
PNGpng pcf8591.png r1 manage 209.7 K 2017-11-21 - 08:12 UnknownUser  
PNGpng pcf8591BlockDiag.png r1 manage 35.3 K 2017-11-21 - 08:05 UnknownUser  
PNGpng pcf8591backcorrected.png r1 manage 765.1 K 2017-11-21 - 08:12 UnknownUser  
PNGpng pointerLoop.png r1 manage 5.9 K 2017-11-21 - 08:48 UnknownUser  
PNGpng pointerVal.png r1 manage 10.2 K 2017-11-21 - 08:05 UnknownUser  
PNGpng pointer_assignment.png r1 manage 13.4 K 2017-11-21 - 08:05 UnknownUser  
Unknown file formatgz pointers.tar.gz r1 manage 6.9 K 2017-11-23 - 15:48 UnknownUser  
PNGpng pot.png r1 manage 6.7 K 2017-11-21 - 08:05 UnknownUser  
PNGpng remain.png r1 manage 5.6 K 2017-11-21 - 08:06 UnknownUser  
PNGpng remainRes.png r1 manage 4.6 K 2017-11-21 - 08:06 UnknownUser  
PNGpng stringLoop.png r1 manage 5.6 K 2017-11-21 - 08:53 UnknownUser  
PNGpng strlen.png r1 manage 10.1 K 2017-11-21 - 08:06 UnknownUser  
PNGpng successiveAppr.png r1 manage 6.8 K 2017-11-21 - 08:06 UnknownUser  
PNGpng updatePtr.png r1 manage 5.9 K 2017-11-21 - 08:06 UnknownUser  
PNGpng yl-40.png r1 manage 215.0 K 2017-11-21 - 08:07 UnknownUser  

This topic: Embedded_Systems > WebHome > LectureSlides > Lecture12:AnalogueToDigitalConversion
Topic revision: r2 - 2017-11-23 - uli
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback