AME 30315 Pendulum Project: Difference between revisions
| Line 20: | Line 20: | ||
The following elements are illustrated in the picture. | The following elements are illustrated in the picture. | ||
* The smaller | * The smaller green printed circuit board, on the lower left, with the serial port on it, has the 68hc11 microprocessor on it. This will be called the "hc11 board" or "microcontroller board." The actual hc11 is the square chip on the vertical board sticking out from the base. The chip on the base board is the serial interface. The round silver component next to the hc11 is the clock. The larger rectangular chip on the other side is the EEPROM. | ||
* The larger printed circuit board, on the upper left, provides the interface between the microcontroller and the H-bridge and, the encoder, the index encoder and some limit sensors. It will be called the "interface board." It also has a chip on it that is a decoder for the encoder. Whenever the encoder encounters an edge, the decoder generates a pulse that produces an interrupt on the hc11. The hc11 then can query the decoder to determine which direction the pendulum is moving. | * The larger printed circuit board, on the upper left, provides the interface between the microcontroller and the H-bridge and, the encoder, the index encoder and some limit sensors. It will be called the "interface board." It also has a chip on it that is a decoder for the encoder. Whenever the encoder encounters an edge, the decoder generates a pulse that produces an interrupt on the hc11. The hc11 then can query the decoder to determine which direction the pendulum is moving. | ||
* The H-Bridge is in the center of the picture and has the heat sinks on it. It takes the PWM signal from the hc11 and produces a current proportional to the duty cycle. | * The H-Bridge is in the center of the picture and has the heat sinks on it. It takes the PWM signal from the hc11 and produces a current proportional to the duty cycle. | ||
Revision as of 18:13, 18 March 2012
Introduction
In this project you will design a feedback controller to stabilize an inverted pendulum. The basic steps are:
- system identification,
- controller design,
- implementation and verification.
The first and third steps require that you be able to program a microcontroller. The second step requires that you understand the course material.
This web page provides a description of the system and instructions to download a program. Read everything before the "Getting Started" section, but do not worry if you do not understand it all. You will probably have to re-read it several times.
The System
The pendulum and controller are shown in the figure below. It is comprised of
- the pendulum,
- a d.c. motor with optical encoder,
- an H-bridge current controller,
- a Freescale 68hc11 8-bit microcontroller with peripherals, and
- a usb-port logic analyzer.
The microcontroller is very inexpensive and has limited capability, as is realistic in industry where component costs are of significant importance.
The following elements are illustrated in the picture.
- The smaller green printed circuit board, on the lower left, with the serial port on it, has the 68hc11 microprocessor on it. This will be called the "hc11 board" or "microcontroller board." The actual hc11 is the square chip on the vertical board sticking out from the base. The chip on the base board is the serial interface. The round silver component next to the hc11 is the clock. The larger rectangular chip on the other side is the EEPROM.
- The larger printed circuit board, on the upper left, provides the interface between the microcontroller and the H-bridge and, the encoder, the index encoder and some limit sensors. It will be called the "interface board." It also has a chip on it that is a decoder for the encoder. Whenever the encoder encounters an edge, the decoder generates a pulse that produces an interrupt on the hc11. The hc11 then can query the decoder to determine which direction the pendulum is moving.
- The H-Bridge is in the center of the picture and has the heat sinks on it. It takes the PWM signal from the hc11 and produces a current proportional to the duty cycle.
- The motor is on the right in the picture.
- On the right edge of the interface board, you can see three colored wires going to the upper edge of the picture. These wires are connected to a USBee SX logical analyzer, which can be connected to the USB port on a PC. If you run the USBee tools on the PC, you can see when interrupts are occurring, etc.
You will need to use one of the desktop computers in 212 or 213 Stinson-Remick. Those computers should have the following software installed:
- the 68hc11 port of the gcc compiler,
- putty, to be able to communicate with the microcontroller over the serial port,
- notepadd++, for editing your programs, and
- the logic analyzer software.
There are 10 pendulum platforms and five USB logic analyzers on the window sill in 212. Return them when you are finished. I have been told there are many more logic analyzers available in S-R.
Interrupts
There are two interrupts in the program. One is an output compare interrupt and the other is a pulse accumulator interrupt.
- The code that is provided has the output compare interrupt running at 880 Hz and is for the pulse width modulation control of the motor. It is output compare 3, OC3. If the motor power is on, you can hear this one in operation because you can hear an 880 Hz sound from the H-bridge.
- The pulse accumulator interrupt happens whenever the optical encoder senses an edge. There is a decoder chip on the board that the hc11 can query to determine which direction the pendulum is moving. On the interface board, there is a green LED that will be on when the pendulum is moving to the right and off when it is moving to the left. It has RIGHT printed next to it. The red LED next to it that has LEFT printed next to it does not come on when it is moving to the left. It is on when the pendulum is at either limit position.
- The encoder also has an index channel, which senses when the encoder passes through the nominal zero position. However, because it was assembled by hand and also because the motor shaft may slip in the collar on the pendulum, the index will never exactly be at 0 degrees. Part of the calibration process will be to determine the offset between the index and the zero position. The index channel on the encoder does not generate an interrupt. However, it does make the white/blue LED flash that is next to the grey ribbon cable on the interface board.
Important Parameters
- There are approximately 5 or 6 interrupts per angular degree of motion of the pendulum. More specifically, there is .18 degree per interrupt generated by the encoder.
- There is an index on the encoder that happens only once per revolution. It should be aligned so that the pendulum is vertical when the motor goes through this position. There is a whitish/blue LED near the grey ribbon cable that flashes when it goes through this position. The calibration steps outlined below provide for an offset if this is not aligned with the vertical position. However, it must be the case that this position is within the range of motion of the pendulum. If the shaft slips too much and it's outside the range of motion, then the code will not work.
- All the I/O for the pendulum control is through PORT A on the hc11.
- pin 0 is connected to the limit sensors for the hard stops.
- pin 1 is the direction.
- pin 2 is connected to the encoder index (close to the top).
- pin 3 is not used.
- pin 4 has been used for various debugging things. It is ok to leave it unused.
- pin 5 is the PWM.
- pin 6 is connected to the red LED on the hc11 board. The code is written so it flashes at 20Hz.
- pin 7 is connected to the decoder which pulses whenever the decoder receives an edge from the encoder.
Switches
- On the smaller, hc11 board, there are two switches and one button. The two switches are facing the back of the system on the vertical board. They must be together to download a program and apart to run. The button is the reset button.
- The four white buttons on the interface board are wired to PORT B on the processor. You do not have to use these, but they can be accessed by your program. You may want to use them, for example, to change a gain value without having to recompile and download your program. It is acceptable to leave these as unused for this project. The rightmost button is wired to the reset button on the hc11 board and does exactly the same thing.
Getting Started
This section outlines the steps to write, compile, download and execute a program on the microcontroller. Until you have a controller designed that is supposed to stabilize the pendulum, make sure the pendulum is pointing down.
The file format that can be downloaded to the hc11 is called an "S-record" and has a filename that has a ".s19" suffex. Here is an example of an S-record that commands a square-wave torque to the pendulum with a period of approximately two seconds. It is a text file, so it is something you can look at and open in an editor, but it is not really decipherable.
The steps required to download the run this example square-wave program are
- ensure that the pendulum is hanging down,
- plug in both power plugs (one is for the hc11 board and the other is for the motor and controller XXXXXXX?)
- connect the serial port (elaborate XXXXXX, are there two comm ports on the PCs?)
- set the switches the right way and push the right buttons
- open a command window on the computer (how to do this?XXXXXX)
- cd to where XXXXXX?
- in the command window type
whatever we type
- when it's downloaded you should see a prompt again. It takes between 30 seconds and two minutes, depending on how long the code is
- open putty and configure XXXXXX
- hit the right button
- you should see
something
in the putty window - move the pendulum through the zero position
- etc
m6811-elf-gcc -g -Os -N -mshort -Wl,-m,m68hc11elfb -fomit-frame-pointer -msoft-reg-count=0 -o pendulum.elf PendulumControl.c
m6811-elf-objcopy --only-section=.text --only-section=.rodata --only-section=.vectors --only-section=.data --output-target=srec pendulum.elf pendulum.s19
pms91 pendulum
Notes on the C Program
Ultimately your job is to edit the program to implement a controller that you design.
Files:
- PendulumControl.c: this is the main C program.
- mc.h: header file that defines what the pins on PORT A are used for. This can't be changed because they are wired in hardware for that functionality.
- hc11.h: header file that defines the register block, where PORT A is, etc.
- vectors.c: C file that defines the interrupt vector. T
Important variables:
- pos: this is encoder counts
- pos_deg: is pos*scale which comes out to be degrees times 100
- u: is the torque with a range of -400 to +400. Negative values are a CCW torque.
- dir: specifies the direction, 0 is CW, 1 is CCW. This should not have to be changed because the provided code interprets the sign of u and sets the direction accordingly.
Functions you will probably use:
Functions you probably won't use:
