0% found this document useful (0 votes)
202 views4 pages

Interfacing Adc and Dac With Arm

Uploaded by

Avinash cliffe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
202 views4 pages

Interfacing Adc and Dac With Arm

Uploaded by

Avinash cliffe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ex.

No:
DATE : INTERFACING ADC AND DAC WITH ARM

AIM
To develop a C-Language program for reading an on-chip ADC, convert into decimal and to display it in
PC and to generate a square wave depending on this ADC reading using ARM processor.

APPARATUS & SOFTWARE REQUIRED

1. VSK-SCM4 Development board.

2. IAR IDE software.

3. Flash Loader Demonstrator. .

4. CRO

THEORY
ADC

Three 12-bit analog-to-digital converters are embedded and each ADC shares up to 16 external channels,
performing conversions in the single-shot or scan mode. In scan mode, automatic conversion is performed on a
selected group of analog inputs.
Additional logic functions embedded in the ADC interface allow:
 Simultaneous sample and hold
 Interleaved sample and hold

PROCEDURE

1. Double click IAR Embedded Workbench in the Desktop.


2. To create a new project, choose Project>Create New Project. In the Dialog box, set the tool chain to
ARM and select the project template as empty project.
3. To type the ADC program, select new from file menu and save it with the name ( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader software.
7. To view the output, after downloading your program change the board to execution mode and reset it.
8. The ADC values will be varying depending on the setting of the POTMETER 2.
DAC

The two 12-bit buffered DAC channels can be used to convert two digital signals into two analog voltage signal
outputs.
This dual digital Interface supports the following features:
 Two DAC converters: one for each output.
 Channel 8-bit or 12-bit monotonic output.
 Left or right data alignment in 12-bit mode.
 Synchronized update capability.
 Noise-wave generation.
 Triangular-wave generation.
 Dual DAC channel independent or simultaneous conversions.
 DMA capability for each channel.
 External triggers for conversion.
 Input voltage reference VREF+.
Eight DAC trigger inputs are used in the device. The DAC channels are triggered through the timer update
outputs that are also connected to different DMA streams.

PROCEDURE

1. Double click IAR Embedded Workbench in the Desktop.


2. To create a new project, choose Project>Create New Project. In the Dialog box, set the tool chain to
ARM and select the project template as empty project.
3. To type the DAC program, select new from file menu and save it with the name ( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader software.
7. To view the output, after downloading your program change the board to execution mode in cortex
M4 development board and reset it.
8. Make use of a CRO or DSO to view the DAC output by connecting the +ve terminal to pin 5 and the
–ve terminal to GND.
9. The waveforms can be viewed in either the CRO or DSO.

PROGRAM
/*Header Files*/
#include "stm32f4xx.h"
#include <stdio.h>

/*Declarations*/
int ConvertedValue = 0;

/*Function to Configure ADC*/


void adc_configure()
{
RCC->APB2ENR |= 1<<10; //The ADC3 is connected the APB2 peripheral bus
RCC->AHB1ENR |= 1<<0; //ADC is connected with PORTA!
GPIOA->MODER |= 0x0000000F; //analog mode PA1,PA2
ADC3->CR2 = 0x00000003; //data right alignment, continuous conversion mode.
ADC3->SMPR2 = 0x00000030; //ADC3 channel-1 with 144 cycles
ADC3->SQR3 = 0x00000001; //rank1 to ADC3 channel-1
}

/*Function to configure DAC*/


void dac_configure()
{
RCC->APB1ENR |= 0x20000000; // Enable clock for DAC
DAC->CR |= 0x00000001; // DAC control reg, both channels ON
GPIOA->MODER |= 0x00000f00; // MODE Register PortA, PA4 & PA5 are analog!
}

/*Functoin to convert ADC*/


int adc_convert()
{
ADC3->CR2 |= 0x40000000; //Start of Conversion
while(! (ADC3->SR & 0x0002) ); //Wait for End Of Conversion
return ADC3->DR;
}

/*Function to Configure USART2*/


void USART2_config()
{
RCC->AHB1ENR |= 1 << 0; //clock to portA
RCC->APB1ENR |= 1 <<17; //clock to USART2
GPIOA->MODER |= 0x000000A0; //alternate function mode(PA2,PA3)
GPIOA->AFR[0] |= 0x00007700; //USART2 RX, TX
USART2->BRR = 0x16D; //115200 baud rate
USART2->CR1 = 0x200C; //Enable Transmission
}

/*Main Routine*/
int main(void)
{
USART2_config();
adc_configure();
dac_configure();
while(1)
{
ConvertedValue = adc_convert(); //Read the ADC converted value
printf("\n\r ADC value => %d",ConvertedValue); //print the ADC value
DAC->DHR12R1 =ConvertedValue; //Move the Digital value to DAC
}
}

int putchar(int data)


{
USART2->DR = (data & 0x01FF);
while((USART2->SR & 0x40) ==0)// Loop until the end of transmission
{}
return data;
}
RESULT
Thus the Conversion of Analog to Digital and digital to analog are performed and verified with ARM processor
successfully.

S.No Mark Allocation Max. Marks


Marks Awarded

1 Preparation 2

2 Interest and
2
Involvement

3 Skill in completing the


4
experiments & results

4 Viva-Voce 2

Total 10

Date Sign

You might also like