Chapter 3 problems |
- D3.22 - |
Bit pattern generator (µC - C) |
1. Specifications
Design a 12-bit pattern generator using a PIC18F46K22.
Configure four transmission speeds (CLK frequency) using the two CF bits.
M bit will set single-frame or repeated transmission frames.
S bit determines what to transmit: 12-bits of user raw data, or a byte of data using a serial standard.
After the initial MCLR_L signal, and before sequencing the bit stream, the device waits for two start-pattern (SP) push-button clicks. The first click is for inputting the high byte of Din(15..8); the second click is for inputting the low byte of Din(7..0).
The green LED (LED_g) will be lit while waiting for the second SP click.
The red LED (LED_r) will be lit while transmitting.
In the design phase #1, the CLK signals are derived from an external oscillator. This signal is also replicated as the output CLK_out.
To convey and serialise the data to a single output, Serial_out, the key component is a datapath containing a 12-bit left-shift register. It is a uint8_t RAM memory position that will also work as a rotator for continuous transmissions.
The same project designed using hardware is shown in D2.22.
![]() |
| Fig. 1. Symbols and features. |
Some example patterns are represented in Fig. 2.
![]() |
| Fig. 2. Bit pattern examples. |
Discuss the given specifications. Which inputs are required to be external interrupt sources?
2. Planning
The product will be developed by organising several design phases, with multiple steps within each phase.
Design phase #1: basic features
Solve the circuit for this design step #1. Only when it is fully tested, working correctly and reported, solve design step #2.
Design step #1. Start/stop a 12-bit example pattern stream, for instance, "100111101010". When the user clicks PB_L, the sequence is generated continuously at the TCLK bit rate. Clicking the same button again stops the pattern generation.
Project location:
C:\CSD\P10\P_gen_12bit_s1\(files)
Project source files:
"P_gen_12bit.pdsprj", "P_gen_12bit.c"
Copy and adapt a circuit from a convenient tutorial project and name it "P_gen_12bit.pdsprj".
a) Draw the hardware schematic necessary for step #1, as shown in Fig. 3. Assign pins to inputs and outputs. Explain how to configure the inputs and outputs in init_system().
![]() |
| Fig. 3. Step #1 hardware to be captured in Proteus. |
b) Draw the state diagram indicating how the state transitions will work. What outputs are in each state?
- What variables are required?
![]() |
Fig. 4. Idea of state diagram controlled by interrupt flag variables. |
c) Draw the hardware/software diagram indicating the required RAM variables and how the FSM is solved in software.
- What variables are required?
- At this initial step, what signals will be read, if any, and when? Organise read_inputs().
- Organise write_outputs().
- The interrupt sources: do they have to be enabled all the time?
d) Draw the truth tables and their equivalent flowcharts for state_logic() and output_logic() functions.
e) What is the interrupt service routine ISR() used in this application? Draw its flowchart.
f) Develop and test (debug) the project by capturing the hardware circuit in Proteus and writing the C source code (as indicated: always copying and adapting from digsys examples) .
Design step #2. CLK rates, single pattern or continuous mode. The pattern to generate and transmit and the transmission configuration bits are input in two steps using 8 switches attached to port RC(7..0)
Inherit the step #1 source hardware and software files into the new location.
Project location:
C:\CSD\P10\P_gen_12bit_s2\(files)
Project source files:
"P_gen_12bit.pdsprj", "P_gen_12bit.c"
a) Draw the hardware schematic necessary for step #2. Add the new switches and the green LED. Explain how to configure it in init_system().
Organise and explain what is new in sections b), c), d), e), f)
Develop and test the new features.
Design step #3. Implement the S function: 12-bit raw generation or standard byte serial as shown in Fig.1.
Inherit the step #2 source hardware and software files into the new location.
Project location:
C:\CSD\P10\P_gen_12bit_s3\(files)
Project source files:
"P_gen_12bit.pdsprj", "P_gen_12bit.c"
To implement this last step, we use the same hardware.
Organise and explain what is new in sections b), c), d), e), f)
Develop and test the new features.
Let us add an LCD display, as studied in P11, to this application. Print the 12bit pattern generated as a text string, the transmission speed and the configuration parameters.
Project location:
C:\CSD\P11\P_gen_12bit\(files)
Project source files:
"P_gen_12bit_LCD.pdsprj", "P_gen_12bit_LCD.c"
g) Enhance the schematic from the previous design phase #1 to include an LCD attached to port D as studied in tutorials.
h) Enhance the software and the source file to drive the LCD.
Develop and test the new feature.
Design phase #3: Using the TMR2 peripheral subsystem.
Design step #1.
The external sampling CLK is replaced by the internal 8-bit TMR2 peripheral to generate interrupts (TMR2IF). Discuss the main features of this peripheral and its applications.
Project location:
C:\CSD\P12\P_gen_12bit\(files)
Project source files:
"P_gen_12bit_LCD_TMR2.pdsprj", "P_gen_12bit_LCD_TMR2.c"
i) Calculate TMR2 parameters required to generate a CLK of 8 Hz (var_CLK_flag period = 125 ms) to acquire the pattern and run the machine, replacing the external CLK signal.
Develop and test the new feature.
Optional design step #2.
j) Add the TMR0 to generate a new switch-off (sleep mode) signal after 1 min of inactivity.
Project location:
C:\CSD\P12\P_gen_12bit_LCD_TMR2_sleep\(files)
Project source files:
"P_gen_12bit_LCD_TMR2_sleep.pdsprj", "P_gen_12bit_LCD_TMR2_sleep.c"
Develop and test the new feature.
Optional design step #3.