The Microchip PIC family of microcontrollers
are excellent low cost general purpose microcontrollers that support
4, 8, 16 and 20 MHz crystal oscillator speeds. The PIC16F76 was
selected as the microcontroller for this project as it was readily
available, it has three I/O ports of eight pins each, it contains
more than enough analog to digital conversion inputs and it has
been used by the PIC programmer in previous project work so the
learning curve is relatively non-existent.
The PIC16F76 is a 28 pin 8-bit CMOS flash microcontroller
containing a RISC-based CPU. Direct assembly level programming
was done as this is the best method to ensure tightly optimized
code and because the PIC programmer is well versed in programming
assembly, particularly in PICs.
The PIC was used to convert the analog voltage
received from the tilt sensor into a digital value. This value
was saved into memory and also displayed on the LED display connected
to Port C. The PIC was then used to generate a binary stream containing
the tilt’s digital value to the MC1488 line driver where
it would be converted to RS232 in real time. As the updated tilt
value only required to be transmitted so often, a continuous code
loop was created where this process was only conducted once every
25th cycle. The other 24 cycles were used to constantly output
the motor controller signals in the output loop.
The first pin of Port B, RB0, was used as an
external interrupt falling-edge detector. As soon as a falling
edge event occurs on this pin, it will cause the PIC code loop
mentioned above to pause in its current operation and jump to
the interrupt handler. The interrupt handler reads in the binary
data stream received from the host computer via the MC1489 receiver
and stores the byte representing the motor duty cycle into a variable.
This variable is constantly read by the output loop to determine
which motor controller signals to send the motor controller and
at what duty cycle to set the PWM signal.