M68HC12
Project Details
- Category: Mechatronics
- Project Date: April 2024
- Attachments:
Intro to Mechatronics – Assembly on the M68HC12
This project was part of Cal Poly’s ME 305 class. The focus was on building embedded control systems using the Motorola M68HC12 microcontroller. All code was written in Assembly with no high-level language support. Every lab required writing firmware from scratch using interrupts, timers, and direct memory-mapped I/O.
One of the main labs was a digital function generator. It used the onboard DAC to output sine, square, or triangle waves. The frequency and waveform type were entered through a keypad. A state machine parsed the input, validated it, and converted it into DAC values. All of this ran inside a timer interrupt. Timing was critical. If anything was misaligned, the output wave would be noisy or the system would freeze.
Another key lab was a PI velocity controller for a DC motor. The motor had an optical encoder for feedback. The control algorithm was written entirely in Assembly. Gains were put into memory using the keypad and tested. Tuning required observing step responses and adjusting constants by hand. The controller maintained steady speed under load but only after careful balancing between speed and stability. Integral wind-up was a problem and had to be managed in code.
Most labs used finite state machines to organize logic. One FSM handled keypad input. Another managed waveform generation. Others controlled the LCD display. Each state handled a specific task like “wait for keypress” or “display error.” Transitions were based on flags and counters. This made the system easier to debug and keep modular even with low-level code.
Writing in Assembly required full attention to timing, memory usage, and logic structure. One wrong instruction or missed flag could cause the system to be buggy or crash. By the end of the class, we understood how to program embedded systems at a low level. We worked with interrupts, managed peripherals, and wrote control programs without abstraction layers. The experience was difficult but gave a strong foundation in embedded design.