This shows you the differences between two versions of the page.
|
pm:prj2026:jan.vaduva:robert.rachieru [2026/05/19 01:20] robert.rachieru [Hardware Design] |
pm:prj2026:jan.vaduva:robert.rachieru [2026/05/27 12:03] (current) robert.rachieru |
||
|---|---|---|---|
| Line 38: | Line 38: | ||
| | Potentiometer | 10k Ohm Rotary | Menu navigation and mode selection | | | Potentiometer | 10k Ohm Rotary | Menu navigation and mode selection | | ||
| | Power Supply | 12V DC / 2A | Powering motors and logic (via step-down) | | | Power Supply | 12V DC / 2A | Powering motors and logic (via step-down) | | ||
| + | |||
| + | == Assembly == | ||
| + | |||
| + | {{https://ocw.cs.pub.ro/courses/_media/pm/prj2026/jan.vaduva/plotter_asm.jpg?700}} | ||
| == Hardware Implementation Status == | == Hardware Implementation Status == | ||
| Line 69: | Line 73: | ||
| | | LCD_D4 - D5 | PB0 - PB1 | Parallel Bus | Higher bits of the 8-bit data bus. | | | | LCD_D4 - D5 | PB0 - PB1 | Parallel Bus | Higher bits of the 8-bit data bus. | | ||
| | | LCD_D6 - D7 | PC0 - PC5 | Parallel Bus | Remaining bits routing the full parallel byte. | | | | LCD_D6 - D7 | PC0 - PC5 | Parallel Bus | Remaining bits routing the full parallel byte. | | ||
| - | | **Peripherals** | Potentiometer| ADC6 | Analog In | **Optimization:** Connected to a dedicated analog-only pin, saving general-purpose digital IO pins. | | ||
| - | | | Touch Panel | ADC7 | Analog In | Connected to the second analog-only input channel. | | ||
| == Electrical Schematic & Explanations == | == Electrical Schematic & Explanations == | ||
| - | {{https://ocw.cs.pub.ro/courses/_media/pm/prj2026/jan.vaduva/Schematics_Plotter_v1.0.png?900}} | + | {{https://ocw.cs.pub.ro/courses/_media/pm/prj2026/jan.vaduva/Schematics_Plotter_v1.0.png?800}} |
| The circuit diagram is structurally grouped into three distinct functional blocks to isolate high-power inductive loads from sensitive logic electronics: | The circuit diagram is structurally grouped into three distinct functional blocks to isolate high-power inductive loads from sensitive logic electronics: | ||
| Line 97: | Line 99: | ||
| The physical setup for the initial milestone focuses entirely on the core power distribution network and the dual-axis motion subsystem. The ATmega328P-XMINI development board is mounted alongside the custom-wired breakout board housing the two DRV8825 stepper drivers and the LM2596 buck converter module. | The physical setup for the initial milestone focuses entirely on the core power distribution network and the dual-axis motion subsystem. The ATmega328P-XMINI development board is mounted alongside the custom-wired breakout board housing the two DRV8825 stepper drivers and the LM2596 buck converter module. | ||
| + | |||
| + | {{https://ocw.cs.pub.ro/courses/_media/pm/prj2026/jan.vaduva/plotter_stepper_test.jpg?700}} | ||
| === 2. Diagnostic Testing Routine === | === 2. Diagnostic Testing Routine === | ||
| Line 114: | Line 118: | ||
| * **GPIO Control Integrity**: The logical isolation between the step pulse generation loop and the shared ground planes is secure. The motors lock under full holding torque when idle and track angular steps flawlessly without stuttering, confirming high noise immunity across the control lines. | * **GPIO Control Integrity**: The logical isolation between the step pulse generation loop and the shared ground planes is secure. The motors lock under full holding torque when idle and track angular steps flawlessly without stuttering, confirming high noise immunity across the control lines. | ||
| + | ====== Software Design ====== | ||
| + | |||
| + | ===== 1. Current Status of the Software Implementation ===== | ||
| + | The software implementation is fully functional and successfully integrated with the hardware. The system is capable of initializing peripheral devices (TFT LCD, SD Card, Stepper Motors), processing user commands via a non-blocking UART interface, and executing physical movements by reading and parsing **G-code** (''.GCO'' files) directly from the SD card. The entire kinetics engine operates asynchronously via hardware interrupts, ensuring highly precise and smooth 2D plotting. | ||
| + | |||
| + | ===== 2. Motivation for the Chosen Libraries ===== | ||
| + | To ensure maximum performance and strict timing, standard Arduino libraries (such as ''Serial'' or ''Stepper.h'') were intentionally avoided in favor of bare-metal AVR C++ programming. The only external third-party library used is: | ||
| + | * **Petit FatFs (pff.h)**: Chosen for SD card filesystem access due to its exceptionally low RAM footprint compared to the standard Arduino SD library. It allows reading G-code line-by-line without exhausting the microcontroller's limited memory. | ||
| + | All other modules (UART, LCD rendering, and Stepper control) were written entirely from scratch using direct register manipulation (e.g., ''PORTA'', ''TCCR1B'') to maintain absolute control over CPU cycles. | ||
| + | |||
| + | ===== 3. Novelty of the Project ===== | ||
| + | The defining novel element of this software architecture is the **Custom Interrupt-Driven Kinetics Engine**. In standard hobbyist plotters, stepper motors are driven using blocking delay loops (e.g., ''_delay_ms()''), which paralyzes the microcontroller. In this project, the **Bresenham Line Algorithm** is deeply integrated into an AVR Hardware Timer Interrupt Service Routine (ISR). This allows the MCU to pulse the motors seamlessly in the background at exactly 4,000 Hz, while the main loop simultaneously parses complex G-code, updates the UI, and communicates over Serial without dropping a single physical step. | ||
| + | |||
| + | ===== 4. Utilization of Laboratory Functionalities ===== | ||
| + | The project heavily applies concepts taught during the laboratory sessions: | ||
| + | * **Hardware Timers & Interrupts:** The 16-bit ''Timer1'' is configured in CTC (Clear Timer on Compare Match) mode with a custom prescaler and compare match register (''OCR1A = 499''). This triggers an ''ISR(TIMER1_COMPA_vect)'' exactly 4,000 times per second for high-resolution 1/16th Microstepping control. | ||
| + | * **USART (Serial Communication):** Implemented bare-metal UART using ''UBRR0'', ''UCSR0A'', and ''UDR0'' registers for a non-blocking 115200 baud command-line interface. | ||
| + | * **GPIO Manipulation:** Fast pin toggling using direct port manipulation (''PORTA'', ''PORTF'') for maximum switching speed on the stepper direction/step pins and LCD data buses. | ||
| + | |||
| + | ===== 5. Project Architecture, Interaction, and Validation ===== | ||
| + | The codebase is heavily decoupled and structured into independent C++ modules (''stepper'', ''uart'', ''lcd'', ''gcode'', ''ui'', ''sd_handler'') interconnected through a shared ''globals'' state. | ||
| + | * **Interaction:** The primary infinite loop reads characters from UART and text lines from the SD card. When a coordinate is parsed by the ''gcode'' module, it invokes ''moveTo()''. The ''moveTo()'' function calculates the discrete step vectors and safely loads them into ''volatile'' memory. The ''Timer1'' ISR then automatically takes over, converting those vectors into physical step pulses asynchronously. | ||
| + | * **Validation:** The system was validated progressively. The UART command parser was tested via Serial Monitor for logic verification. The stepper kinetic logic was validated by ensuring no serial buffer overflow occurred during movement. Finally, overall system integration was proven by exporting an SVG file to G-code via CAM software and successfully observing the machine plot mathematically correct curves on paper without stuttering or crashing. | ||
| + | |||
| + | ===== 6. Finite State Machine (FSM) UI Implementation ===== | ||
| + | To manage the user interface and system modes without blocking the main execution loop, a **Finite State Machine (FSM)** was implemented. The system operates in one of four distinct states at any given time, defined by an ''enum'': | ||
| + | * ''STATE_MAIN_MENU'' | ||
| + | * ''STATE_SD_MENU'' | ||
| + | * ''STATE_TOUCH_DRAW'' | ||
| + | * ''STATE_HOME'' | ||
| + | |||
| + | The FSM is driven by the UART non-blocking parser. When a user issues a command (such as ''SELECT 1'' or ''BACK''), the parser acts as a state transition controller, updating the ''currentState'' variable and setting a ''needsRendering'' boolean flag. The primary infinite loop evaluates a ''switch(currentState)'' statement and routes execution to the appropriate module to redraw the TFT LCD. | ||
| + | |||
| + | This FSM architectural pattern is critical: it prevents the microcontroller from getting trapped in nested sub-menu loops. Because the state machine evaluates and exits rapidly, the main loop is free to continuously poll for new serial commands, read the SD card, and pass coordinates to the interrupt-driven kinetic engine simultaneously. | ||
| + | |||
| + | ==== Bibliography/Resources ==== | ||
| + | |||
| + | Stepper Motor Setup https://www.makerguides.com/drv8825-stepper-motor-driver-arduino-tutorial/ | ||
| + | |||
| + | ILI9486 LCD + SD Reader Datasheet https://datasheet4u.com/datasheets/ILITEK/ILI9486/945603 | ||
| + | |||
| + | FAT32 File System Module https://elm-chan.org/fsw/ff/00index_p.html | ||
| + | |||
| + | Github Project https://github.com/Hatmanul-RRC/ProiectPM-Plotter | ||