{"id":27882993,"url":"https://github.com/kmoraza/inverter_drive_simulator","last_synced_at":"2025-07-23T13:32:56.622Z","repository":{"id":289127669,"uuid":"970213240","full_name":"KMORaza/Inverter_Drive_Simulator","owner":"KMORaza","description":"Das ist eine Desktop-App, die in der C-Programmiersprache geschrieben ist und einen elektrischen Wechselrichterantrieb simuliert. (Desktop app written in C programming language which simulates electrical inverter drive.); Developed: 21 April 2025","archived":false,"fork":false,"pushed_at":"2025-04-23T09:50:54.000Z","size":327,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T06:11:34.931Z","etag":null,"topics":["c-language","c-programming","electrical-circuits","electrical-engineering","electrical-system","induction-motor","induction-motors","inverter-drive","mathematics","mechanical-engineering","physics","simulation","simulations","simulator","simulators","variable-frequency-drive"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KMORaza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-21T16:56:53.000Z","updated_at":"2025-05-04T14:36:27.000Z","dependencies_parsed_at":"2025-04-21T17:55:40.879Z","dependency_job_id":null,"html_url":"https://github.com/KMORaza/Inverter_Drive_Simulator","commit_stats":null,"previous_names":["kmoraza/inverter_drive_simulator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KMORaza/Inverter_Drive_Simulator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KMORaza%2FInverter_Drive_Simulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KMORaza%2FInverter_Drive_Simulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KMORaza%2FInverter_Drive_Simulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KMORaza%2FInverter_Drive_Simulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KMORaza","download_url":"https://codeload.github.com/KMORaza/Inverter_Drive_Simulator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KMORaza%2FInverter_Drive_Simulator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266688999,"owners_count":23969140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-language","c-programming","electrical-circuits","electrical-engineering","electrical-system","induction-motor","induction-motors","inverter-drive","mathematics","mechanical-engineering","physics","simulation","simulations","simulator","simulators","variable-frequency-drive"],"created_at":"2025-05-05T06:10:56.242Z","updated_at":"2025-07-23T13:32:56.545Z","avatar_url":"https://github.com/KMORaza.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Inverter Drive Simulator\n\nThis is a desktop app, written to simulate a variable frequency drive (VFD) controlling an induction motor. It provides a user interface for configuring motor and drive parameters, simulating input signals, monitoring motor behavior, injecting faults, and visualizing real-time plots. \n\n## Application Structure\n\nThe simulator is organized into modular C files, each handling specific functionality:\n\n- **main.c**: Initializes the GTK application, sets the dark theme (`gtk-application-prefer-dark-theme`), and activates the main window.\n- **gui.c/h**: Manages the GUI layout using a `GtkGrid` with controls on the left (motor parameters, drive settings, input signals, control panel, fault inputs, outputs) and plots on the right (voltage, current, frequency, torque, speed).\n- **inverter.c/h**: Handles inverter calculations, including line-to-line voltage (`V_L-L`) and PWM waveform generation.\n- **motor.c/h**: Simulates an induction motor with V/f control, calculating speed, torque, current, and temperature.\n- **fault.c/h**: Detects and manages faults (overcurrent, undervoltage, overtemperature) with manual injection and reset capabilities.\n- **waveform.c/h**: Renders five real-time plots using `GtkDrawingArea` and Cairo, currently displaying a placeholder voltage waveform for all parameters.\n\n## GUI Layout\n\nThe GUI is divided into two main sections within a `GtkGrid`:\n\n- **Left Columns (0–3)**:\n  - **Status Label**: Displays \"Running\", \"Stopped\", or \"Faulted\" with direction (Forward/Reverse).\n  - **Motor Parameters**: Text entries for rated voltage (V), current (A), frequency (Hz), and RPM.\n  - **Drive Settings**: Entries for ramp up/down times (s), max/min frequency (Hz), and a combo box for control mode (V/f only, with placeholders for vector control, sensorless vector, DTC).\n  - **Input Signals**: Slider for speed reference (0–100%), Forward/Reverse buttons.\n  - **Control Panel**: Run, Stop, Reset buttons, and a keypad entry for parameter updates (currently sets rated voltage).\n  - **Fault Inputs**: Checkboxes for manual fault injection (overcurrent, undervoltage, overtemperature).\n  - **Output Labels**: Show calculated V_L-L, current, speed, torque, frequency, and fault/error messages.\n- **Right Column (4)**:\n  - **Plot Area**: Five stacked plots (voltage, current, frequency, torque, speed) rendered with Cairo, each with a grid, waveform, and label. \n\nThe dark theme ensures a dark background with light text and bright plot colors (blue waveform, light gray grid).\n\n## Simulation Logic\n\nThe simulation runs in a timed loop (50 ms interval) triggered by the \"Run\" button and managed in `gui.c` (`update_simulation` function). \n\nKey steps include:\n\n1. **Input Collection**:\n\n   - Reads motor parameters, drive settings, speed reference, and fault checkboxes from GUI widgets.\n   - Parameters: Rated voltage (1–10,000 V), current (1–1,000 A), frequency (1–1,000 Hz), RPM (1–10,000), ramp up/down (0–60 s), max/min frequency (0–1,000 Hz, min ≤ max).\n   - Speed reference: Slider value (0–100%) scales to max frequency.\n\n2. **Input Validation**:\n\n   - Checks for valid ranges (e.g., `rated_voltage \u003e 0`, `max_freq \u003e min_freq`).\n   - Displays error messages in the error label (e.g., \"Invalid Rated Voltage (1–10000 V)\") and stops simulation if invalid.\n\n3. **Motor and Inverter Update**:\n\n   - Updates motor parameters (`motor.c`: `set_motor_params`) and drive settings (`set_drive_params`).\n   - Sets inverter parameters (`inverter.c`: `set_inverter_params`) with rated voltage, target frequency (from speed reference), and fixed modulation index (0.8).\n   - Updates motor state (`update_motor`) with target frequency, direction, and ramp times.\n\n4. **Fault Handling**:\n\n   - Checks automatic faults (`fault.c`: `check_faults`) based on thresholds: current \u0026gt; 20 A, voltage \u0026lt; 300 V, temperature \u0026gt; 80°C.\n   - Applies manual faults if checkboxes are active (`trigger_fault`).\n   - Stops simulation and updates status/error labels if a fault occurs.\n\n5. **Output Calculation**:\n\n   - Calculates V_L-L (`calculate_vll`), motor current, speed, torque, and frequency (`get_motor_*` functions).\n   - Updates output label with formatted values (e.g., \"V_L-L: 392.30 V\\\\nCurrent: 8.00 A\\\\n...\").\n   - Queues plot redraw (`gtk_widget_queue_draw`).\n\n6. **Plot Rendering**:\n\n   - Draws five plots in `waveform.c` (`draw_waveform`), each with a grid, waveform, and label.\n   - Currently uses a placeholder voltage waveform (`get_pwm_waveform`) scaled to max values (e.g., 1.1 \\* V_dc for voltage).\n\nThe simulation stops when:\n\n- \"Stop\" button is clicked (`is_running = FALSE`).\n- A fault is detected or injected (`has_fault()`).\n- Invalid inputs are entered.\n\nThe \"Reset\" button clears faults, unchecks fault boxes, and updates the status.\n\n## Key Calculations\n\nThe simulator uses simplified models for inverter and motor behavior, focusing on V/f control. Below are the main calculations:\n\n### Inverter Calculations (`inverter.c`)\n\n- **Line-to-Line Voltage (V_L-L)**:\n  - Formula: `V_L-L = m_a * V_dc * sqrt(3) / sqrt(2)`\n  - `m_a` (modulation index) is fixed at 0.8.\n  - `V_dc` is the rated voltage from motor parameters.\n  - Example: For V_dc = 400 V, `V_L-L = 0.8 * 400 * sqrt(3) / sqrt(2) ≈ 392.30 V`.\n- **PWM Waveform**:\n  - Generates a sinusoidal waveform: `V(t) = m_a * V_dc * sin(2π * freq * t)`.\n  - `freq` is the target frequency (speed reference \\* max frequency).\n  - Samples: 100 points over one period (`1/freq`).\n\n### Motor Calculations (`motor.c`)\n\n- **Speed**:\n  - Target speed: `(target_freq / rated_freq) * rated_rpm * (is_forward ? 1 : -1)`.\n  - Applies ramping: Acceleration = `rated_rpm / ramp_up`, deceleration = `rated_rpm / ramp_down`.\n  - Updates every 50 ms: `current_speed += accel * 0.05` or `-decel * 0.05`, clamped to target.\n  - Example: For target_freq = 50 Hz, rated_freq = 50 Hz, rated_rpm = 1500, speed = 1500 RPM (forward).\n- **Frequency**:\n  - Derived from speed: `current_freq = |current_speed / rated_rpm| * rated_freq`.\n- **Torque**:\n  - Simplified (constant torque load): `torque = rated_current * rated_voltage / rated_rpm * |current_speed|`.\n  - Example: For rated_current = 10 A, rated_voltage = 400 V, rated_rpm = 1500, speed = 1500 RPM, `torque ≈ 106.67 Nm`.\n- **Current**:\n  - Proportional to frequency: `current = rated_current * (current_freq / rated_freq)`.\n  - Example: For current_freq = 40 Hz, rated_freq = 50 Hz, rated_current = 10 A, `current = 8 A`.\n- **Temperature**:\n  - Increases with current: `temp += current * 0.01` per cycle, minimum 25°C (ambient).\n  - Example: For current = 10 A, temp increases by 0.1°C every 50 ms.\n\n### Fault Detection (`fault.c`)\n\n- **Overcurrent**: Triggered if `current \u003e 20 A`.\n- **Undervoltage**: Triggered if `voltage \u003c 300 V`.\n- **Overtemperature**: Triggered if `temp \u003e 80°C`.\n- Manual faults override automatic checks when checkboxes are active.\n\n## Parameters\n\nThe application handles the following user-configurable parameters, validated in `gui.c`:\n\n| Parameter | Range | Default | Description |\n| --- | --- | --- | --- |\n| Rated Voltage (V) | 1–10,000 | 400 | Motor rated voltage (V_dc for inverter). |\n| Rated Current (A) | 1–1,000 | 10 | Motor rated current. |\n| Rated Frequency (Hz) | 1–1,000 | 50 | Motor rated frequency. |\n| Rated RPM | 1–10,000 | 1500 | Motor rated speed. |\n| Ramp Up Time (s) | 0–60 | 2 | Time to reach rated speed. |\n| Ramp Down Time (s) | 0–60 | 2 | Time to stop from rated speed. |\n| Max Frequency (Hz) | 0–1,000 (\u0026gt; min) | 100 | Maximum output frequency. |\n| Min Frequency (Hz) | 0–max_freq | 10 | Minimum output frequency. |\n| Speed Reference (%) | 0–100 | 50 | Scales target frequency (min to max). |\n| Control Mode | V/f (others N/A) | V/f | Motor control mode (V/f implemented). |\n| Direction | Forward/Reverse | Forward | Motor rotation direction. |\n| Faults (Overcurrent, etc.) | On/Off | Off | Manual fault injection. |\n| Keypad Value | Any number | N/A | Updates rated voltage (simplified). |\n\n## Simulation Characteristics\n\n- **Input Signals**:\n  - Speed reference slider scales target frequency (`speed_ref * max_freq / 100`).\n  - Forward/Reverse buttons toggle motor direction (`is_forward`).\n  - Run/Stop/Reset buttons control simulation state and fault clearing.\n- **Motor Behavior**:\n  - V/f control: Voltage and frequency are proportional (`V/f = constant`).\n  - Ramps speed based on user-defined ramp times.\n  - Simulates constant torque load (simplified).\n- **Graphical Monitoring**:\n  - Five plots (600x600 pixels total, 80 pixels per plot) show voltage, current, frequency, torque, and speed.\n  - Placeholder: All plots use the PWM voltage waveform scaled to max values (e.g., 1.1 \\* V_dc for voltage).\n- **Fault Handling**:\n  - Automatic detection based on thresholds.\n  - Manual injection via checkboxes.\n  - Faults stop simulation and display status (e.g., \"Fault: Overcurrent\").\n- **Control Panel**:\n  - Replicates a VFD panel with Run, Stop, Reset, Forward/Reverse buttons.\n  - Keypad entry simulates parameter editing (limited to voltage).\n\n![](https://github.com/KMORaza/Inverter_Drive_Simulator/blob/main/screenshot.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmoraza%2Finverter_drive_simulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkmoraza%2Finverter_drive_simulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmoraza%2Finverter_drive_simulator/lists"}