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

Chapter 3 problems

      - B3.6 -

Water tank level meter (μC - C)

Products

B3.5

B3.7


1.- Specifications

Create the circuit Tank_level_meter represented in Fig. 1 using plan B and a microcontroller PIC18F4520.

The same project is proposed in D1.6 as a combinational circuit based on logic gates.

tank schematic

Fig.1. The tank level meter idea built using digital optical sensors (1), (2) attached to  the tank wall. 

Use this project to review basic concepts on μC as theory attached to the specifications section.

2. Planning

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(8..7) ---> RA(1..0)

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

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

S(2..0) ---> RA(4..2)

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

E  ---> RD6

Pin assignment option #2:

S(8..7) ---> RB(5..4)

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

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

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

Y(3..0) ---> RD(7..4)

E  ---> RC2

Pin assignment option #3:

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

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

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

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

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

E  ---> RC6

Project location:

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

 

B) Planning software

a) Organise the main program in our CSD way.

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

In this project we capture/read a 9-sensor input vector, thus the right variable size is var_S (int type) that will save the value in the 9 least significant bits of the variable: var_S = "0 0 0 0 0 0 0 S8 S7 S6 S5 S4 S3 S2 S1 S0"

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

d) Organise using a flowchart the interface function read_inputs().

e) Organise using a flowchart the interface function write_outputs().

f) 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 12 MHz quartz crystall oscillators.