|
META TOPICPARENT |
name="LectureSlides" |
|
|
< < | |
> > | Digital to Analogue Conversion |
| Digital to Analogue Conversion: the mcp4275 Lecture 10
Uli Raich
UCC semester 2017/2018
|
|
- 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: |
> > | 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
|
|
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)
|
> > | 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 |
|
< < | 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? |
|
have a look at this excellent tutorial, from which I have copied the above illustration. |
|
> > | |
| 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 |
> > | 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
|
|
< < | 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. |
| thus creating a short circuit.
|
|
< < | 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:
|
|
< < |
- 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
|
|
< < | I2C addressing |
> > | I2C addressing |
|
Since there can be several slaves on the bus there must |
| user to have several devices of the same type on the bus
|
|
< < | 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 |
|
|
|
< < | Initiating a I2C transfer |
> > | Initiating an I2C transfer |
|
|
|
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. |
> > | 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. |
|
|
|
|
|
> > |
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
Specs of the MCP4275
MCP4275 registers
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.
MCP4275 normal write cycle
Read back the DAC data
pigpio: i2c_open
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:
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
i2c_write_byte_data
The pigpio library provides a function
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
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
Differential non-linearity
Offset error
Gain error
Settling Time
|
| %SLIDESHOWEND%
-- Uli Raich - 2017-10-31 |
|
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" |
|
|
< < |
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" |
|
|
< < |
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" |
|
|
< < |
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" |
|
|
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" |
|
|
> > |
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" |
|