Srinath Avadhanula
We therefore developed a process where the PIC 2520 is initially loaded with an FSM emulation program which can understand and model a (reasonably) arbitrary Finite State Machine. The state transition table for the FSM is communicated to the PIC wirelessly via the IR photo transistors already on the PIC. The FSM emulation program then steps through the FSM and exhibits the behavior specified therein. While stepping through the FSM, the program also monitors the photo transistor and if it receives a certain (improbable) sequence of values, it erases the current FSM and waits for a new FSM description. This way, we can reprogram wirelessly by flashing a pre-determined sequence of bits at the photo transistor. Thus we completely eliminate the step of detaching the glider board from the glider and attaching the ZIF connector which makes programming and re-programming the PIC much safer and faster.
A Finite State machine or FSM is a simple way to specify (or model) the behavior of a discrete time system. Wikipedia contains a somewhat detailed description of the FSM. Note that our FSM is a somewhat limited subset of a generic FSM.
In short, the FSM is a way to specify behavior by describing all possible states in which we want the system to be and when to transition between them. At any time instant, the system will always be in one of the specified states. When it is in a state, we specify that the machine should perform certain actions. In our case, an action is simply setting some parameter of an output peripheral of the PIC (such as the value of an LED or the duty cycle of a PWM) to a given value. Moreover whenever the system is in any given state, we check the transition conditions corresponding to that state. When any of the transition conditions evaluate to true, then we transition to a new state (which state to transition to is specified as a part of the transition condition).
In pseudo-code, our FSM emulation can be thought of as
present_state_number = 0 local_timer = 0 global_timer = 0 BEGIN: Perform Actions of present_state_number FOREACH condition IN Transition conditions of present_state_number: IF condition IS TRUE: present_state_number = target(condition) local_timer = 0 local_timer = local_timer + 1 global_timer = global_timer + 1 GOTO BEGIN
Note that we maintain two "clocks", a local_timer and a global_timer, both of which increment by one with every tick of the FSM. However, the local_timer resets to 0 whenever a transition is made, whereas the global_timer will increment indefinitely. Note that it is possible for the user to reset the global_timer as one of the actions of an FSM state.
The basic component of an XML file is an "element". An element has a name, some (optional) "attributes", and some optional "child elements". This is specified using the following syntax:
<element_name attribute1="value1" attribute2="value2" ...> ... child elements ... </element_name>
Note that apart from a single space between attributes, additional space is ignored. An example of a minimal XML element can thus be
<student name="foo" roll="42"></student>
Notice that each element has what is called a start tag, which consists of the element name and the attributes surrounded by angle brackets. In the above example, the start tag is <student name="foo" roll="42">. The element description ends with an end tag which consists of the element name prefixed by a single forward slash enclosed in angle brackets. In the above example, the end tag is </student>. An additional syntax feature which makes XML more readable is that if an element does not have any children, then we can skip the end tags and have the start tag itself end with a />. For example, the above example could also have been written as:
<student name="foo" roll="42" />
Child elements are again specified using exactly the same syntax.
The supplied FSM program understands the following "dialect" of the general XML syntax:
The parser ignores any attributes which you supply to the state element. However, for the sake of readability, it is often useful to include some "comment like" attribute, for example, something like <state number="0">.
Possible Values:
Possible values:
IF lhs_addr (cmp_op) rhs0 (bin_op) rhs1: GOTO target ELSE STAY
where lhs_addr is a pointer to the output peripheral whose value we want to use in the left hand side of the comparision. To implement this behavior, the following attributes need to be defined:
Possible Values: This attribute takes the same set of values as the rhs attribute of the assignment element.
Possible Values:
Possible Values:
These two attributes can take the same value as rhs attribute of the assignment element. In addition to that, one or both of these attributes can also be directly assigned a 16 bit integer value.
To summarize, the XML description of the FSM should have the following structure:
<document> <state> <assignment lhs_addr="..." rhs="..." /> <assignment lhs_addr="..." rhs="..." /> <transition lhs_addr="..." cmp_op="..." rhs0="..." bin_op="..." rhs1="..." target="..." /> <transition lhs_addr="..." cmp_op="..." rhs0="..." bin_op="..." rhs1="..." target="..." /> </state> ... </document>
A detailed description of the required software for Windows XP is:
When you get to the last page of the setup, you will be asked to "Select Packages". At this stage, make sure that in addition to the standard packages it selects, the following packages are also selected:
After installation is complete, you should be able to open a "cygwin prompt" by clicking on the Cygwin icon which the installation places on your Desktop.
Extract the ZIP file above into a directory, say c:/fsm. Open a cygwin prompt and then change into this directory
$ cd /cygdrive/c/fsm
Note that c: is referred to as /cygdrive/c in cygwin.
From this directory, issue the command
$ make pickle
You should see the following output
gcc -c pickle.c gcc -c crc.c gcc -c globals.c gcc -o pickle crc.o pickle.o -lexpat
At the end, you should see a file called pickle.exe created in this directory. If you have this file, you are all set!
Note that the software packages above are sufficient for IR programmming/re-programming a PIC 2520 which is already flash-loaded with the FSM emulation code. If you also need to load the FSM emulation code into the PIC, you will need MPLAB IDE and MPLAB ICD2 both of which are free downloads from microchip.com. How to program the PIC is presently outside the scope of this document.
This document was generated using the LaTeX2HTML translator Version 2002-2-1 (1.71)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -local_icons -split 0 manual.tex
The translation was initiated by U-IBM-37E42D9DFC1on 2005-12-07