upc eetac_1

Project P10: Let's program a FSM

Counters and other basic sequential applications

6-bit Johnson counter

1. Specifications

- Implement a 6-bit Johnson counter using a microcontroller chip. The program is organised mimicking a FSM  and interrupt-driven to attend edge-triggered inputs from pushbuttons or other external digital signals.

Well, as you see, it looks that simply once again we are revisiting the same circuits from Chapter 2. However, it is not only so, because in the end, comprehending correctly the basic behaviour of such simple systems will give you a great advantage when considering larger and far more complex systems. This P10 is like the key to open the door of professional embedded microcontroller applications (data logging, signal acquisition and distribution, motors, LED lamps control, robotics, etc.).


Fig 1. Circuit to be designed using interrupts to detect edge transitions (visio).

- 6-bit reversible Johnson counter (UD_L signal)

- Count enable (CE signal switch)

- Start/stop button (ST_SP) to trigger the operation and to stop it once the sequence has ended. Sensitive to the falling edge.

- The counter advances synchronously on the falling edge of an external CLK input of 2.5 Hz.

- TC (terminal count) is an squared signal which is high in half of the states and low in the other half.

Follow the discussion in class (1), (2) in class to fully understand the specifications and be able to infer a plan.

Learning materials and tutorials:

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

- New version of the BCD counter (PIC18F4520). Plan: current state is an state enumeration.

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

- On the design of the 74HCT4017 chip (5-bit Johnson /one-hot counter).

- Old version of the BCD counter using FSM style with state enumeration. (PIC16F877A, PIC18F452, ATmega8535, PIC18F4520). Plan: current state is an state enumeration.

- Old version of a large binary counter in FSM style. Plan: current state is a variable.

- 16-key matrix encoder.


2. Planning

Some initial notes on a feasible plan that, as you see, mixes hardware and software. 

1) Project locations and file names. Place the project folder in your Samba drive Z, L, etc.:


2) Organise the hardware. Draw your circuit in sheets of paper and discuss where to connect: Reset (CD), CLK oscillator, digital I/O and push-buttons. A good idea is to connect inputs and outputs in the free pins of a development board like the PICDEM2 Plus, in case you would like to prototype the application.

3) Organise the C code using a FSM-like program flowchart: Init_system(), output_logic(), state_logic(), ISR() (interrupt service routine). Design the hardware-dependent functions read_inputs(), write_outputs(). Define the RAM internal variables that will allow the FSM sequencing using convenient flags, like CLK_flag and ST_Flag.  Class notes: (1), (2), (3).



Fig. 2. General interrupt-driven FSM-style program organisation (visio).


4) Plan a sequence for building and debugging the application: as is P9 the idea is "plan & develop & test" step by step enhancing the initial state diagram with a new features at a time. For instance: 1) solve a basic up Johnson counter with an Start/Stop button; 2) add the up/down switch; etc. 


3. Development

1) Draw the schematic of the application in Proteus copying and adapting an example or tutorial.

Fig. 3. The counter as captured in Proteus.

2) Run the microcontroller's IDE to develop and compile the C code copying and adapting an example.  Do it section by section according to your plan, testing if it works before adding new code.


4. Testing 

 Run the Proteus simulator. Do it in step by step mode while watching variables and placing break points, specially to follow the interrupt flags.


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


5. Report

Your class participation is required 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 to explain any section of your project individually or in group using sketches, diagrams, and other engineering tools. 

By now, you'll have to be finishing the oral presentation of some project.


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.

- Here you are a similar circuit from an old unit. 


Other materials of interest

Books, web pages, etc.