Guides

Your First Project

Create your first AI-assisted PLC program step by step

Your First Project

In this tutorial, you'll create a simple motor control function block using PLC Assist. By the end, you'll understand the basic workflow of AI-assisted PLC development.

Prerequisites

Before starting, make sure you have:

  • PLC Assist account created
  • Bridge installed and working (see installation guide)
  • A PLC project open in your environment (CODESYS, TwinCAT XAE, etc.)

If you haven't set these up yet, see the installation guide.

What We'll Build

We'll create a function block called FB_SimpleMotor that:

  • Starts a motor when a start button is pressed
  • Stops the motor when a stop button is pressed
  • Includes a run timer to track operating time
  • Has an emergency stop that immediately stops the motor

Step 1: Connect to Your Project

  1. Open your PLC environment with your project
  2. Start the PLC Assist bridge
  3. Open PLC Assist in your browser
  4. Verify the bridge shows as connected

The bridge should show as connected in PLC Assist.

Step 2: Create a New Function Block

In the AI chat, type:

Create a new function block called FB_SimpleMotor with these features:
- Inputs: bStart (BOOL), bStop (BOOL), bEmergencyStop (BOOL)
- Outputs: bRunning (BOOL), tRunTime (TIME)
- When bStart goes TRUE and motor is not running, start the motor
- When bStop goes TRUE, stop the motor
- bEmergencyStop immediately stops the motor regardless of other inputs
- tRunTime should track how long the motor has been running

Step 3: Review the Generated Code

The AI will generate code similar to this:

FUNCTION_BLOCK FB_SimpleMotor
VAR_INPUT
    bStart : BOOL;
    bStop : BOOL;
    bEmergencyStop : BOOL;
END_VAR

VAR_OUTPUT
    bRunning : BOOL;
    tRunTime : TIME;
END_VAR

VAR
    tonRunTimer : TON;
    bStartEdge : BOOL;
    bPrevStart : BOOL;
END_VAR

// Detect rising edge of start
bStartEdge := bStart AND NOT bPrevStart;
bPrevStart := bStart;

// Motor control logic
IF bEmergencyStop THEN
    bRunning := FALSE;
ELSIF bStop THEN
    bRunning := FALSE;
ELSIF bStartEdge AND NOT bRunning THEN
    bRunning := TRUE;
END_IF

// Run time tracking
tonRunTimer(IN := bRunning, PT := T#24H);
IF bRunning THEN
    tRunTime := tonRunTimer.ET;
ELSE
    tRunTime := T#0S;
END_IF

Take a moment to review:

  • Are the variable names appropriate?
  • Does the logic match what you wanted?
  • Is the timer implementation correct?

Step 4: Accept the Changes

If the code looks good:

  1. Click Accept to apply the changes
  2. The code will be sent to your PLC environment
  3. Watch for compilation results

If you see any errors, the AI can help fix them.

Step 5: Enhance with AI

Let's add a feature. Ask the AI:

Add a speed input (rSpeed: REAL, 0-100%) and speed output to FB_SimpleMotor.
The motor should only run if speed is greater than 0.

Review and accept the changes.

Step 6: Add Error Handling

One more enhancement:

Add error detection to FB_SimpleMotor:
- bError output that goes TRUE if speed exceeds 100%
- nErrorCode output: 0 = no error, 1 = overspeed
- Motor should not run while bError is TRUE

Congratulations!

You've created your first AI-assisted function block! You learned how to:

  • Create new code with natural language prompts
  • Review and apply AI-generated changes
  • Iteratively enhance code with additional requests
  • Handle compilation feedback

What's Next?

On this page