|
发表于 2014-3-6 15:08:28
|
显示全部楼层
CprE 288 Spring 2014 – Homework 6
Note: Unless otherwise specified, all problems assume the ATMega128 is being used
Question 1: USART Basics (10pts)
Sketch the waveform appearing at the output of the USART when it transmits a character ‘7’ at 57,600 baud rate (see the example on slide 4, week 6). The sketch should show the bit durations in microseconds, in addition to the waveform. The frame format is of 1 start bit, 8 data bits, an even parity bit, and 1 stop bits.
#include <homework_6_answer.h>
void main()
{
Q1(1,7,57600,1,8,0,1);
}
Question 2: USART Programming (20pts)
You are asked to program an ATmega128 so that it plays as a one-way USART reply node from USART0 to USART1: Any character received by USART0 should be transmitted through USART1 to the outside. The program must be interrupt-based, so the microcontroller can do other work.
a. [10] Assume the ATmega128 runs at 16MHz. Write a USART_init() function to initialize both USART units as follows:
• Asynchronous communication
• USART0 as receive only, USART1 as transmit only
• 115,200 baud rate
• 8 data bits
• no Parity
• 1 stop bit
• An interrupt enable bit is set if and only if that is necessary.
You may initialize unrelated control bits as you wish.
#include <homework_6_answer.h>
USART_init()
{
Q2_a(0);
Q2_a(1);
}
void main()
{
SetCPU_Mhz(16);
USART_init();
}
b. [10] What interrupt handler(s) do you have to write to implement the reply functionality? Explain.
Then, write the interrupt handler(s). You code should check for communication overflow: if USART0 receives a character but USART1 is not ready for transmitting, then the received character should be discarded. In other word, your code should check the UDRE flag in UCSR1A before it writes to UDR1. You need to find out the interrupt vector code, which is available in the ATmega128 datasheet.
Note: Reading UDRn will clear the RXC interrupt flag and consequently the interrupt signal, so your code does not have to clear that interrupt flag.
#include <homework_6_answer.h>
void USART_init()
{
Q2_b(0);
Q2_b(1);
UART_interrupt(Q2_bb);
}
void main()
{
SetCPU_Mhz(16);
USART_init();
}
Question 3: ADC Design Principle (10 pts)
Suppose that an ATmega128 is used with a thermal sensor to monitor the ambient temperature. The sensor measures temperature in range of -50 degree Celsius to 150 degree Celsius and converts temperature proportionally to an electrical signal of voltage range from 0.0V to 2.0V. The ADC uses the reference voltage of 2.56V. Assume that the number of steps is 2n, where n is the number of bits of the ADC output. Recall that the ADC in ATmega128 is 10-bit.
a. If the ambient temperature is 32 degree Celsius, what is the voltage of the sensor’s output? (3 pts)
#include <homework_6_answer.h>
char i;
i = Q3_a_adc(32,2.56,0,2);
b. What is the corresponding digital reading from the ADC output? (3 pts)
#include <homework_6_answer.h>
char i;
i = Q3_b_adc();
c. If the digital reading is 300, what is the range of the analog value? Note that each digital number corresponds to a step (a small range in the span) of the analog value. (4 pts)
#include <homework_6_answer.h>
char i;
i = Q3_c_adc(300);
Question 4: ADC Design Principle (10 pts)
A 4-bit ADC (of 24 = 16 steps in the analog range) uses the Successive Approximation implementation. The input voltage range is 0.0V-16.0V. If the input is 5.0V, how does the ADC work out each bit of the digital encoding? Fill the following table to show the steps (as did in the class). The first step is given.
Step Range DN_Mid AV_Mid(V) Input >= AV_Mid
0 xxxx 1000 8 0
1 0xxx
2
3
4
The digital value is __ Q4A_b() ___ (binary) and __ Q4A_d() ___ (decimal).
Question 5: ATmega128 ADC Programming (5 pts)
Describe in a few sentences how to use the ADSC bit in ADCSRA to start an ADC conversion, and to wait for the ADC conversion result to be ready.
Q5()
Question 6: ATmega128 ADC Programming (10 pts)
Assume ATmega128 platform with the system clock configured to 4MHz (for improved power efficiency). Write two C statements to configure the ADC as follows:
• Interrupt enabled
• One-shot mode
• ADC clock rate in the range of 50K-200K Hz
• Reference voltage is Vcc
• No differential input
• ADCW right adjusted
• The initial input channel is 7
ADC_init()
{
Q6();
}
Question 7: ADC Programming (20 pts)
A Atmega128 is being used to monitor humidity inside test chamber 03. The device uses two sensors to have some fault tolerance. They are connected to ADC channels 0 and 1. The program uses the average and maximum error of the two values. Previously the program used interrupts to update the average and the maximum error of the two sensors, but recently the interrupts on the chip stopped working. GLaDOS has asked you to write code to do this with polling instead of interrupts.
Other notes:
MaxError can only be set to a higher value
The ADC has been initialized like the question above
Using a spin lock to wait for ADSC to clear is ok.
Void updateHumidity(unsigned* maxError, unsigned* ave){
//your code
Q7();
}
main(){
unsigned MaxError = 0;
unsigned Ave = 0;
init();
while(1){
updateHumidity(&MaxError, &Ave);
// Somebody else’s problem
}
}
if you want to buy <<CprE 288 Spring 2014 – Homework 6 Answer>>,please go to "www.taobao.com"
and find the shop that name is "what the hell is the homework answer " .
My name is red scarf , I'm pleased to help you, Now please pay me $50 for my work, thank you. |
|