Download presentation
Presentation is loading. Please wait.
Published byJoella Small Modified over 8 years ago
1
1 Lab 4: D/A Converter
2
2 1000 Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum), 01, 10, 11 (maximum) You need to design the resistive network to generate proper outputs. For ECE5430 students, a four-bit D/A is recommended. 1000 ohms
3
3 Lab4: D/A Converter STK500 reads the analog value from VA using ADC channel 0
4
4 Lab 4: D/A Converter Equations for D/A Outputs: B’00:0.0 VS = (R1 || R2 || R3 ) * (0 Volts) B’01:0.3 VS = (R1 || R3 ) * (5 volts) / ((R1 || R3 ) + R2 ) B’10: 0.7 VS = (R1 || R2 ) * (5 volts) / ((R1 || R2 ) + R3 ) B’11:1.0 VS = R1 * (5 volts) / ((R2 || R3 ) + R1 ) Given: VS = 4 Volts, R1 = 1000 Find R2 and R3 by solving 2 equations with 2 variables using the equations for B’01 and B’11. Here we choose R1 = 1000 ohms. You can choose any proper value you want for R1. If R1 is too small, it may require large currents resulting in overheat problem.
5
5 Lab 4: D/A Converter
6
6
7
7 In-Lab Tasks Construct Circuit 4-1 with appropriate values of resistance. Do NOT connect Circuit 4-1 to the AVR mcu. Given your computed values of R2 and R3, verify the voltage of VA for the four possible port values. Connect Circuit to the AVR mcu. Write software for the AVR mcu that sets analog voltages at VA. Have the software loop through the voltages from 0.0VS, 0.30VS, xVS, 1.0VS and step back down to 0.0VS. Include a delay between each value. Use the C-routine delay_ms() in to generate the delay. Verify and document the resulting voltages of VA.
8
8 Lab 4: D/A Converter Initialize peripherals in ATMEGA16 P: Port x : Output to LED’s Port x : DAC output on pins 0 & 1 Port D : UART on pins 0 & 1 UART : 9600 baud, 8-N-1 Display opening marquee Start counter at 0 Start Port x = counter (to DAC) Port x = ~ counter (to LED’s) Increment counter so it runs: 1, 2, 3, 4, 1, 2 … Delay 2.5 seconds for voltage measurement Sample of Software flowchart
9
9 Lab 4: D/A Converter Initialization code for the ADC: // ADC initialization // ADC Clock frequency: 115.000 kHz // ADC Voltage Reference: AREF pin // ADC High Speed Mode: Off // ADC Auto Trigger Source: None
10
10 Lab 4: D/A Converter Code for reading an ADC channel: // Read the AD conversion result unsigned int read_adc(unsigned char adc_input) { ADMUX = adc_input|ADC_VREF_TYPE; // Start the AD conversion ADCSRA |= 0x40; // Wait for the AD conversion to complete while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; return ADCW; }
11
11 Lab 4: D/C Converter Suppose PB1 and PB0 are used as bit 1 and bit 0. They need to be set up as outputs and initially cleared. Initialization code for PORT B: // Port B initialization // Use b1 and b0 as the output pins to drive the resistor network. PORTB=0x00; // Clear output. DDRB=0x03; // Set up bit1-0 as outputs.
12
12 Lab 4: D/A Converter UART Design Set up the UART port to display the voltage at each step of the digital output. Initialization code for the UART: // Use UART for initial debug and later to output the count after // the count has been stopped. // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART Mode: Asynchronous // USART Baud rate: 9600 UCSRA=0x00; UCSRB=0x18; UCSRC=0x86; UBRRL=0x17; UBRRH=0x00;
13
13 Lab 4: D/A Converter while (1) { // Loop from b00, b01, b10, b11. for( i = 0; i < 4; i++ ) { // Change to the next D to A step. PORTB = i; // Delay for 2 seconds delay_ms( 2000 ); // Print the voltage to the screen. value = read_adc( 0x0 ); voltage = value * 5 / 1023; ??????
14
14 Lab 4: D/A Converter Terminal need to display: –Binary Output (first column) –ADC Reading (second column) –Voltmeter Reading (third column) 00 0.00 Volts 0.0012 Volts 01 1.20 Volts 1.194 Volts 10 2.75 Volts 2.710 Volts 11 3.96 Volts 3.906 Volts
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.