You are on page 1of 8

Program: Interfacing of DAC with ARM

#include
#include
#include
#include

<iolpc2378.h>
"irq.h"
"config.h"
"dac.h"

void DACInit( void )


{
/* setup the related pin to DAC output */
PINSEL1 = 0x00200000; /* set p0.26 to DAC output */
return;
}
//Main Function
int main (void)
{
unsigned int i;
TargetResetInit();
/* Initialize DAC
DACInit();

*/

while ( 1 )
{
DACR = (i << 6) | DAC_BIAS;
i++;
if ( i == 1024 )
{
i = 0;
}
}
return 0;
}

17

Exp.No:
Date :

INTERFACING OF ADC & DAC

Aim
To interface ADC and DAC with ARM 7 Controller
Components Required:
1. LPC 2378 ARM Development board
2. IAR Embedded Workbench 6.5
3. Flash Magic ISP Utility
Theory
A digital-to-analog converter is a device for converting a digital (usually binary) code to
an analog signal (current, voltage or charges). Digital-to-Analog Converters are the interface
between the abstract digital world and the analog real life. Simple switches, a network of
resistors, current sources or capacitors may implement this conversion. A DAC inputs a binary
number and outputs an analog voltage or current signal.
MCP429x:

The Microchip Technology Inc. MCP492X is 2.7 5.5V, low-power, low DNL, 12-Bit
Digital-to-Analog Converters (DACs) with optional 2x buffered output and SPI interface. The
MCP492X are DACs that provide high accuracy and low noise performance for industrial
applications where calibration or compensation of signals is required
Interfacing SPI-DAC:
Fig.4 shows how to interface the SPI-DAC to microcontroller. With an SPI connection
there is always one master device (usually a microcontroller) which controls the peripheral
devices. Typically there are three lines common to all the devices,
Master In Slave Out (MISO) - The Slave line for sending data to the master,
Master Out Slave In (MOSI) - The Master line for sending data to the peripherals,
Serial Clock (SCK) - The clock pulses which synchronize data transmission generated by
the master.
Slave Select pin - the pin on each device that the master can use to enable and disable
specific devices.

18

OUTPUT:

19

Interfacing of ADC:
An analog-to-digital converter is a device that converts a continuous quantity to a
discrete digital number. Typically, an ADC is an electronic device that converts an input analog
voltage (or current) to a digital number proportional to the magnitude of the voltage or current.
The resolution of the converter indicates the number of discrete values it can produce over the
range of analog values. The values are usually stored electronically in binary form, so the
resolution is usually expressed in bits. In consequence, the number of discrete values available,
or "levels", is usually a power of two.
An ADC with a 10-bit output can represent up to 1024 (210) unique conditions of signal
measurement. Over the range of measurement from 0% to 100%, there will be exactly 1024
unique binary numbers output by the converter (from 0000000000 to 1111111111, inclusive).
ViARM - 2378 Development board has two potentiometers for working with A/D
Converter. All Potentiometers outputs are in the range of 0V to 3.3V. ARM processor takes
analog signal from its input pin and translates it into a digital value. Basically, you can measure
any analog signal that fits in range acceptable by LPC2378. That range is 0V to 3.3V.
PROCEDURE:
1. Run the Application IAR Embedded Workbench 6.5
2. Create new project in the current work space. Create a new project by selecting the tool
chain as ARM and create empty project and click ok. Give Project Name and click
SAVE Button.
3. Select LPC2378 >Options menu
4. Select General options category. Enable target option file and select the device as NXP
LPC2378 and click ok.
5. Select C/C++ Compiler >Select Preprocessor and include (C:\Program Files\IAR
Systems\Embedded
Workbench
6.5\arm\inc\c,
C:\Program
Files\IAR
Systems\Embedded Workbench 6.5\arm\inc\NXP)
6. Enable Output Converter Menu and select output format as Intel extended and Enable
Override default option
7. Select Linker Category. Enable Override default option, click SAVE Button.
8. New>File Menu, for creating a new C file. File>Save As, for saving a file. Give your
File name ( Eg: DAC.C) and click Save Button.

20

Program: Interfacing of ADC with ARM


#include<NXP\iolpc2378.h>
#include "irq.h"
#include "config.h"
unsigned int ADC_VALUE=0;
#define ADC_CLK
1000000
/* set to 1Mhz */
void send_serial_data(unsigned char serial)
{
while((U0LSR & 0x20)==0);
U0THR = serial;
}
void adc_serial_tx(unsigned int ch)
{
unsigned int
t1000 = ch
temp = ch
t100 = temp
temp = temp
t10
= temp
t1
= temp

t1000,t100,t10,t1,temp;
/ 1000;
% 1000;
/ 100;
% 100;
/ 10;
% 10;

send_serial_data(t1000+0x30);
send_serial_data(t100 +0x30);
send_serial_data(t10+0x30);
send_serial_data(t1+0x30);
send_serial_data(0x0d);
send_serial_data(0x0a);
}
void main()
{
unsigned long int val;
unsigned int Fdiv;
TargetResetInit();
PCONP |= (1 << 12);
PINSEL1 = 0X00054000;
PINSEL0 = 0x00000050;

//AD0.0 AS ANALALOG INPUT


// RxD0 and TxD0

// PINSEL1 &= ~0x003FC000; /* P0.23~26, A0.0~3, function 01 */


// PINSEL1 |= 0x00154000;
// PINSEL3 |= 0xF0000000; /* P1.30~31, A0.4~5, function 11 */
U0LCR = 0x83;
// 8 bits, no Parity, 1 Stop bit
Fdiv = ( Fpclk / 16 ) / 19200 ; //baud rate
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03;
// DLAB = 0
U0FCR = 0x07;
// Enable and reset TX and RX FIFO.

21

9. Right Click the project name option for select a C file in


workspace window. Select Add >Add (DAC.C) Menu.
10. Select LPC2378>Rebuild all menu, for checking any error in your C file. If your
Cfile has no error.
11. Select LPC2378>Rebuild all menu, for checking any error in your C file.
12. If your project has no error, Building completed and Hex file generated.
13. This Hex file will be downloaded to the VIARM-2378 controller by Flash Magic
Software
Steps To Be Followed In Flash Magic Software For Embed Into Kit:
Step 1: Open Flash Magic software
Step 2: Go to step 1: Communications
Select Com port
: COM1
Baud Rate
: 19200
Device
: LPC2378
Interface
: None (ISP)
Oscillator Freq (MHz) : 16.000000
Step 3: Go to step 2: Erase
Select Erase blocks used by Hex file
Step 4: Go to step 3: Hex file
Select Browse corresponding Hex file
Step 5: Directly go to step 5: Start click start for Embed (*.HEX) file to kit.

22

// AD0CR = 0x01200601;
// Start A/D Conversion
AD0CR = ( 0x01 << 1 ) |
/* SEL=1,select channel 0~7 on ADC0 */
( ( Fpclk / ADC_CLK - 1 ) << 8 ) | /* CLKDIV = Fpclk / 1000000 - 1 */
( 1 << 16 ) |
/* BURST = 0, no BURST, software controlled */
( 0 << 17 ) |
/* CLKS = 0, 11 clocks/10 bits */
( 1 << 21 ) |
/* PDN = 1, normal operation */
( 0 << 22 ) |
/* TEST1:0 = 00 */
( 1 << 24 ) |
/* START = 0 A/D conversion stops */
( 0 << 27 );
/* EDGE = 0 (CAP/MAT singal falling,trigger A/D
conversion) */

while(1)
{
while((AD0GDR & 0X80000000)!=0X80000000);
val = (AD0GDR>>6)& 0x3ff ;
// convesion data holds AD0DR0[6]
to AD0DR0[15]
adc_serial_tx(val);
// 10 bit adc data transmit serial
port.
}
}

23

RESULT:

24

You might also like