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

Chapter 3 problems

      - B3.6 -

Water tank level meter

Problems

B3.5

B3.7


1. Specifications

As an alternative to the hardware design proposed in D1.6 , create the circuit Tank_level_meter represented in Fig. 1 using plan B and a microcontroller PIC18F4520.

Tank level meter

Fig.1. The tank level meter idea built using level sensors attached to  the tank wall.

This circuit has a particular truth table. The sensors generates a '1' when covered in water, thus only a Johnson output code is possible, as shown in Fig. 2 truth table.

 truth table

Fig.2. Truth table definition with 120 combinations where the code is not necessary because an error condition will be displayed instead. This circuit has an incomplete truth table.

Draw an example of timing diagram to be used later as stimulus in the Proteus simulation of the circuit. 

 

A) Planning hardware

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

Pin assignment option #1:

S(6..5) ---> RB(7..6)

S(4..3) ---> RC(1..0)

S(2..0) ---> RA(3..1)

Y(2..0) ---> RD(3..1)

E  ---> RD(6)

Pin assignment option #2:

S(6..5) ---> RC(7..6)

S(4..3) ---> RA(1..0)

S(2..0) ---> RB(3..1)

Y(2..0) ---> RD(7..5)

E  ---> RC(2)

Pin assignment option #3:

S(6..5) ---> RD(7..6)

S(4..3) ---> RB(1..0)

S(2..0) ---> RC(3..1)

Y(2..0) ---> RA(3..1)

E  ---> RC(6)

Project location:

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

 

B) Planning software

Organise the main program in our CSD way.

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

Explain how to configure the µC in init_system(). List all RAM variables required and their type.

Organise using a flowchart the interface function read_inputs().

Organise using a flowchart the interface function write_outputs().

Infer the truth_table() software function using a behavioural interpretation and the corresponding flowchart.

 

Developing & testing (debugging)

Write the Tank_level_meter.c source code translating the function flowcharts. Start capturing only one input as in (LAB9) and visualising it in the watch window. And only then go step by 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; the output pin have the correct digitl value, for example turning on or off a LED.

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

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