# Firmware Requirements for Turning Table based on HC32 MCU ## 1. Overview This document outlines the firmware requirements for a motorized turning table based on the HC32F005C6PA microcontroller. The system drives a 28BYJ-48 stepper motor and provides user control via a single button for speed and direction, with status feedback from a single LED. ## 2. Hardware Specifications - **Microcontroller:** HC32F005C6PA (32MHz ARM Cortex-M0+ with 32KB Flash and 4KB RAM, 6 Timers, 2 UARTs, 1 I2C, 1 SPI, 1 9ch 12-bit ADC, 2 Analog Comparators) - **Motor:** 28BYJ-48 Stepper Motor - **Motor Driver:** ULN2003-based driver board - **User Input:** 1x Tactile Button - **Status Output:** 1x LED - **Power Control:** External hardware circuit managed by a GPIO pin. ## 3. Functional Requirements ### 3.1. State Definitions - **POWER_OFF:** The main power is off. This state is entered by firmware action but cannot be exited by firmware. - **IDLE:** The system is powered on, but the motor is not rotating. This is the default state after power-on. - **ROTATING:** The system is on and the motor is actively rotating. ### 3.2. Power Control - **FR1:** The firmware does not control power-on. It assumes the system starts in the **IDLE** state when power is applied by the external circuit. - **FR2:** The firmware shall hold the system power ON by driving pin **P33** high (output/push-pull). - **FR3:** A "long press" on the button (held for > 2 seconds) shall trigger the **POWER_OFF** state by changing pin **P33** to output low. - **FR18:** Before releasing the power latch (P33 low), the motor shall be decelerated to a full stop using the acceleration control defined in FR12. After the motor reaches standstill, the LED shall turn off (FR13), and only then shall the power latch be released. If the motor has not reached standstill within a bounded time (e.g. 2 seconds), the latch shall be released anyway so the power-off is never blocked. ### 3.3. Button Input Logic - **FR4:** The button is connected to pin **P32**, which shall be configured as an input with its internal pull-up resistor enabled. A button press pulls the pin to ground. Software debouncing should be implemented. - **FR5:** A "short press" is defined as a press-and-release cycle shorter than 1 second. - **FR6:** A "long press" is defined as holding the button for more than 2 seconds. - **FR7:** A "double press" is defined as two consecutive short presses where the interval between the first release and the second press is less than 300ms. ### 3.4. Motor Control - **FR8:** From the **IDLE** state, a short press shall transition the system to the **ROTATING** state at Speed 1. - **FR9:** While in the **ROTATING** state, a short press shall cycle through the four defined speed levels in the order: Speed 1 -> Speed 2 -> Speed 3 -> Speed 4 -> Speed 1... - **FR10:** While in the **ROTATING** state, a double press shall reverse the motor's direction of rotation. - **FR11:** The firmware shall drive the stepper motor in half-step mode to ensure smoother rotation. - **FR12:** Rotation shall be continuous. Apply acceleration control when changing speed and direction to avoid skipping steps. ### 3.5. LED Indicator Logic - **FR13:** In the **POWER_OFF** state, the LED is off. - **FR14:** In the **IDLE** state, the LED shall blink slowly (0.5 Hz, 1 second on, 1 second off) to indicate the system is on and ready. - **FR15:** In the **ROTATING** state, the LED shall be solid ON. - **FR16:** As feedback for a speed change, the LED shall interrupt its solid ON state to blink N times corresponding to the new speed level (e.g., 3 blinks for Speed 3), then return to solid ON. - **FR17:** As feedback for a direction change, the LED shall perform a quick double-blink, then return to solid ON. ## 4. Non-Functional Requirements - **NFR1:** The firmware shall be written in C. - **NFR2:** The target compiler and toolchain shall be ARM GCC. - **NFR3:** The firmware must operate within the memory constraints of the HC32F005C6PA (32KB Flash, 4KB RAM). ## 5. Pin Assignments | Pin | Function | Configuration | Notes | |---|---|---|---| | P02 | LED | Open-Drain Output | Active Low | | P23 | Motor IN1 | Push-Pull Output | | | P24 | Motor IN2 | Push-Pull Output | | | P25 | Motor IN3 | Push-Pull Output | | | P26 | Motor IN4 | Push-Pull Output | | | P32 | Button | Input with Pull-up | Active Low | | P33 | Power Latch | Push-Pull Output | |