End Presentation


TWiki Slide Show
Next
Digital to Analogue Conversion

Digital to Analogue Conversion:

the mcp4275

Lecture 10

Uli Raich

UCC semester 2017/2018

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





















TWiki Slide Show
Next
Analogue versus digital
Up to now we only treated digital signals:
  • 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
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

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





















TWiki Slide Show
Next
Converting from digital to analogue
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)

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





















TWiki Slide Show
Next
Digital to analogue conversion
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?

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





















TWiki Slide Show
Next
Can we smooth the output signal?
Yes, it is possible to smooth out these steps.

We need a low-pass filter, which filters out high frequencies

(the abrupt steps we have in the output signal) and lets pass only slower transitions.

When looking carefully at the output of our sine generator you will

also see these steps. In this case however they come from the

limited number of sine values (100) we calculate. To improve the resolution

we would have to increase the number of samples and the frequency

with which we send these values to the DAC.

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





















TWiki Slide Show
Next
How does a DAC work?
dacPrinc.png

If you want to know more about DAC technology (and you should!)

have a look at this excellent tutorial, from which I have copied the above illustration.

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





















TWiki Slide Show
Next
The MCP4725 12 bit DAC
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

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





















TWiki Slide Show
Next
The I2C bus
The I2C bus is an industrial standard 2 wire bus using a data (SDA) and a clock (SCL) line.

Adding Vcc and Gnd we need a mere 4 wires to connect

a I2C device to the Raspberry Pi cobbler

The I2C bus was invented by Philips

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





















TWiki Slide Show
Next
Typical I2C connections
i2c_conn.png

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





















TWiki Slide Show
Next
Open drain signals
Open drain signals mean that you can pull a line down

but you cannot set it to a high level.

If nobody pulls the line down, then it is at Vcc level,

pulled up by a pull-up register.

Like this the contention problem is solved where one device tries

to set a line to a high level, while another sets it to low,

thus creating a short circuit.

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





















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

  • 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

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





















TWiki Slide Show
Next
I2C addressing
Since there can be several slaves on the bus there must

be a means of distinguishing them through addressing:

Every I2C slave has a 7 bit address associated with it

Usually this address is determined by the manufacturer but

often there are address pins on the devices allowing the

user to have several devices of the same type on the bus

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





















TWiki Slide Show
Next
I2C buses and I2C addresses on the Raspberry Pi
The Raspberry Pi has 2 I2C buses with bus 1 being put onto the cobbler

You can find out the addresses of the I2C slaves are currently

connected with the i2cdetect command

i2cdetect.png

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





















TWiki Slide Show
Next
Initiating an I2C transfer
initiate.png

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





















TWiki Slide Show
Next
Start stop conditions
The master starts a transfer by creating a

start condition:

  • high to low transition on SDA while SCL is high
and ends the transfer with a

  • stop condition: low to high transition on SDA while SCL is high4

startStop.png

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





















TWiki Slide Show
Next
Data transmission
Data are transmitted with the SDA line stable with SCL is high

dataTransfer.png

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





















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

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





















TWiki Slide Show
Next
The read cycle
The read cycle is a bit more complex:

First the master sends the slave address with R/W set to write

Then it sends the register information.

After that another address byte is sent, this time with RW set to read

And finally the slave sends the data. The master still sends the clock but

releases the SDA line allowing the slave to control it

readCycle.png

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





















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

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





















TWiki Slide Show
Next
MCP4725
mcp4725Desc.png

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





















TWiki Slide Show
Next
Specs of the MCP4275
dacSpecs.png

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





















TWiki Slide Show
Next
MCP4275 registers
dacRegs.png

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





















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

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





















TWiki Slide Show
Next
MCP4275 normal write cycle
mcpNormalWrite.png

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





















TWiki Slide Show
Next
Read back the DAC data
mcp4725ReadCycle.png

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





















TWiki Slide Show
Next
pigpio: i2c_open
i2c_open.png

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





















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

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





















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

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





















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

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





















TWiki Slide Show
Next
Writing the DAC value, an example
dacValue is a short, while reg and value are unsigned char

dacWriteExample.png

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





















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

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





















TWiki Slide Show
Next
Relative accuracy
INL_Def.png inlDiag.png

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





















TWiki Slide Show
Next
Differential non-linearity
dnldescr.png dnlDiag.png

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





















TWiki Slide Show
Next
Offset error
offsetDesc.png offsetDiag.png

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





















TWiki Slide Show
Next
Gain error
gainErrorDesc.png gainError_Diag.png

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





















TWiki Slide Show
Next
Settling Time
settlingTime.png settlingHigh.png
settlingLow.png  

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





















First slide Previous End Presentation






























-- Uli Raich - 2017-10-31

Comments

I Attachment History Action Size Date Who Comment
PNGpng INL_Def.png r1 manage 28.9 K 2017-11-06 - 10:46 UnknownUser  
PNGpng addressing.png r1 manage 31.1 K 2017-10-31 - 18:03 UnknownUser  
PNGpng blockDiagram.png r1 manage 26.2 K 2017-10-31 - 18:03 UnknownUser  
PNGpng connection.png r1 manage 30.9 K 2017-10-31 - 18:03 UnknownUser  
PNGpng dacPrinc.png r1 manage 39.1 K 2017-11-01 - 08:57 UnknownUser  
PNGpng dacRegs.png r1 manage 57.5 K 2017-11-06 - 09:48 UnknownUser  
PNGpng dacSpecs.png r1 manage 33.9 K 2017-11-06 - 09:51 UnknownUser  
PNGpng dacWriteExample.png r1 manage 28.4 K 2017-11-06 - 10:23 UnknownUser  
PNGpng dac_front.png r1 manage 1097.6 K 2017-10-31 - 18:03 UnknownUser  
PNGpng dataTransfer.png r1 manage 18.7 K 2017-11-03 - 16:50 UnknownUser  
PNGpng dnlDiag.png r1 manage 23.7 K 2017-11-06 - 10:44 UnknownUser  
PNGpng dnldescr.png r1 manage 31.5 K 2017-11-06 - 10:44 UnknownUser  
PNGpng eqation.png r1 manage 17.0 K 2017-10-31 - 18:03 UnknownUser  
PNGpng gainErrorDesc.png r1 manage 18.9 K 2017-11-06 - 10:44 UnknownUser  
PNGpng gainError_Diag.png r1 manage 29.4 K 2017-11-06 - 10:44 UnknownUser  
PNGpng i2c_conn.png r1 manage 23.8 K 2017-11-03 - 16:26 UnknownUser  
PNGpng i2c_open.png r1 manage 15.0 K 2017-11-06 - 10:20 UnknownUser  
PNGpng i2c_write_byte_data.png r1 manage 19.2 K 2017-11-06 - 10:20 UnknownUser  
PNGpng i2cdetect.png r1 manage 25.5 K 2017-11-03 - 16:44 UnknownUser  
PNGpng initiate.png r1 manage 19.2 K 2017-11-03 - 16:49 UnknownUser  
PNGpng inlDiag.png r1 manage 24.6 K 2017-10-31 - 18:03 UnknownUser  
Unknown file formatodp lecture_10.odp r1 manage 2016.0 K 2017-11-16 - 18:32 UnknownUser  
PNGpng mcp4725Desc.png r1 manage 38.5 K 2017-11-06 - 09:51 UnknownUser  
PNGpng mcp4725ReadCycle.png r1 manage 56.8 K 2017-11-06 - 09:58 UnknownUser  
PNGpng mcp4725i2cWrite.png r1 manage 30.8 K 2017-11-06 - 09:58 UnknownUser  
PNGpng mcpNormalWrite.png r1 manage 109.9 K 2017-11-06 - 09:58 UnknownUser  
PNGpng offsetDesc.png r1 manage 13.8 K 2017-11-06 - 10:45 UnknownUser  
PNGpng offsetDiag.png r1 manage 18.6 K 2017-11-06 - 10:45 UnknownUser  
PNGpng pigpio_i2cInit.png r1 manage 58.0 K 2017-11-06 - 10:10 UnknownUser  
PNGpng pinout.png r1 manage 33.6 K 2017-10-31 - 18:03 UnknownUser  
PNGpng readCycle.png r1 manage 12.7 K 2017-11-03 - 16:49 UnknownUser  
PNGpng resolution.png r1 manage 17.6 K 2017-10-31 - 18:03 UnknownUser  
PNGpng settlingHigh.png r1 manage 31.5 K 2017-10-31 - 18:03 UnknownUser  
PNGpng settlingLow.png r1 manage 30.4 K 2017-10-31 - 18:03 UnknownUser  
PNGpng settlingTime.png r1 manage 16.9 K 2017-10-31 - 18:03 UnknownUser  
PNGpng startStop.png r1 manage 7.8 K 2017-11-03 - 16:50 UnknownUser  
PNGpng writeCycle.png r1 manage 11.8 K 2017-11-03 - 16:49 UnknownUser  

This topic: Embedded_Systems > WebHome > LectureSlides > Lecture10:DigitalToAnalogueConversion
Topic revision: r6 - 2017-11-16 - 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