Assume that we want to use an Analog to Digital Converter to digitize the wavefo
ID: 2084303 • Letter: A
Question
Assume that we want to use an Analog to Digital Converter to digitize the waveform shown in Fig. 1. A signal generator produces the waveform and it is connected to pin PA0 of the Arduino microcontroller. Assume that you have three functions: a function called analogPin, that defines the pin where you signal is connected to the ADC, another function called analogRead that when called returns the value of a 10-bit sample, and a Delay function that receives as a parameter the length of the delay. Give the flow diagram to write the main program that uses the analogPin, analogRead and delay functions needed to capture 50 samples per period of the given signal Write the main C program The samples should be stored in memory in an array called Samples. Clearly explain any variables that need to be used and initializedExplanation / Answer
Arduino C code:
========================
int Samples[50]={}; // Samples array declaration and initialization
void setup() {
analogPin(); // defining A0 pin as analog input
}
void loop() {
int i; // counter variable used for counting samples
for(i=0;i<50;i++){
Samples[i]=analogRead(A0); // sampling signal
Delay(25); // generating delay of 25us
}
}
void analogPin(){
pinMode(A0, INPUT);
}
void Delay(int i){
delayMicroseconds(i);
}
=========================