upc eetac_1

P8

Project P9: Introducing the microcontroller (μC)

P10


Commercial devices, IDE, program flow in C and basic I/O

1. Specifications

- The aim of this project is to solve a combinational circuit 1-digit BCD adder (Adder_BCD_1digit) using a microcontroller μC). This goal implies:

1) Getting in touch with a commercial device from Microchip, for instance the PIC18F4520, learning how to compile a C language code and simulate the project using Proteus. And also:

2) Pay attention on how the C code is organised and how to configure digital inputs and outputs and connect program variables to pins using bitwise operations (OR, AND, etc.)

sYMBOL

Fig 1. The symbol (visio) of the 1-digit BCD adder indicating where to connect the input and output ports.

Solve the truth table of this device which is very similar to the classic chip MC14560  represented in Fig. 2.

You may wonder why an error signal is required in this chip.

MC560
Fig 2. The classic chip MC14560 that we try to recreate as a way to learn on digital inputs and outputs and code organisation in a microcontroller. This chip is not new for you because it could have been proposed in P3 as another arithmetic circuit, thus we'll concentrate our efforts in the new μC technology to implement it.

Learning materials and tutorials:

Let's go to the laboratory to discover the new set of tools to work with micrcocontrollers. The teaching method is project-based learning (PBL) designing practical examples. Even if you find it confusing or somewhat disorganised we assure you that there is nothing like learning by doing practical examples and at the same time studying the required theory.

LAB#9. This is the tutorial Dual_MUX4

- Basic concepts on microcontrollers, chips, tools and some books on the subject.

- Bitwise operations. This is an example on how to read/poll/capture a signal connected to a uC pin and convert it into a convenient RAM variable pin (1). [Let's use the concept sampling later in P10 where we'll be able to implement such device as a CLK for synchronising operations, which, as you know, is the key for sampling inputs periodically at a give rate as in the previous Chapter 2].

- Bitwise operations. These are examples on how to write to a port a given RAM variable (1) - (2).  

 

2. Planning

 1) Project locations and file names:

<disk>/CSD/P9/Adder_BCD_1digit/(files)

2) Hardware. Draw your circuit in a sheet of paper and discuss where to connect: Reset (CD), crystall oscillator and digital I/O.

3) Our CSD style is reflected in the hardware/software diagram. The key point is to define RAM variables (char, int, double int, etc.) that will allow the processing of the algorithms without regarding the way the PORT pins have been read or written. Thus, the kernel of the code (in this case the truth_table() function) is hardware independent. Pay attention on hardware-dependent functions (input, output and system initialisation) and software (or platform independent) functions (the truth table) which is drawn using a different colour.

3) Software. Organise the code as in Fig. 4 using a program flowchart: Init_system(), read_inputs(), truth_table() (which is the algorithm or data processing)  and write_outputs().

software
Fig. 4.  Software organisation for this simple example.
variables

Fig. 5.  Example of some convenient variables "Var" that will allow the processing of information in truth_table() independently of the microcontroller hardware. 

Program variables will be stored in RAM memory addresses and so, they are volatile.

4) Plan a sequence for building and debugging the application: the idea is "plan & develop & test" step by step introducing a few lines of code at a time. For instance:

1) Solve the code for reading only the Cin pin, compile, run and test the Var_Cin variable using the watch window.

2) Add the code for reading only the operant A, run and test it, etc.

NOTE: You may also consider several design phases. For instance:

Phase#1. Solve the circuit using only switches, buttons and LED as represented in Fig. 7. And only when the system is working correctly,

Phase#2.  Add the extra RAM variables and modify the hardware and software to interface the 7-segment display as represented in Fig. 6.

3. Development

1) Hardware. Draw the schematic of the application in Proteus copying an example or tutorial which already contains the microcontroller that you have to use.

Development
Child Sheet
Fig. 6. The Adder_BCD_1digit symbol and electrical connections as captured in Proteus. Below you can see the internal architecture (child sheet) based on the PIC18F4520 where only some connections are completed.

2) Software. Run the microcontroller's IDE to develop and compile the C code copying and adapting an example code. NOTE: If your project was created in a previous session and you like to continue working with it, simply click Open project and select the folder.

Do it step by step according to your plan, testing if it works before adding new code. For example, as indicated in the planning above, complete the operations for watching the Var_Cin variable; then repeat it all for watching the variable Var_A, and so on. Use tutorial examples to copy and adapt the C source file. Remember that, as usual, C code is not valid unless you are translating a flow chart which is at the same time the translation of some algorithm.

 

4. Testing 

) Run the Proteus simulator. Do it in step by step mode while watching variables and placing break points..

Test
Fig. 7.  The circuit in "run" mode while monitoring the variables in the "watch" window.

5. Report

Having solved this introductory project, also means that you are able to answer most of the questions listed here.

Do you become fully aware now on how designing an example also means learning the "theory" ?:

Having solved the project in paper, you are always in time to publish your project report using a word processor: scanned figures, file listings, docx , pptx, or any other resources.  

Remember that in class you'll be required to explain any section of your project individually or in group.

 

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

Books, web pages, etc.

By the way, the Arduino platform is another microcontroller which has become famous, so that you can program it using "*.ino" source files and its development environment, or instead using "*.c" files and Atmel Studio IDE. Remember that at the EETAC we have the academic license to simulate Arduino boards and applications in Proteus. Hence, you are invited to try your own projects. This is a sample.

- Exams, questions, problems and projects

 

Other materials of interest

Indeed, there are thousands of resources in books and through the internet to learn the basics on microcontrollers (microprocessor, program memory, RAM memory, I/O, peripherals, etc.). For instance (1), from where this image in Fig. 7 is taken:

pic-microcontrollers-examples-in-assembly-language-fig0-1

Fig. 8.  The idea of a microcontroller (or microcomputer) integrating many dedicated peripherals, memory and a microprocessors in a single chip.