Вы находитесь на странице: 1из 4

Assignment: ACS6110/SAP.

02 Name: Vishanth Vijayakumar Registration number: 130135689

Equipment used:
7-bit optical rotary encoder

Modified code:
// to continuously run the code, a for loop must be used, else the code reaches end function without reading any data for(;;) {printf("The values of port b are %d \n",*portB); // using printf to print all the values of portB on the computer screen usleep(5000); //using a small delay before printing the next value from portB }

127 was the maximum value shown.

Modified code:
1. Using function GrayDecode():

int graydecoded; //declaring variable graydecoded in the main function. for(;;) { graydecoded=GrayDecode(*portB); // the value at portB is grey decoded, by sending the data to GrayDecode() and this decoded value is stored in the variable graydecoded // the GrayDecode() is called for every value of port B. printf("The decoded values of port b are %d \n",graydecoded); //printing the grey decoded value usleep(5000); //using a small delay before printing the next gray decoded value. 2. Using function GrayDecodeTable[]:

int graydecoded; //declaring variable graydecoded in the main function. for(;;) { graydecoded=GrayDecodeTable[*portB]; // GrayDecodeTable[] calculates the gray value for all the possible values of portB printf("The decoded values of port b are %d \n",graydecoded); //printing the grey decoded value usleep(5000); //using a small delay before printing the next gray decoded value. }

The GrayDecodeTable[] might be a better option, because it calculates the gray decoded values for all the portB values, and when the particular gray value is required it is looked upon the table. While, the GrayDecode() does the calculation repeatedly for all the individual port B data, which is more time
consuming. Observation: maximum decoded value: 95 minimum decoded value: 0

int graydecoded; //declaring variable graydecoded in the main function. int degreefound; //declaring variable degreefound in the main function..

for(;;) {graydecoded=GrayDecodeTable[*portB]; // gray decoded value stored in graydecoded variable. degreefound=DecodeToDegreeTable[graydecoded]; // the grey decoded value is sent to the DecodeToDegreeTable[]; this value is converted to degrees and is stored in the variable degreefound printf("The decoded values of port b are %d \n",degreefound); //print the degree , by printing the variable degreefound. usleep(5000); //using a small delay before printing the next angle. } Observation: maximum angle: 360 minimum angle: 0

The angular precision is 3.7895 according to the code, but practically the outputs has a difference of 4 degrees between them. Practical angular precision is 4 degrees

int graydecoded; //declaring variable graydecoded in the main function. int degreefound; //declaring variable degreefound in the main function. for(;;) { old_angle=*portB; // copying value of portB into old_angle variable graydecoded=GrayDecodeTable[*portB]; // gray decoded value stored in graydecoded variable. degreefound=DecodeToDegreeTable[graydecoded]; // the grey decoded value is sent to the DecodeToDegreeTable[] if(old_angle != new_angle) // checks if old angle equals new angle, if not proceeds with the loop { printf("The decoded values of port b are %d \n",degreefound); //print the degree , by printing the variable degreefound. new_angle=*portB; // copying value of portB into new_angle variable } usleep(5000); } This code updates the old_angle with the port B value first , then does the decoding and prints the value if the old value is not equal to the new value. Then the port B value is copied to new_angle variable.

Essentially old_angle has the older variable by one iteration, and its checked with new_angle to check whether the consecutive angles are same or not.

The angle can be updated faster by reducing the pause time. As we had a pause time of 5000ms , any time lesser would give a faster update.

Вам также может понравиться