|
|||||
Chapter 3 problems |
- B3.9 - |
4-bit (nibble) shifter operator |
|||
|
1.- Specifications
In digital systems it is often necessary to have circuits that can shift the bits of a vector by one or more bit positions to the left or right. The same project is proposed in D1.9 as a combinational circuit based on logic gates.
Design a circuit that can shift a 4-bit vector W(3..0), also called nibble, one bit position to the right when a control signal SR = '1', and one bit position to the left when SL = '1'. When the control signals are not active SR = '0', SL = '0', the output is a copy of the vector W. We dont'care about the output values if by any chance both control signals are activated SR = '1', SL = '1'; assuming that this condition will nevel occur. The simbol and operations of this device are represented in Fig. 1.
Use a PIC18F4520 microcontroller, C language and Microchip IDE tools. Test your design using Proteus. Add switches to input data and control signals and LED to visualise the operations.
Fig.1. Symbol of the Shifter_4bit. |
Complete the circuit's truth table sketched in Fig. 2.
Fig.1. Truth table idea. |
Draw an example of timing diagram.
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 SL and monitor its current value var_SL in a watch window.
- step #2 read only SR and monitor its current value.
- step #3 read the vector W(3..0) and monitor its current value in a watch window. In this way, your read_inputs() function will be validated.
- step #4 Imagine a given value for the variable var_Y, write it in the corresponding pins and observe LED values, thus validating your function write_outputs().
- step #5 complete the truth table and the project.
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:
SL --> RD6; SR --> RB0; W(3..2) ---> RC(1..0); W(1..0) ---> RD(2..1); Y(5) ---> RA3; Y(4..2) ---> RB(7..5); Y(1) ---> RD4; Y(0) ---> RA2;
Pin assignment option #2:
SL --> RB0; SR --> RD6; W(1..0) ---> RC(2..1); W(3..2) ---> RD(2..1); Y(5) ---> RA2; Y(4..2) ---> RB(6..4); Y(1) ---> RA3; Y(0) ---> RD4;
Pin assignment option #3:
SL --> RC1; SR --> RD2; W(3..2) ---> RB(5..4); W(1..0) ---> RA(3..2); Y(5..3) ---> RC(7..5); Y(2) ---> RA0; Y(1..0) ---> RD(4..3)
Project location:
C:\CSD\P9\Shifter_4bit\(files)
Organise the main program in our CSD way. Copy and adapt a circuit from any of the LAB9 projects and name it Shifter_4bit.pdsprj.
Propose a hardware-software diagram naming all the electrical signals, RAM variables and the software functions.
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().
Fig. 4. Reading inputs. |
Organise using a flowchart the interface function write_outputs().
Fig. 5. Writing outputs. |
Infer the truth_table() software function using a behavioural plan B interpretation from the corresponding flowchart.
Fig. 6. Shifter_4bit initial discussion on adapting the truth table using plan B flowcharts. |
3. Developing & 4. Testing (debugging)
- Step #1. Write the Shifter_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.
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.
Fig. 8. Loop execution time measurements. |