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

Chapter 3 problems

- B3.10 -

4-bit radix-2 /Johnson and 8-bit Johnson / radix-2 converters

Products

B3.9

B3.11


1.- Specifications

Design the 4-bit binary radix-2 to Johnson code converter represented in Fig. 1 using a PIC18F4520 microcontroller, C language and Microchip IDE tools. Test your design using Proteus. Add switches to input codes and enable signals and LED to visualise the operations.

Binary to Johnson code converter

Fig.1. Symbol of the 4-bit binary to Johnson converter.

The same project is proposed in D1.10 as a combinational circuit based on logic gates. The emphasis is focused therefore in learning how to poll/read digital inputs and write digital outputs. The truth table will be solved using a behavioural plan B interpretation translated into C language and organising the hardware-software diagram so that the input and outputs variables will be saved in RAM memory in an infinite loop.

Draw an example timing diagram.

Picture report

Fig. 2. Timing diagram example.

2. Planning

You will solve the circuit in several steps, adding a few lines of code each time to develop and test immediately to debug any error before adding more code. For instance:

- step #1 read only E and monitor its current value var_E in a watch window.

- step #2 read the vector B(3..0) and monitor its current value in a watch window. In this way, your read_inputs() function will be validated.

- step #3 Imagine a given value for the variable var_J, write it in the corresponding pins and observe LED values, thus validating your function write_outputs().

- step #4 complete the truth table and the project.

 

A) Planning hardware

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

Pin assignment option #1:

E --> RB5; B(3..2) ---> RC(1.0); B(1..0) ---> RC(7..6); J(7..4) ---> RA(3..0); J(3..2) ---> RB(7..6);  J(1..0) ---> RD(4..3)

Pin assignment option #2:

E --> RB2; B(3..2) ---> RD(1.0); B(1..0) ---> RD(7..6); J(7..4) ---> RB(6..3); J(3..2) ---> RA(3..2);  J(1..0) ---> RC(4..3)

Pin assignment option #3:

E --> RC5; B(3..2) ---> RC(1.0); B(1..0) ---> RD(5..4); J(7..4) ---> RA(4..1); J(3..2) ---> RB(5..4);  J(1..0) ---> RB(7..6)

Project location:

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

 

B) Planning software

Organise the main program in our CSD way. Copy and adapt a circuit from any of the LAB9 projects and name it Bin_Johnson_4bit.c.

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

Picture report

Fig. 3. Hardware-software diagram. 

Describe all the RAM memory variables used in this project and its type.

Explain how to configure the µC in init_system().

Organise using a flowchart the interface function read_inputs().

Picture report

Fig. 4. Reading inputs.

Organise using a flowchart the interface function write_outputs().

Picture report

Fig. 5. Writing outputs.

Infer the truth_table() software function using a behavioural plan B interpretation from the corresponding flowchart.

Picture report

Fig. 6. Bin_Johnson_48bit initial discussion on adapting the truth table using plan B flowcharts.

 

3. Developing & 4. Testing (debugging)

- Step #1. Write the Bin_Johnson_4bit.c source code translating the function flowcharts. Start capturing only one input as in (LAB9) and visualising it in the watch window as a RAM variable as indicated in the sequence of steps above in the planning section. And only then go to the next 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.

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.

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

Picture report

Fig. 7. Example pictures demonstrating how the circuit works.

Measure how long does it take to run the main loop code when using a 4 MHz and a 16 MHz quartz crystal oscillator.

Picture report

Fig. 8. Loop execution time measurements.

 


Chapter 3 problems

- B3.10 -

4-bit radix-2 /Johnson and 8-bit Johnson / radix-2 converters

Products

B3.9

B3.11


1.- Specifications

Design the 8-bit Johnson to binary radix-2 code converter represented in Fig. 1 using a PIC18F4520 microcontroller, C language and Microchip IDE tools. Test your design using Proteus.  Add switches to input codes and enable signals and LED to visualise the operations.

Johnson to binary converter

Fig.1. Symbol of the Johnson_bin_8bit converter.

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

The emphasis is focused therefore in learning how to poll/read digital inputs and write digital outputs. The truth table will be solved using a behavioural plan B interpretation translated into C language and organising the hardware-software diagram so that the input and outputs variables will be saved in RAM memory in an infinite loop.

Draw an example timing diagram.

Picture report

Fig. 2. Timing diagram example.

2. Planning

You will solve the circuit in several steps, adding a few lines of code each time to develop and test immediately to debug any error before adding more code. For instance:

- step #1 read only E and monitor its current value var_E in a watch window.

- step #2 read the vector J(7..0) and monitor its current value in a watch window. In this way, your read_inputs() function will be validated.

- step #3 Imagine a given value for the variable var_Bin, write it in the corresponding port pins and observe LED values, thus validating your function write_outputs().

- step #4 complete the truth table and the project.

 

A) Planning hardware

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

Pin assignment option #1:

E --> RB5; J(7..4) ---> RA(3..0); J(3..2) ---> RB(7..6);  J(1..0) ---> RD(4..3); B(3..2) ---> RC(1.0); B(1..0) ---> RC(7..6)

Pin assignment option #2:

E --> RB2;  J(7..4) ---> RB(6..3); J(3..2) ---> RA(3..2);  J(1..0) ---> RC(4..3); B(3..2) ---> RD(1.0); B(1..0) ---> RD(7..6)

Pin assignment option #3:

E --> RC5;  J(7..4) ---> RA(4..1); J(3..2) ---> RB(5..4);  J(1..0) ---> RB(7..6); B(3..2) ---> RC(1.0); B(1..0) ---> RD(5..4)

Project location:

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

 

B) Planning software

Organise the main program in our CSD way. Copy and adapt a circuit from any of the LAB9 projects and name it Johnson_bin_8bit.c.

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

Picture report

Fig. 3. Hardware-software diagram. 

Describe all the RAM memory variables used in this project and its type.

Explain how to configure the µC in init_system().

Organise using a flowchart the interface function read_inputs().

Picture report

Fig. 4. Reading inputs.

Organise using a flowchart the interface function write_outputs().

Picture report

Fig. 5. Writing outputs.

Infer the truth_table() software function using a behavioural plan B interpretation from the corresponding flowchart.

Picture report

Fig. 6. Johnson_bin_8bit initial discussion on adapting the truth table using plan B flowcharts.

 

3. Developing & 4. Testing (debugging)

- Step #1. Write the Johnson_bin_8bit.c source code translating the function flowcharts.  Start capturing only one input as in (LAB9) and visualising it in the watch window as a RAM variable as indicated in the sequence of steps above in the planning section. And only then go to the next 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.

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.

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

Picture report

Fig. 7. Example pictures demonstrating how the circuit works.

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

Picture report

Fig. 8. Loop execution time measurements.