. Assume that we want to use an Analog to Digital Converter to digitize any Anal
ID: 3711427 • Letter: #
Question
. Assume that we want to use an Analog to Digital Converter to digitize any Analog signal that is connected to the Arduino. An external signal generator produces the waveform to be converted and it is connected to one of the analog pins of the Arduino microcontroller . Assume that you have a function named ADC that receives three parameters: a parameter called analogPin, that defines the pin where you signal is connected to the ADC, another parameter that specifies the number of samples called No_Samples, and a parameter called Sampling Period that specifies how often a sample should be taken parameter the length of the delay. that when called returns the value of a 10-bit sample Questions * Give the flow diagram for the implementation of the function, * Give the flow diagram for the implementation of the main program that calls the function, the main program should receive from the keyboard the values of the following three variables: n- number of samples,f- Maximum frequency of the signal to convert, and p- analog pin where the signal is connected. After these variables are received, the main program should call the ADC function needed to capture n samples per period of the given signalExplanation / Answer
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);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.