The document discusses exercises related to analog to digital conversion (ADC) and digital to analog conversion (DAC). It provides code to:
1. Initialize the ADC peripheral and configure pin PC4 as an analog input.
2. Take a single ADC reading in polling mode and calculate the average of multiple readings to smooth the results.
3. Display the analog input value as a bar of LEDs, with the number of lit LEDs corresponding to the input voltage level.
The document discusses exercises related to analog to digital conversion (ADC) and digital to analog conversion (DAC). It provides code to:
1. Initialize the ADC peripheral and configure pin PC4 as an analog input.
2. Take a single ADC reading in polling mode and calculate the average of multiple readings to smooth the results.
3. Display the analog input value as a bar of LEDs, with the number of lit LEDs corresponding to the input voltage level.
The document discusses exercises related to analog to digital conversion (ADC) and digital to analog conversion (DAC). It provides code to:
1. Initialize the ADC peripheral and configure pin PC4 as an analog input.
2. Take a single ADC reading in polling mode and calculate the average of multiple readings to smooth the results.
3. Display the analog input value as a bar of LEDs, with the number of lit LEDs corresponding to the input voltage level.
The document discusses exercises related to analog to digital conversion (ADC) and digital to analog conversion (DAC). It provides code to:
1. Initialize the ADC peripheral and configure pin PC4 as an analog input.
2. Take a single ADC reading in polling mode and calculate the average of multiple readings to smooth the results.
3. Display the analog input value as a bar of LEDs, with the number of lit LEDs corresponding to the input voltage level.
Download as DOCX, PDF, TXT or read online from Scribd
Download as docx, pdf, or txt
You are on page 1of 2
EEET2096 Tutorial Exercises ( week10)
Exercises on ADC & DAC
1. One of the 16 ADC external inputs is connected to a potentiometer to pick an analogue voltage value in the board used in the lab. Give the pin and the port of this ADC inputs. 2. Give the code for the ADC AF configuration ( related to Q1) . RCC->APB2ENR |= (1<<0);
3. Give the code necessary to initialise the operation of the ADC ( Related to Q1). GPIOC->CRL &= 0x000F0000; // set GPIOC pin 4 as analog input RCC->APB2ENR |= (1<<9); // Now we enable clock for ADC // The sequence registers for the ADC is all cleared to 0, // except bit 14 of SQR3, in order to configure ADC 3 // and to configure the sample time for channel 14 in the SMPR1 ADC1->SQR1 = 0x00000000; ADC1->SQR2 = 0x00000000; ADC1->SQR3 = (14<<0); ADC1->SMPR1 = (3<<12); // The ADC uses the alternate function (AF), so RCC->APB2ENR |= (1<<0); // enable peripheral clock for AF // Now we configure the ADC using the CR2 register, // Where we configure it to run on an external trigger (bit 20) // and SWSTART bits (17:19), then we enable continuous // conversion (bit 1) and turn the ADC to ON (bit 0) // then last we set right alignment (by clearing bit 11) ADC1->CR2 = ((1<<20) | (7<<17) | (1<<1) | (1<<0)); ADC1->CR2 &= ~(1<<11); ADC1->CR2 |= (1<<3); // Now we Reset the ADC (bit 3) while(ADC1->CR2 & (1<<3));// Wait till reset finished ADC1->CR2 |= (1<<2); //then start Calibration (bit 2) while(ADC1->CR2 & (1<<2))// Wait till calibration finished // We then have to turn the ADC on again ADC1->CR2 |= (1<<0);
4. With 12 bit ADC, what is the half value of the maximum reading? 2048
5. Give the code to implement the following ADC operation. ( polling & interrupt) [ Note: You can refer to lecture notes and the sample program blink]
6. Explain why the following formula can smooth the reading. V_new = [ V_old * (n-1) + New_Reading] / n; 7. Design the code for the LED bar to indicate the ADC value. Min ADC value : All LEDs off Value in between: height reflect the value Max ADC value: All LEDs O GLCD_DisplayString(2,0,buffer); // Cast average value to a float adc_test = average_val; // And normalize it according to max reading adc_test = (adc_test/3750)*8; // Then cast it back to integer led_val = adc_test; // Display this value as an LED bar GPIOE->ODR = 0xFF<<led_val; average_val = 0; // Reset average value