Tags:
create new tag
view all tags
Start Presentation

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

yl-40.png

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)

pcf8591.png

Slide 9: YL-40 corrected

pcf8591backcorrected.png

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

pcf8591BlockDiag.png

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

successiveAppr.png

Slide 13: The PCF8591 control byte

controlByte.png

Slide 14: An include file to describe the ADC

includeFile.png

Slide 15: 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);

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

pointer_assignment.png

pointerVal.png

Slide 18: De-reference pointers

dereference.png

derefRes.png

Slide 19: 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

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"

stringLoop.png

this is what we will see:

remainRes.png

Here is the source code of the example programs:

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

-- Uli Raich - 2017-11-21

Comments

Topic attachments
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  
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
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