UPC EETAC Bachelor's Degree in Telecommunications Systems and in Network Engineering EEL

Chapter 3 problems

      - B3.12 -

5-bit Gray to binary and binary to Gray code converters

Problems

B3.11

B3.13


Project option #1: 5-bit Gray to binary converter                   Project option #2: 5-bit binary radix-2 to Gray converter      

1.- Specifications

Design the 5-bit Gray to binary radix-2 code converter represented in Fig. 1 using plan B and a microcontroller PIC18F4520.

The same project is proposed in D1.12 as a combinational circuit based on logic gates.

5-bit Gray to bin converter

Fig.1. Symbol of the Gray_bin_5bit converter.

Use this project to review basic concepts on μC as theory attached to the specifications section.

 

2. Planning

A) Planning hardware

Copy and adapt a circuit from any of the previous projects (LAB9) and name it Gray_bin_5bit.pdsprj. Assign pins to inputs and outputs accordingly to one of the following options (your instructior will tell you which):

Pin assignment option #1:

G4 --> RC7; G3 --> RC4; G2 --> RC3; G1 --> RB6; G0 --> RA1

Y4 --> RA3; Y3--> RC5; Y2 --> RD7; Y1 --> RD2; Y0 --> RB1

Pin assignment option #2:

G4 --> RC6; G3 --> RC7; G2 --> RD3; G1 --> RB4; G0 --> RA0

Y4 --> RA2; Y3--> RD5; Y2 --> RB7; Y1 --> RD2; Y0 --> RC1

Pin assignment option #3:

G4 --> RB7; G3 --> RC2; G2 --> RC1; G1 --> RD6; G0 --> RA2

Y4 --> RA0; Y3--> RC3; Y2 --> RD4; Y1 --> RD1; Y0 --> RA2

Project location:

C:\CSD\P9\Gray_bin_5bit\(files)

 

B) Planning software

Organise the main program in our CSD way.

Propose a hardware-software diagram naming all the electrical signals, RAM variables and the software functions.  

Explain how to configure the µC in init_system(). List all RAM variables required and their type.

Organise using a flowchart the interface function read_inputs().

Organise using a flowchart the interface function write_outputs().

Infer the truth_table() software function using a behavioural interpretation and the corresponding flowchart.

 

Developing & testing (debugging)

Write the Gray_bin_5bit.c source code translating the function flowcharts. Start capturing only one input as in (LAB9) and visualising it in the watch window. And only then go step by step developing & testing more inputs. 

Start a software IDE project for the target microcontroller PIC18F4520 and generate the configuration files ".cof" and ".hex" after compilation. Discuss the project summary: % of ROM used for the code, number of RAM bytes used, etc.

Add a few lines of code every time, compile and run the test intereactively to check results watching variables.

Note: Step-by-step tactical approach for developing and testing the project: Read one input at a time and run to check that the voltage value is correctly captured as a valid digital value in RAM memory. Write one output at a time and run to check that your code is correct to light the LED connected at the output pin.

Measure how long does it take to run the main loop code when using a 4 MHz and a 20 MHz crystall oscillators.

 



Project option #2: 5-bit binary radix-2 to Gray code converter

1.- Specifications

Design the 5-bit binary radix-2 to Gray code converter represented in Fig. 1 using plan B and a microcontroller PIC18F4520. The same project was proposed in D1.12 as a combinational circuit based on logic gates.

5-bit Bin to Gray converter

Fig.1. Symbol of the Bin_Gray_5bit converter.

Use this project to review basic concepts on μC as theory attached to the specifications section.

 

2. Planning

A) Planning hardware

Copy and adapt a circuit from any of the previous projects (LAB9) and name it Bin_Gray_5bit.pdsprj. Assign pins to inputs and outputs accordingly to one of the following options (your instructior will tell you which):

Pin assignment option #1:

X4 --> RA3; X3--> RC5; X2 --> RD7; X1 --> RD2; X0 --> RB1

G4 --> RC7; G3 --> RC4; G2 --> RC3; G1 --> RB6; G0 --> RA1

Pin assignment option #2:

X4 --> RA2; X3--> RD5; X2 --> RB7; X1 --> RD2; X0 --> RC1

G4 --> RC6; G3 --> RC7; G2 --> RD3; G1 --> RB4; G0 --> RA0

Pin assignment option #3:

X4 --> RA0; X3--> RC3; X2 --> RD4; X1 --> RD1; X0 --> RA2

G4 --> RB7; G3 --> RC2; G2 --> RC1; G1 --> RD6; G0 --> RA2

Project location:

C:\CSD\P9\Bin_Gray_5bit\(files)

 

B) Planning software

Organise the main program in our CSD way.

Propose a hardware-software diagram naming all the electrical signals, RAM variables and the software functions.  

Explain how to configure the µC in init_system(). List all RAM variables required and their type.

Organise using a flowchart the interface function read_inputs().

Organise using a flowchart the interface function write_outputs().

Infer the truth_table() software function using a behavioural interpretation and the corresponding flowchart.

 

Developing & testing (debugging)

Write the Bin_Gray_5bit.c source code translating the function flowcharts. Start capturing only one input as in (LAB9) and visualising it in the watch window. And only then go step by step developing & testing more inputs. 

Start a software IDE project for the target microcontroller PIC18F4520 and generate the configuration files ".cof" and ".hex" after compilation. Discuss the project summary: % of ROM used for the code, number of RAM bytes used, etc.

Add a few lines of code every time, compile and run the test intereactively to check results watching variables.

Note: Step-by-step tactical approach for developing and testing the project: Read one input at a time and run to check that the voltage value is correctly captured as a valid digital value in RAM memory. Write one output at a time and run to check that your code is correct to light the LED connected at the output pin.

Measure how long does it take to run the main loop code when using a 4 MHz and a 20 MHz crystall oscillators.