This shows you the differences between two versions of the page.
|
pm:prj2026:victor.stoica0203:antonio.neagu [2026/05/04 14:16] antonio.neagu created |
pm:prj2026:victor.stoica0203:antonio.neagu [2026/05/19 20:02] (current) antonio.neagu |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Reaction Trainer ====== | ====== Reaction Trainer ====== | ||
| - | Reaction Trainer este un joc embedded de testare și antrenare a reflexelor, implementat pe placa ATmega328P-XMINI. Sistemul generează runde în care utilizatorul trebuie să reacționeze cât mai rapid la semnale vizuale afișate pe un LED RGB și la semnale sonore generate de un buzzer pasiv. | + | ===== Introduction ===== |
| - | Utilizatorul apasă butonul corespunzător semnalului afișat, iar microcontrollerul măsoară timpul de reacție, detectează apăsările greșite sau premature și calculează scorul. Rezultatele rundelor și scorul final sunt transmise către PC prin interfața UART. | + | Reaction Trainer is an embedded reflex testing and training game implemented on the ATmega328P-XMINI development board. |
| - | Proiectul folosește GPIO pentru butoane și LED RGB, timere pentru măsurarea timpului de reacție, întreruperi pentru detectarea apăsărilor, UART pentru afișarea rezultatelor și un automat finit de stări pentru logica jocului. Dificultatea jocului este reglată cu ajutorul unui potențiometru citit prin ADC. | + | The project generates game rounds in which the user must react as quickly as possible to visual signals shown using two LEDs: one red LED and one yellow LED. The user must press the button corresponding to the active LED. The microcontroller measures the reaction time, detects wrong or premature button presses and calculates the final score. |
| - | ===== Schema bloc ===== | + | The idea started from a simple reaction timer game, but the project was extended to include multiple hardware and software concepts used in embedded systems: GPIO, ADC, UART, timers and a finite state machine. |
| - | {{:pm:prj2026:victor.stoica0203:schemabloc.png?700|Schema bloc Reaction Trainer}} | + | The project is useful because it demonstrates how a microcontroller can interact with external components, measure real-time events and provide feedback to the user. It is also useful for learning how to write firmware using AVR registers instead of only using high-level functions. |
| - | ===== Mod de funcționare ===== | + | ===== General Description ===== |
| - | Sistemul funcționează pe baza plăcii ATmega328P-XMINI, care coordonează logica jocului, citește butoanele, măsoară timpul de reacție și controlează feedback-ul vizual și sonor. | + | The system is based on the ATmega328P-XMINI board, which controls the game logic, reads the buttons, measures the reaction time and controls the visual feedback. |
| - | La pornire, sistemul se află în starea de repaus. Utilizatorul poate porni jocul prin apăsarea unui buton sau printr-o comandă trimisă prin UART. După pornire, microcontrollerul generează o rundă de joc: așteaptă un interval de timp, afișează un semnal pe LED-ul RGB și pornește măsurarea timpului. Utilizatorul trebuie să apese butonul corespunzător cât mai repede. | + | At startup, the system is in the idle state. The user starts the game by pressing the START button. After that, the microcontroller waits for a pseudo-random amount of time, turns on either the red LED or the yellow LED and starts measuring the reaction time. |
| - | Conectate la placa ATmega328P-XMINI sunt următoarele componente: | + | The user must press the correct button as fast as possible. If the correct button is pressed, the reaction time is sent to the PC through UART. A point is awarded only if the response is correct and the reaction time is below 600 ms. |
| - | * butoane push-button - folosite pentru pornirea jocului și pentru răspunsurile utilizatorului; | + | The difficulty is controlled using a potentiometer connected to an ADC pin. The ADC value changes the maximum allowed reaction time. |
| - | * led rgb - oferă feedback vizual și indică semnalul la care utilizatorul trebuie să reacționeze; | + | |
| - | * buzzer pasiv - oferă feedback sonor pentru început de rundă, răspuns corect, răspuns greșit și final de joc; | + | |
| - | * potențiometru - conectat la un pin ADC și folosit pentru reglarea dificultății jocului; | + | |
| - | * pc prin uart - folosit pentru afișarea scorului, timpilor de reacție și mesajelor de stare. | + | |
| - | Dificultatea jocului este controlată prin potențiometru. Microcontrollerul citește valoarea analogică folosind ADC-ul, iar în funcție de valoarea citită modifică timpul maxim permis pentru reacție sau viteza rundelor. O valoare mică poate corespunde unui mod ușor, iar o valoare mare poate corespunde unui mod mai dificil. | + | The project also includes a display module, which will be used to show the current round, reaction time and score directly on the device. Until the display arrives and is integrated, the results are shown through UART in the Serial Monitor. |
| - | Logica jocului este implementată ca automat finit de stări. Stările principale sunt: | + | The main modules of the project are: |
| - | * repaus - sistemul așteaptă pornirea jocului; | + | * ATmega328P-XMINI - main control board; |
| - | * așteptare rundă - sistemul așteaptă un interval înainte de afișarea semnalului; | + | * Red LED and yellow LED - visual output signals; |
| - | * semnal activ - led-ul rgb afișează semnalul, iar timpul de reacție este măsurat; | + | * Push-buttons - user input for start and answers; |
| - | * răspuns corect - sistemul acordă punctaj și oferă feedback sonor; | + | * Potentiometer - analog input used for difficulty control; |
| - | * răspuns greșit - sistemul marchează greșeala și oferă feedback sonor diferit; | + | * Display module - planned local output for round number, reaction time and score; |
| - | * final joc - sistemul afișează scorul final și timpii prin UART. | + | * UART communication - temporary output interface used to send results to the PC; |
| + | * Timer module - generates a millisecond counter used for reaction time measurement; | ||
| + | * Finite state machine - controls the game flow. | ||
| - | Dacă utilizatorul apasă înainte de apariția semnalului, răspunsul este considerat prematur și runda este marcată greșită. Dacă utilizatorul nu apasă în timpul maxim permis, sistemul marchează runda ca ratată. La finalul tuturor rundelor, scorul total și timpii de reacție sunt transmiși către PC prin UART. | + | ===== Block Diagram ===== |
| - | ===== Bill of Materials ===== | + | {{:pm:prj2026:victor.stoica0203:schemabloc.png?700|Reaction Trainer block diagram}} |
| - | ^ Componentă ^ Cantitate ^ Rol în proiect ^ | + | The hardware components interact with the microcontroller through digital and analog pins. The LEDs are controlled as digital outputs, the buttons are read as digital inputs with internal pull-up resistors, and the potentiometer is read through the ADC. The results are currently transmitted to the PC using UART through the virtual COM port. The display module will later be used as the local output interface. |
| - | | ATmega328P-XMINI | 1 | placa principală de control | | + | |
| - | | LED RGB | 1 | feedback vizual pentru semnalele jocului | | + | |
| - | | Buzzer pasiv | 1 | feedback sonor pentru start, răspuns corect/greșit și final de rundă | | + | |
| - | | Butoane push-button | 3-4 | input pentru start și răspunsurile utilizatorului | | + | |
| - | | Potențiometru | 1 | reglarea dificultății jocului prin ADC | | + | |
| - | | Rezistențe pentru LED | 3 | limitarea curentului pentru canalele LED-ului RGB | | + | |
| - | | Rezistențe pentru butoane | 3-4 | pull-up sau pull-down, dacă nu se folosesc rezistențele interne | | + | |
| - | | Breadboard | 1 | realizarea montajului | | + | |
| - | | Fire jumper | mai multe | conexiuni între componente | | + | |
| - | ===== Schema electrică ===== | + | The software is organized as a finite state machine. Each state represents a different part of the game: waiting for start, waiting before a signal, active signal, round result and game over. |
| - | TODO | + | ===== Hardware Design ===== |
| + | |||
| + | ==== Component List ==== | ||
| + | |||
| + | ^ Component ^ Quantity ^ Role in the project ^ | ||
| + | | ATmega328P-XMINI | 1 | Main development board and controller | | ||
| + | | Red LED | 1 | Visual signal for one reaction option | | ||
| + | | Yellow LED | 1 | Visual signal for the second reaction option | | ||
| + | | Push-buttons | 3 | START button and two answer buttons | | ||
| + | | Potentiometer 10kΩ | 1 | Difficulty control using ADC | | ||
| + | | Display module | -- | -- | | ||
| + | | Resistors 330Ω | 2 | Current limiting resistors for LEDs | | ||
| + | | Resistors 10kΩ | 3 | Optional pull-up/pull-down resistors for buttons | | ||
| + | | Breadboard | 1 | Prototype circuit assembly | | ||
| + | | Jumper wires | Several | Connections between components | | ||
| + | |||
| + | ==== Pin Connections ==== | ||
| + | |||
| + | ^ Component ^ Microcontroller Pin ^ Description ^ | ||
| + | | Yellow LED | PB1 | Digital output for yellow LED | | ||
| + | | Red LED | PB2 | Digital output for red LED | | ||
| + | | START button | PD2 | Digital input with internal pull-up | | ||
| + | | Red button | PD3 | Digital input with internal pull-up | | ||
| + | | Yellow button | PD4 | Digital input with internal pull-up | | ||
| + | | Potentiometer | PC0 / ADC0 | Analog input for difficulty control | | ||
| + | | Display module | -- | -- | | ||
| + | | UART | USB / Virtual COM | Temporary output for displaying results on the PC | | ||
| + | |||
| + | ==== Electrical Schematic ==== | ||
| + | |||
| + | |||
| + | ==== Signal Diagrams ==== | ||
| + | |||
| + | The main timing signal in the project is the reaction time interval. This interval starts when one of the LEDs is turned on and stops when the user presses one of the answer buttons. | ||
| + | |||
| + | The reaction time is calculated as: | ||
| + | |||
| + | reaction time = current time - signal start time | ||
| + | |||
| + | The system also detects premature button presses, which happen when the user presses an answer button before the visual signal appears. | ||
| + | |||
| + | ==== Simulation Results ==== | ||
| + | |||
| + | No simulation results are currently available. | ||
| + | |||
| + | ===== Software Design ===== | ||
| + | |||
| + | ==== Development Environment ==== | ||
| + | |||
| + | The firmware was developed using PlatformIO for the ATmega328P microcontroller. | ||
| + | |||
| + | The final version of the code uses direct AVR register access instead of Arduino-style functions. This makes the firmware closer to the hardware and shows how the microcontroller peripherals are configured. | ||
| + | |||
| + | ==== Libraries and Third-Party Sources ==== | ||
| + | |||
| + | The project uses standard AVR headers: | ||
| + | |||
| + | * avr/io.h - register definitions for ATmega328P; | ||
| + | * avr/interrupt.h - interrupt support; | ||
| + | * stdint.h - fixed-width integer types; | ||
| + | * stdio.h - used for number-to-string conversion. | ||
| + | |||
| + | No external third-party libraries are used in the final firmware. | ||
| + | |||
| + | ==== Implemented Modules ==== | ||
| + | |||
| + | The firmware is divided into several functional modules: | ||
| + | |||
| + | * GPIO module - configures LEDs as outputs and buttons as inputs with internal pull-up resistors; | ||
| + | * ADC module - reads the potentiometer value and adjusts the difficulty; | ||
| + | * UART module - sends text messages and results to the PC; | ||
| + | * Timer module - uses Timer1 in CTC mode to generate a 1 ms system tick; | ||
| + | * Display module - planned output module for showing game information locally; | ||
| + | * Game logic module - implements the finite state machine and scoring system; | ||
| + | * Pseudo-random generator - selects the next LED signal and waiting time. | ||
| + | |||
| + | ==== GPIO ==== | ||
| + | |||
| + | The LEDs are controlled through PORTB pins. PB1 controls the yellow LED and PB2 controls the red LED. | ||
| + | |||
| + | The buttons are connected to PORTD pins and use the internal pull-up resistors. This means that an unpressed button reads as logic 1, while a pressed button reads as logic 0. | ||
| + | |||
| + | ==== ADC ==== | ||
| + | |||
| + | The potentiometer is connected to PC0 / ADC0. The ADC value is used to modify the maximum allowed reaction time. | ||
| + | |||
| + | A small ADC value gives a larger reaction time window, making the game easier. A large ADC value gives a smaller reaction time window, making the game harder. | ||
| + | |||
| + | ==== UART ==== | ||
| + | |||
| + | UART is currently used to display the game status, reaction times and final score on the PC. This is a temporary output method used during development and testing, because the display module has not arrived yet. | ||
| + | |||
| + | After the display module is integrated, the main game information will be shown directly on the device, while UART can still be used for debugging. | ||
| + | |||
| + | ==== Display ==== | ||
| + | |||
| + | ==== Timer ==== | ||
| + | |||
| + | Timer1 is configured in CTC mode to generate an interrupt every 1 ms. Inside the interrupt service routine, a global millisecond counter is incremented. | ||
| + | |||
| + | This counter is used for: | ||
| + | |||
| + | * measuring reaction time; | ||
| + | * implementing waiting intervals; | ||
| + | * detecting timeout conditions; | ||
| + | * debounce timing. | ||
| + | |||
| + | ==== Finite State Machine ==== | ||
| + | |||
| + | The game logic is implemented as a finite state machine. | ||
| + | |||
| + | ^ State ^ Description ^ | ||
| + | | IDLE | Waits for the START button | | ||
| + | | WAIT_RANDOM | Waits for a pseudo-random interval before showing the signal | | ||
| + | | SIGNAL_ACTIVE | Turns on one LED and measures the reaction time | | ||
| + | | ROUND_RESULT | Displays the result of the current round and updates the score | | ||
| + | | GAME_OVER | Displays the final score and waits for restart | | ||
| + | |||
| + | ==== Scoring System ==== | ||
| + | |||
| + | A point is awarded only if: | ||
| + | |||
| + | * the user presses the correct button; | ||
| + | * the reaction time is below 600 ms. | ||
| + | |||
| + | If the user presses the wrong button, presses too early or exceeds the maximum allowed reaction time, no point is awarded. | ||
| + | |||
| + | ===== Obtained Results ===== | ||
| + | |||
| + | The project currently implements a working reaction trainer game using LEDs, buttons, a potentiometer and UART output. | ||
| + | |||
| + | The user can start the game using the START button. During each round, the system turns on either the red LED or the yellow LED. The user must press the corresponding button as fast as possible. | ||
| + | |||
| + | At the current stage, the results are displayed through UART in the Serial Monitor because the display module has not arrived yet. The display will be added later in order to show the round number, reaction time and score directly on the device. | ||
| + | |||
| + | The system detects: | ||
| + | |||
| + | * correct answers; | ||
| + | * wrong answers; | ||
| + | * premature button presses; | ||
| + | * timeout situations; | ||
| + | * reaction times below or above the scoring threshold. | ||
| + | |||
| + | The reaction time and score are displayed through UART in the serial monitor. | ||
| + | |||
| + | Example output: | ||
| + | |||
| + | === reaction trainer start === | ||
| + | runda 1 / 5 | ||
| + | corect, timp reactie = 421 ms | ||
| + | punct acordat | ||
| + | |||
| + | runda 2 / 5 | ||
| + | gresit, timp reactie = 730 ms | ||
| + | |||
| + | === final joc === | ||
| + | scor final: 3 / 5 | ||
| + | |||
| + | ===== Conclusions ===== | ||
| + | |||
| + | The project demonstrates the use of several ATmega328P peripherals in a practical embedded application. | ||
| + | |||
| + | The firmware uses GPIO for LEDs and buttons, ADC for reading the potentiometer, UART for communication with the PC and Timer1 for measuring time. The game logic is implemented using a finite state machine, which makes the program easier to understand and extend. | ||
| + | |||
| + | The project was initially tested using simpler high-level code, then rewritten using AVR registers in order to better reflect the hardware-level programming concepts required for the course. | ||
| + | |||
| + | Possible future improvements include: | ||
| + | |||
| + | * adding a passive buzzer for sound feedback; | ||
| + | * integrating the display module for local output; | ||
| + | * adding a local web interface on the PC; | ||
| + | * storing best scores; | ||
| + | * increasing the number of reaction modes. | ||
| + | |||
| + | ===== GitHub Resources ===== | ||
| ===== Timeline ===== | ===== Timeline ===== | ||
| - | 28.04.2026 - Alegere temă proiect. | + | ^ Date ^ Activity ^ |
| + | | April 2026 | Project idea selection: Reaction Trainer | | ||
| + | | 04.05.2026 | Block diagram created and initial wiki documentation written | | ||
| + | | 18.05.2026 | Software implementation still incomplete - some hardware components had not arrived yet | | ||
| - | 04.05.2026 - Creare pagină documentație. | + | ===== Bibliography / Resources ===== |
| - | ===== Bibliografie ===== | + | ==== Hardware Resources ==== |
| * [[https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/UserGuides/ATmega328P-Xplained-Mini-UG-DS50002659B.pdf|ATmega328P Xplained Mini User Guide]] | * [[https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/UserGuides/ATmega328P-Xplained-Mini-UG-DS50002659B.pdf|ATmega328P Xplained Mini User Guide]] | ||
| + | |||
| + | ==== Software Resources ==== | ||
| + | |||
| + | * [[https://docs.platformio.org/|PlatformIO Documentation]] | ||