140 likes | 364 Views
Lab 4: D/A Converter. Lab 4: D/A Converter. 1000. 1000 ohms. This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (m inimum), 01, 10, 11 (maximum) You need to design the resistive network to generate proper outputs.
E N D
Lab 4: D/A Converter 1000 1000 ohms 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.
Lab4: D/A Converter STK500 reads the analog value from VA using ADC channel 0
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.
Lab 4: D/A Converter • 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 <delay.h> to generate the delay. • Verify and document the resulting voltages of VA.
Start • 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 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 Lab 4: D/A Converter Sample of Software flowchart
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
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; • }
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.
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;
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; • ?????? • ??????
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