279_Exam_2_Combine.JPG

docx

School

Purdue University *

*We aren’t endorsed by this school

Course

ECET 27900

Subject

Electrical Engineering

Date

Feb 20, 2024

Type

docx

Pages

10

Uploaded by DukeWillpowerGerbil42

Report
Question 1 10/ 10 points In this function, Fcpu = 16MHz. OCROA = 100 TCNTO = 100 Answer the questions below: void Exam2(void) { TCCROB = (1<<CS02)| (1<<CS00) ; while((TIFRO & (1<<TOVO0)) == 0); TIFRO |= (1<<TOVO); TCNTO = 100; What is the prescaler used in the code? _-1024 __ v(20 %) When the function is called once, how long is the delay? in xx.x milli seconds _.100___ x (10.0 mSec) Name the flag that was used to produced the delay. Do not abbreviate, write the complete name as it appears in the datasheet ___Timer/CounterQ Overflow Flag___ % (Timer/counter 0 Overflow Flag) This function uses what type of method? Polling or Interrupt? Input the method in the space below. —Polling___ v(20%) If we convert the delay function to use interrupt, what should be inside the ISR? ISR ( IMERO_OVF _ve: _ v(20%) ) Question 2 2/ 3 points When writing code to use timer O, using the following conditions, check all the bits that should be set it 1 « Use timer O to write a delay code using polling method using Compare Output A Flag « Use 8 as the prescaler v| |Cs00 v| | TOIEO % [v| OCIEOA v |Cs02 = v|v|CS01 v/ |TOVO Question 3 3/ 3 points You are to make a function that generate delay using polling method that monitor the Output Compare Flag A. Assume we use prescaler 1024 and Fcpu = 16MHz. How long does it take for the timer TCNT to increment its count by 1? (answer in pus) Answer: 64 v Question 4 3/ 3 points Check all the modes that you cannot be use to control a dc motor with changing duty cycles? v | Phase Correct Mode || CTC mode v normal mode V| | Fast PWM Question 5 3/ 3 points You will use Timer3 to produce a PWM signal. Where is this pin most likely to locate in the Arduino mega? PB5 v(e) PE3 PA7
Question 6 3/ 3 points Which of the following WGM Mode always have the same duty cycle, 50% duty cycle. This is not a PWM mode. Phase Correct mode v ®) CTC mode Fast PWM mode Normal mode Question 7 12/ 12 points Use Timer 3 to produce PWM signal. The clock frequency of the controller is 16MHz. The following code is used to set up the PWM signal. TCNT3 =0; TCCR3A = (1<<COMBA1) | (1<<WGM31) | (1<<WGM30); TCCR3B = (1<<WGM32) | (1<<CS32) | (1<<CS30) ; OCR3A = 200; What is the PWM mode of operation as written in the datasheet, including the number of bits? ___Fast PWM, 10-bit __ (25 %) What is the prescaler? 1024 (25 %) What is the duty cycle? answer in xx % format _20% __ x (20%,20%) Where is the PWM output located? Port ___E___ «(5%) Pin 3__ v(5%)
Question 8 3/ 3 points To set up the potentiometers for ADC, the input pins should be configured to Check all the true statements « | input with pull up resistors enabled v output + input, with pullup resistors disabled v | DDRF = OxFF; PORTF = 0x00; Question 9 3/ 3 points To start ADC conversion using polling method at channel 3 with 128 as prescaler, which of the following must be set? v v ADEN v MUX3 v MUX4 v MUX2 Vv MUX1 v ADIF v~ ADPS2 Vv ADPSO v v/ MUX0 v v ADPS1 Question 10 2/ 2 points an ADC_value equals to 205, using 10 bit conversion, what is the voltage input (answer in x.x V) ? siO 9 (1, 1.001) V.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Question 11 Match the bits names with their functions v __1__ Voltage Reference Selection 1. REFS1 v __2__ ADC Left Adjust Result 2. ADLAR v __3__ Analog Channel and Gain Selection bits 3. MUXO0 Question 12 Match the following bit with their functions v __4__ Prescaler Select Bit 1. ADEN v __1__ ADC Enable, enable ADC 2 ADSC v __2__ ADC start Conversion 3 ADIF ADC Interrupt Flag, it turns to one when conversion is 4 ADPS2:0 -—2__ completed Question 13 4 / 4 points ADC hardware is connected as shown in the image. You are to write code to initialize the ADC. Check the register that should be set to 1in ADMUX - Vref = 5V Sensor 0-5V MUX Oulpul v ADC G:igclx disgbi;tal out Pre-scaler = 128 F_cpu =T 16MHz v |MUX3 v | REFSO v | MUX4 v v | MUX2 v MUX1 v |MUXO v |REFS1 v v | ADLAR
Question 14 3.5/ 4 points ADC hardware is connected as shown in the image. You are to write code to initialize and start conversion using interrupt method. Check the register that should be set to 1 in ADCSRA 0o Vref = 5V Sensor 0-5v Mux ADC AN Output to ADC G digital ain 1x out Pre-scaler = 128 F_cpu = 16MHz v| |ADIF v| | ADATE = v|v|ADPS2 = v|v|ADEN » X ADIE = v|v|ADSC = « v|ADPS1 = || ADPSO
Question 15 Sensor 0-5v MUX Oulpul lu ADC Using the above setup, use polling method in your ADC function, write a line of code that reset the interrupt flag. Answer: ADCSRA = ADCSRA | (1<<(ADIF = 0)); (ADCSRA |= (1<<ADIF);) Question 16 Apca Sensor 0-5v MUX Oulpul v ADC Vref =5V ADC Gain 1x Pre-scaler = 128 T F_cpu = 16MHz x Vref =5V ADC Gain 1x Pre-scaler =128 F_cpu = 16MHz 8bit digital out 8bit digital out 0/ 4 points 4/ 4 points Using the above setup, use polling method in your ADC function, write a line of code that wait until the ADC interrupt flag indicates the conversion is complete. Must use (1<< ) operations. Binary number or hex numbers will not be accepted. Answer: while (ADCSRA & (1<<ADIF))==0){} (while ((ADCSRA & (1<<ADIF)) == 0) ;) x
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Question 17 | Abca Sensor 05V MUX Oulpul W ADC Vref = 5V ADC Gain 1x Pre-scaler = 128 F_cpu = 16MHz 8bit digital out Use the above setup, write the function that read the ADC input and return the value to the main function. Use Polling method and only the most appropriate data type. Name of the function: adc_channel4 Include the function header Points will be deducted if there are codes not useful for this specific function. Do not include ADC initialization in this function. (points will be deducted) 8 /10 points Do not select the channel in this function, it has already been selected before calling this function. (points will be deducted) Do start ADC conversion uint8_t adc_channel4(void) { ADCSRA = ADCSRA | (1<<ADSC); while (ADCSRA & (1<<ADIF) == 0) {} uint8_t adc_read_out = ADCH; return adc_read_out; )
Question 18 Sensor 05V MUX Oulpul W ADC Use the above setup, write the ISR code that read the ADC input. appropriate data type. Note reading only 8 bits of data. Do not select channel (points will be deducted) Do start ADC conversion after reading the values Start with ISR ( xxxxxxx ), include the ISR header { ] ISR (ADC_vect) { } Vref =5V ADC Gain 1x Pre-scaler = 128 F_cpu = 16MHz 8bit digital out 1/ 4 points You may choose your name for the variables and use the most The correct answer is not displayed for Written Response type questions.
Question 19 4 / 4 points Match the following interrupt source with their routine v __3__ ADC Conversion Complete 1. ISR(TIMERO_OVF _vect) + __4__ Timer/Counter 0 Compare Match A 2. ISR(INTO_vect) v __1__ Timer/Counter O Overflow 3. ISR(ADC _vect) v_2_ External Interrupt Request O 4. ISR(TIMERO_COMPA _vect) Question 20 4/ 4 points When using the external interrupt 4, which of the following register and bit enables this interrupt? EICRB, bit 4 EIMSH, bit 0 EICRA, Bit 4 V(e EIMSK, bit 4 Question 21 3/ 3 points Two pushbuttons are connected to INTO and INT1. They are set up as external interrupts. These interrupts are triggered by falling edge. To initialize these external interrupts, select the bits that should be set to 1 in register EICRB v/ 1SC00 v/ 15C01 v[ I1sC10 viv|IsC11 v/ 15C20 v/ I1sc21 v/ 1SC30 v 1sC31
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Question 22 When the input capture interrupt is triggered, what happened? | Output Compare value is cleared = « | Content of TCNT is copied to ICR registers v | TCNT value is cleared = % | | Code inside the service routine is executed Question 23 This is declaration of variable: uint16_t A; A=16/9; What is A? Answer: 1 v Question 24 X = 0xA9; Y = 0x08; Z=0x02; C=X"Y; What is the value of C (in hex) ? (0x??) put the value for ?? Answer: 0xA1 v 2.25/ 3 points 2/ 2 points 2/ 2 points Attempt Score:() 88.75 /100 - B+ Overall Grade (highest attempt):© 88.75 / 100 - B+