Difference: Lecture12:AnalogueToDigitalConversion (1 vs. 2)

Revision 22017-11-23 - uli

Line: 1 to 1
 
META TOPICPARENT name="LectureSlides"

Start Presentation

Slide 1: Analogue to Digital Conversion

Line: 139 to 139
 
  • pigpio_start
and opened the I2C bus with

  • i2c_open
Changed:
<
<
you must set the control byte:

ControlByte =PCF8591:CHANNEL_C PCF8591_4_SINGLE_ENDED;

  • i2c_write_byte(pi,handle,controlByte;
>
>
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:

Changed:
<
<
  • adcValue=i2c_read(pi,handle);
>
>
  • adcValue=i2c_read_byte(pi,handle);
 

A bit more C programming

Line: 197 to 195
  remainRes.png
Added:
>
>
Here is the source code of the example programs:

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

 %SLIDESHOWEND%

-- Uli Raich - 2017-11-21

Line: 224 to 226
 
META FILEATTACHMENT attachment="pcf8591backcorrected.png" attr="" comment="" date="1511251948" name="pcf8591backcorrected.png" path="pcf8591backcorrected.png" size="783488" user="uli" version="1"
META FILEATTACHMENT attachment="pointerLoop.png" attr="" comment="" date="1511254117" name="pointerLoop.png" path="pointerLoop.png" size="5995" user="uli" version="1"
META FILEATTACHMENT attachment="stringLoop.png" attr="" comment="" date="1511254425" name="stringLoop.png" path="stringLoop.png" size="5775" user="uli" version="1"
Added:
>
>
META FILEATTACHMENT attachment="pointers.tar.gz" attr="" comment="" date="1511452093" name="pointers.tar.gz" path="pointers.tar.gz" size="7091" user="uli" version="1"

Revision 12017-11-21 - uli

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="LectureSlides"

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(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

-- Uli Raich - 2017-11-21

Comments

<--/commentPlugin-->

META FILEATTACHMENT attachment="controlByte.png" attr="" comment="" date="1511251536" name="controlByte.png" path="controlByte.png" size="34611" user="uli" version="1"
META FILEATTACHMENT attachment="dereference.png" attr="" comment="" date="1511251536" name="dereference.png" path="dereference.png" size="43097" user="uli" version="1"
META FILEATTACHMENT attachment="derefRes.png" attr="" comment="" date="1511251536" name="derefRes.png" path="derefRes.png" size="42596" user="uli" version="1"
META FILEATTACHMENT attachment="includeFile.png" attr="" comment="" date="1511251536" name="includeFile.png" path="includeFile.png" size="43467" user="uli" version="1"
META FILEATTACHMENT attachment="pcf8591BlockDiag.png" attr="" comment="" date="1511251536" name="pcf8591BlockDiag.png" path="pcf8591BlockDiag.png" size="36109" user="uli" version="1"
META FILEATTACHMENT attachment="pointer_assignment.png" attr="" comment="" date="1511251536" name="pointer_assignment.png" path="pointer_assignment.png" size="13727" user="uli" version="1"
META FILEATTACHMENT attachment="pointerVal.png" attr="" comment="" date="1511251536" name="pointerVal.png" path="pointerVal.png" size="10480" user="uli" version="1"
META FILEATTACHMENT attachment="pot.png" attr="" comment="" date="1511251536" name="pot.png" path="pot.png" size="6828" user="uli" version="1"
META FILEATTACHMENT attachment="remain.png" attr="" comment="" date="1511251582" name="remain.png" path="remain.png" size="5775" user="uli" version="1"
META FILEATTACHMENT attachment="remainRes.png" attr="" comment="" date="1511251582" name="remainRes.png" path="remainRes.png" size="4740" user="uli" version="1"
META FILEATTACHMENT attachment="Screenshot_from_2017-11-14_12-11-57.png" attr="" comment="" date="1511251583" name="Screenshot_from_2017-11-14_12-11-57.png" path="Screenshot_from_2017-11-14_12-11-57.png" size="220150" user="uli" version="1"
META FILEATTACHMENT attachment="strlen.png" attr="" comment="" date="1511251583" name="strlen.png" path="strlen.png" size="10350" user="uli" version="1"
META FILEATTACHMENT attachment="successiveAppr.png" attr="" comment="" date="1511251583" name="successiveAppr.png" path="successiveAppr.png" size="6991" user="uli" version="1"
META FILEATTACHMENT attachment="updatePtr.png" attr="" comment="" date="1511251583" name="updatePtr.png" path="updatePtr.png" size="5995" user="uli" version="1"
META FILEATTACHMENT attachment="yl-40.png" attr="" comment="" date="1511251664" name="yl-40.png" path="yl-40.png" size="220150" user="uli" version="1"
META FILEATTACHMENT attachment="pcf8591.png" attr="" comment="" date="1511251946" name="pcf8591.png" path="pcf8591.png" size="214742" user="uli" version="1"
META FILEATTACHMENT attachment="pcf8591backcorrected.png" attr="" comment="" date="1511251948" name="pcf8591backcorrected.png" path="pcf8591backcorrected.png" size="783488" user="uli" version="1"
META FILEATTACHMENT attachment="pointerLoop.png" attr="" comment="" date="1511254117" name="pointerLoop.png" path="pointerLoop.png" size="5995" user="uli" version="1"
META FILEATTACHMENT attachment="stringLoop.png" attr="" comment="" date="1511254425" name="stringLoop.png" path="stringLoop.png" size="5775" user="uli" version="1"
 
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