2. Analog to Digital Conversion ICC-12 (by using chip M68HC12) In this lab you w
ID: 673975 • Letter: 2
Question
2. Analog to Digital Conversion ICC-12 (by using chip M68HC12)
In this lab you will use the potentiometers (pots) provided as the source of analog parameters. The two end pins will be connected to 5V and GND respectively. The variable pin (center pin) will be connected to the analog input pins (PORT AD pins) of the 6812. After commanding the 6812 to perform the A to D conversion (example code on pages 273-275 of the text ) the digitized values will be read from the registers ADRnH. One pot will cause the frequency to vary from 500 Hz (corresponding to digital value 0) to 5000 Hz (corresponding to digital value 255) . Similarly another pot will cause the duty cycle from 10% to 90%.
Explanation / Answer
/*
Function: uppercaseMethod
Purpose: Converts all lower case letters found within the line to uppercase
*/
void * uppercaseMethod(void *arg)
{
int i;
for(i = 0; i < 63; i++)
{
if(islower(input[i]))
{
input[i] = toupper(input[i]);
}
}
}
/*
Function: writeMethod
Purpose: Writes formatted line to screen and file
*/
void * writeMethod(void *arg)
{
int m;
char e, d;
Queue obj;
if(input != " ")
{
for(m = 0; m < input.length(); m++)
{
e = input[m];
obj.Enqueue(e);
}
for(m = 0; m < input.length(); m++)
{
d=obj.Dequeue(d);
}
cout << " Line " << lineNum << ": ";
cout << input << endl;
outFile << input << endl;
lineNum++;
}
}
/*
Function: readerMethod
Purpose: Reads each line from file
*/
void * readerMethod(void *arg)
{
ifstream infile("file.txt");
cout << "The file is now opened!" << endl;
cout << " Reading input file now..." << endl;
cout <<" _________________________________ " << endl;
for(m = 0; m < input.length(); m++)
{
e = input[m];
obj.Enqueue(e);
}
for(m = 0; m < input.length(); m++)
{
d = obj.Dequeue(d);
cout << " Line " << lineNum << " : ";
cout << input << endl;
outFile << input << endl;
lineNum++;
}
/*
Function: readerMethod
Purpose: Reads each line from file
*/
void * readerMethod(void *arg)
{
ifstream inFile("file.txt");
cout << "The file is now opened!" << endl;
cout << " Reading input file now..." << endl;
cout <<" _________________________________ " << endl;
while(!inFile.eof())
{
getline(inFile, input);
int i;
for(i = 0; i < input.length(); i++)
{
if(i >= 63)
{
string j;
j = "";
input[i] = j[0];
}
}
symbolMethod(NULL);
uppercaseMethod(NULL);
writeMethod(NULL);
}
inFile.close();
outFile.close();
return NULL;
}
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
int main(int argc, char **argv)
{
int argc, char **argv
pthread_t reader, munch1, munch2, writer; //Create the four threads
pthread_mutex_lock(&mutex1);
// produces error messages when a thread cannot be created
if(pthread_create(&reader, NULL, readerMethod, Null))
{
cout << " !!Reader Thread could not be created!! ;
return -1;
}
pthread_mutex_unlock(&mutex1);
else if(pthread_create(&munch1, NULL, symbolMethod, NULL))
{
cout << " !!Reader Thread could not be created!! ;
return -1;
}
else if(pthread_create(&munch2, NULL, uppercaseMethod, NULL))
{
cout << " !!Reader Thread could not be created!! ;
return -1;
}
else if(pthread_create(&writer, NULL, writeMethod, NULL))
{
cout << " !!Reader Thread could not be created!! ;
return -1;
}
//Produces error messages when a thread cannot be joined
if(pthread_join(reader, NULL)
{
cout << " !!Could not join thread!! ";
}
else if(pthread_join(munch1, NULL))
{
cout << " !!Could not join thread!! ;
return -1;
}
else if(pthread_join(munch2, NULL))
{
cout << " !!Could not join thread!! ;
return -1;
}
else if(pthread_join(writer, NULL))
{
cout << " !!Could not join thread!! ;
return -1;
}
cout << " The file contains " << lineNum-1 << "line(s) of input. ";
cout << "---------------------------------------------------- " << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.