Homework 7 Solution

# 8 possibe prescaler values switchprescale case 1

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 4 3 : : : : : ADEN ADSC ADFR ADIF ADIE = = = = = 1 0 0 0 0 (enable the ADC) (writing a 0 causes no modification) (One shot mode) (writing a 0 causes no modification) (Disable conversion completion interrupts) Name: Lab Section: // Note: Can used interrupts, but solution must use an ISR properly //Bits 2-0:dADPS2 ADPS1 ADPS0= 111(ADC clk prescalar:16MHz/128=125K) ADCSRA = 0b10000111; // Capture the time of a positive edge while(1) { // Check if A_in is < .5V (i.e. logic 0) if(ADC_Read_value() < VOLTAGE_0_5V) { // wait for A_in > 2V (i.e. logic 1) while(ADC_Read_value() <= VOLTAGE_2_0V) {} rising_edge_time = TCNT1; // Store counter value } } } // Helper function, used to make main easier to understand int ADC_Read_value(void) { // Initiate an ADC conversion ADCSRA |= 0x40; // or 0b01000000 // Wait for the conversion to finish while(ADCSRA & 0x40) {} // Read ADC digital value return ACDW; } Question 4: Edge Detection (10 pts) The following simple block diagram illustrates how one may implement an Input Capture circuit. Name: Lab Section: An example timing diagram for capturing the rising edge of Input_signal is given below. In s...
View Full Document

## This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online