Difference: Lecture10:DigitalToAnalogueConversion (4 vs. 5)

Revision 52017-11-06 - uli

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

Start Presentation

Changed:
<
<
>
>

Digital to Analogue Conversion

 

Digital to Analogue Conversion:

the mcp4275

Lecture 10

Uli Raich

UCC semester 2017/2018

Line: 11 to 11
 
  • on/off for the LEDs
  • on/off to read the LED state
  • Powering or not powering coils to generate magnetic fields in a stepping motor
Changed:
<
<
However:
The world is mostly analogue:
>
>
However:

The world is mostly analogue:
 
  • Temperatures are changing continuously and not in steps
  • Pressure is an analogue value
  • Distance, time, current, resistance … are all analogue values
Line: 19 to 19
 

Converting from digital to analogue

Changed:
<
<
Since our computer is a digital device we must
  • Convert digital values to analogue voltage levels
    Digital to Analogue Conversion (DAC)
>
>
Since our computer is a digital device we must

  • Convert digital values to analogue voltage levels
    Digital to Analogue Conversion (DAC)

 
  • … and we must convert external analogue values to digital
    Analogue to Digital Conversion (ADC)

Digital to analogue conversion

Changed:
<
<
A digital to analogue converter does not really convert into a continuous waveform
Since we have digital values as a base, there will be steps in the output waveform
The size of these steps depends on the resolution of the DAC
What is the smallest step a 12 bit DAC can produce on a 0..5V scale?
>
>
A digital to analogue converter does not really convert into a continuous waveform

Since we have digital values as a base, there will be steps in the output waveform

The size of these steps depends on the resolution of the DAC

What is the smallest step a 12 bit DAC can produce on a 0..5V scale?
 

Can we smooth the output signal?

Line: 55 to 55
  have a look at this excellent tutorial, from which I have copied the above illustration.
Added:
>
>

 

The MCP4725 12 bit DAC

Changed:
<
<
As a demo device we bought the MCP4725 DAC
This is a 12 bit DAC which can be accesses by the I2C bus
Here is its data sheet
>
>
As a demo device we bought the MCP4725 DAC

This is a 12 bit DAC which can be accesses by the I2C bus

Here is its data sheet
  and here a photo of the device

dac_front.png

Changed:
<
<

The I2C bus

>
>

The I2C bus

  The I2C bus is an industrial standard 2 wire bus using a data (SDA) and a clock (SCL) line.
Line: 97 to 98
 thus creating a short circuit.

Changed:
<
<

I2C Master and slave

>
>

I2C Master and slave

  The I2C bus has at least one master (in our case the interface in the

Raspberry Pi’s ARM processor) and several slaves

We have the following I2C slave devices:

Changed:
<
<
  • mcp4275 DAC
  • bmp180 barometric pressure sensor
  • pcf8581 8 bit ADC
  • ads115 16 bit ADC
  • at24c32 eeprom
  • ds1307 real time clock
  • mma845x accelerometer
>
>
  • mcp4275 DAC

  • bmp180 barometric pressure sensor

  • pcf8581 8 bit ADC

  • ads115 16 bit ADC

  • at24c32 eeprom

  • ds1307 real time clock

  • mma845x accelerometer

 
  • pcf8574 I/O expander used on the 2-line LCD display

Changed:
<
<

I2C addressing

>
>

I2C addressing

  Since there can be several slaves on the bus there must
Line: 128 to 129
 user to have several devices of the same type on the bus

Changed:
<
<

I2C buses and I2C addresses on the Raspberry Pi

>
>

I2C buses and I2C addresses on the Raspberry Pi

  The Raspberry Pi has 2 I2C buses with bus 1 being put onto the cobbler
Line: 139 to 140
 i2cdetect.png

Changed:
<
<

Initiating a I2C transfer

>
>

Initiating an I2C transfer

  initiate.png
Line: 166 to 167
 

A write cycle

Changed:
<
<
A write cycle:
After the start condition the device address. The eighth bit, the R/W bit is kept low.

The second data byte is considered the register byte and the last one the data byte
The slave acknowledges each byte transfer.
>
>
A write cycle:

After the start condition the device address. The eighth bit, the R/W bit is kept low.

The second data byte is considered the register byte and the last one the data byte

The slave acknowledges each byte transfer.
  writeCycle.png
Line: 187 to 188
  readCycle.png
Added:
>
>

I2C clock frequency

I2C bus supports different transfer speeds:

  • Standard: 100 kbps

  • Fast: 400 kbps

  • High speed: 3.4 Mbps
pigpio seems to use the standard speed

while the Raspberry Pi can run I2C transfers of up tp 1.66 Mbps

However: you need more low level libraries or direct register

access to accomplish these high speeds

MCP4725

mcp4725Desc.png

Specs of the MCP4275

dacSpecs.png

MCP4275 registers

dacRegs.png

MCP4275 I2C fast write

How does the I2C write cycle look like in the MCP4275?

The MCP4275 fast write cycle write only the DAC register and not the EEPROM.

This is enough for what we want to do.

mcp4725i2cWrite.png

MCP4275 normal write cycle

mcpNormalWrite.png

Read back the DAC data

mcp4725ReadCycle.png

pigpio: i2c_open

i2c_open.png

I2C access initialization with pigpio

In addition to opening the library with pigpio_start we now also must

make a connection to the I2C driver:

pigpio_i2cInit.png

Accessing I2C with pigpio

Coming back to fast write mode, we must write 3 bytes:

  • Address + R/W
  • Register
  • Data
The register byte contains also the high 4 bits on the 12 bit DAC data word

The first byte is created and written within the library extracting the I2C address

for the I2C initialization call

mcp4725i2cWrite.png

i2c_write_byte_data

The pigpio library provides a function

i2c_write_byte_data.png

This means we have to split our 12 bit DAC data into 2 parts:

The highest 4 bits go into i2c_reg, the lower 8 bits into bVal

Writing the DAC value, an example

dacValue is a short, while reg and value are unsigned char

dacWriteExample.png

DAC performance

There are a number of criteria which characterize the performance of a DAC

  • Its resolution or its least significant bit (lsb)

  • Its settling time (maximum speed you can go)
  • Its integral non-linearity or relative accuracy
  • Its differential non-linearity
  • Its offset error
  • Its gain error ...

Relative accuracy

INL_Def.png inlDiag.png

Differential non-linearity

dnldescr.png dnlDiag.png

Offset error

offsetDesc.png offsetDiag.png

Gain error

gainErrorDesc.png gainError_Diag.png

Settling Time

settlingTime.png settlingHigh.png
settlingLow.png  
 %SLIDESHOWEND%

-- Uli Raich - 2017-10-31

Line: 204 to 330
 
META FILEATTACHMENT attachment="addressing.png" attr="" comment="" date="1509473034" name="addressing.png" path="addressing.png" size="31875" user="uli" version="1"
META FILEATTACHMENT attachment="blockDiagram.png" attr="" comment="" date="1509473034" name="blockDiagram.png" path="blockDiagram.png" size="26858" user="uli" version="1"
META FILEATTACHMENT attachment="connection.png" attr="" comment="" date="1509473034" name="connection.png" path="connection.png" size="31653" user="uli" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="dacSpecs.png" attr="" comment="" date="1509473034" name="dacSpecs.png" path="dacSpecs.png" size="34714" user="uli" version="1"
>
>
META FILEATTACHMENT attachment="dacSpecs.png" attr="" comment="" date="1509961886" name="dacSpecs.png" path="dacSpecs.png" size="34714" user="uli" version="1"
 
META FILEATTACHMENT attachment="eqation.png" attr="" comment="" date="1509473034" name="eqation.png" path="eqation.png" size="17431" user="uli" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="INL_Def.png" attr="" comment="" date="1509473034" name="INL_Def.png" path="INL_Def.png" size="29564" user="uli" version="1"
>
>
META FILEATTACHMENT attachment="INL_Def.png" attr="" comment="" date="1509965219" name="INL_Def.png" path="INL_Def.png" size="29564" user="uli" version="1"
 
META FILEATTACHMENT attachment="inlDiag.png" attr="" comment="" date="1509473034" name="inlDiag.png" path="inlDiag.png" size="25183" user="uli" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="mcp4725Desc.png" attr="" comment="" date="1509473035" name="mcp4725Desc.png" path="mcp4725Desc.png" size="39400" user="uli" version="1"
>
>
META FILEATTACHMENT attachment="mcp4725Desc.png" attr="" comment="" date="1509961886" name="mcp4725Desc.png" path="mcp4725Desc.png" size="39400" user="uli" version="1"
 
META FILEATTACHMENT attachment="dacPrinc.png" attr="" comment="" date="1509526657" name="dacPrinc.png" path="dacPrinc.png" size="40088" user="uli" version="1"
META FILEATTACHMENT attachment="i2c_conn.png" attr="" comment="" date="1509726361" name="i2c_conn.png" path="i2c_conn.png" size="24377" user="uli" version="1"
META FILEATTACHMENT attachment="i2cdetect.png" attr="" comment="" date="1509727476" name="i2cdetect.png" path="i2cdetect.png" size="26106" user="uli" version="1"
Line: 217 to 343
 
META FILEATTACHMENT attachment="writeCycle.png" attr="" comment="" date="1509727758" name="writeCycle.png" path="writeCycle.png" size="12068" user="uli" version="1"
META FILEATTACHMENT attachment="startStop.png" attr="" comment="" date="1509727800" name="startStop.png" path="startStop.png" size="7946" user="uli" version="1"
META FILEATTACHMENT attachment="dataTransfer.png" attr="" comment="" date="1509727800" name="dataTransfer.png" path="dataTransfer.png" size="19169" user="uli" version="1"
Added:
>
>
META FILEATTACHMENT attachment="dacRegs.png" attr="" comment="" date="1509961712" name="dacRegs.png" path="dacRegs.png" size="58893" user="uli" version="1"
META FILEATTACHMENT attachment="mcp4725i2cWrite.png" attr="" comment="" date="1509962282" name="mcp4725i2cWrite.png" path="mcp4725i2cWrite.png" size="31543" user="uli" version="1"
META FILEATTACHMENT attachment="mcp4725ReadCycle.png" attr="" comment="" date="1509962282" name="mcp4725ReadCycle.png" path="mcp4725ReadCycle.png" size="58117" user="uli" version="1"
META FILEATTACHMENT attachment="mcpNormalWrite.png" attr="" comment="" date="1509962282" name="mcpNormalWrite.png" path="mcpNormalWrite.png" size="112491" user="uli" version="1"
META FILEATTACHMENT attachment="pigpio_i2cInit.png" attr="" comment="" date="1509963057" name="pigpio_i2cInit.png" path="pigpio_i2cInit.png" size="59418" user="uli" version="1"
META FILEATTACHMENT attachment="i2c_open.png" attr="" comment="" date="1509963601" name="i2c_open.png" path="i2c_open.png" size="15370" user="uli" version="1"
META FILEATTACHMENT attachment="i2c_write_byte_data.png" attr="" comment="" date="1509963601" name="i2c_write_byte_data.png" path="i2c_write_byte_data.png" size="19686" user="uli" version="1"
META FILEATTACHMENT attachment="dacWriteExample.png" attr="" comment="" date="1509963836" name="dacWriteExample.png" path="dacWriteExample.png" size="29032" user="uli" version="1"
META FILEATTACHMENT attachment="gainErrorDesc.png" attr="" comment="" date="1509965063" name="gainErrorDesc.png" path="gainErrorDesc.png" size="19372" user="uli" version="1"
META FILEATTACHMENT attachment="dnldescr.png" attr="" comment="" date="1509965046" name="dnldescr.png" path="dnldescr.png" size="32296" user="uli" version="1"
META FILEATTACHMENT attachment="dnlDiag.png" attr="" comment="" date="1509965046" name="dnlDiag.png" path="dnlDiag.png" size="24240" user="uli" version="1"
META FILEATTACHMENT attachment="gainError_Diag.png" attr="" comment="" date="1509965063" name="gainError_Diag.png" path="gainError_Diag.png" size="30089" user="uli" version="1"
META FILEATTACHMENT attachment="offsetDesc.png" attr="" comment="" date="1509965126" name="offsetDesc.png" path="offsetDesc.png" size="14153" user="uli" version="1"
META FILEATTACHMENT attachment="offsetDiag.png" attr="" comment="" date="1509965126" name="offsetDiag.png" path="offsetDiag.png" size="19064" 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