upc eetac_1 Bachelor's Degree in Telecommunications Systems and in Network Engineering

P9

Project P10: Let's program a μC in C like a FSM. Interrupts.

P11


4-bit serial transmitter

1. Specifications

Let's design a simple 2-wire asynchronous data transmitter based on a µC for sending to another computer a nibble (4-bits) of data. It is basically a right-shift register as studied in this tutorial in P7.

The target chips is the PIC18F4520.

We'll use the FSM style of programming in C language. The format for the serial output once the start-transmission (ST) rising edge is detected by means of an interrupt is: Start bit ('0'), Data_in (0), Data_in (1), Data_in (2), Data_in (3); and then the end-of-transmission EoT pulse is generated to indicate that the transmitter has ended the process. Serial_out is held high when idle.   

Symbol

Fig 1. Symbol for the 4-bit serial transmitter.

Fig. 2 shows an example of timing diagram to transmit data when the ST pulse is detected.

Timing

Fig 2. Example of a section of a timing diagram where it can be seen how the data is read and right shifted in a single wire.

Learning materials and theory:

Study these tutorials and run them in Proteus to see how the system works and can be programmed taken advantage of all your previous knowledge from Chapter 2.

LAB#10Counter_BCD_1digit . Plan X: current_state is an state enumeration.

- LAB#10.  Counter_mod1572. Plan Y: current_state is a variable type char, int, etc. that can contain any value. 

Examples for other μC:

- On the design of the 74HCT4017 chip (5-bit Johnson /one-hot counter) (PIC16F877A) . Another specifications for a 6-bit Johnson counter.

- This a tutorial example (PIC16F877A) on the use of the Port B and external INT interrupts. Class discussion (1), (2). This is the adaptation when using this demonstration board.

This is a list of some more introductory topics on microcontrollers. Pay attention to the idea of external interrupt and how they are handle by the μC in hardware (INT0IF) and by our application in software (Var_CLK_Flag).

 

2. Planning

 

 

Fig. 3. Interrupt logic and the way to detect a signal edge event.

 

In Fig.4 there is the representation of the hardware-software diagram.

Hardware-software diagram
Fig. 4. This diagram connects in a convenient way the hardware section and the software functions for better understanting the idea of programming FSM. 

In Fig. 5 there is the representation of the RAM memory required in this project.

RAM Fig. 5.  We'll use six bytes of RAM to store the variables.

Hardware. Some pins must be selected to be inputs and outputs.This is a file Serial_transmitter.pdsprj containing the circuit represented in Fig. 6. Be aware that ST and CLK imputs must be connected to external interrupts like INT1/RB1 and INT0/RB0.

Software. Copy and adapt a previous example of FSM organisation in software.

- Draw the state_logic() truth table and flowchart.

- Draw the output_logic() truth table and flowchart.

 

3. Development

The planning ideas in the previous section are translated to a C source file to Serial_transmitter.c to start a new IDE project targetting a PIC18F4520.

Circuit
Fig. 6. The proposed circuit running the final executable "*.cof" to be able to debug errors and step by step mode.

 

4. Testing 

These are the project files where the Serial_transmitter.pdsprj run in Proteus environment.

 

Waves Fig. 7.  Waveforms captured in Proteus showing the transmission of the four bytes once the start bit is low. 

5. Report

Your class attendance is required and better adopting an active attitude; it is highly recommended you engage in the project discussions, rising questions and giving answers.

Project report starting with the template sheets of paper, scanned figures, file listings, docx , pptx, or any other resources.  

Remember that at this point in the course, you'll have to be able to explain any section of your project individually or in group using sketches, diagrams, and other engineering tools. 

This document may become a tutorial report on the project. Later, it can be written in a word processor, but now it is better in handwriting for better discussion, finding errors and adding new features and improvements.

 

6. Prototyping

You're invited to download the application to a given training board an verify that it works as expected and the same as in the simulator.

 

Other similar projects on sequential circuits

Books, web pages, etc.

- Exams, questions, problems and projects

- A good example to see how the interrupt mechanism works is for instance: modify the 1-digit BCD adder so that the truth table is calculated only when a EXEC pushbutton is pressed. Hardware flag: INT0F, software variable: var_EXEC_flag.

 

Other materials of interest

Hundreds of books, thousands of web pages, videos, webinars, slides, etc. on microcontrollers.