Guides
Prompting Tips
How to write effective prompts for better AI results
Prompting Tips
The quality of AI-generated code depends heavily on how you phrase your requests. This guide will help you write prompts that get better results.
Core Principles
1. Be Specific
The more specific your request, the better the result.
// Less effective
"Create a timer"
// More effective
"Create a TON timer called tonDelay with PT of 5 seconds
that starts when bStart is TRUE"2. Include Data Types
Always specify the data types you want:
// Less effective
"Add a temperature variable"
// More effective
"Add a REAL variable called rTemperature with range -40.0 to 200.0"3. Describe the Behavior
Explain what should happen, not just what you want:
// Less effective
"Add motor control"
// More effective
"Add motor control where:
- bStart rising edge starts the motor
- bStop sets motor to off
- Motor can only start if bReady is TRUE"Prompt Templates
Creating a Function Block
Create a function block called [NAME] that:
- Inputs: [list inputs with types]
- Outputs: [list outputs with types]
- Internal variables: [list any needed]
- Behavior: [describe the logic]Adding Features
Add [FEATURE] to [EXISTING CODE]:
- [specific requirement 1]
- [specific requirement 2]
- Keep existing functionalityImplementing Algorithms
Implement [ALGORITHM NAME]:
- Input parameters: [list]
- Output: [describe]
- Requirements: [list any specific requirements]Debugging Help
I'm getting this error: [ERROR MESSAGE]
In this code: [PASTE CODE]
What's wrong and how do I fix it?Advanced Techniques
Reference Existing Code
The AI knows your project context. Use it:
"Create FB_Pump similar to FB_Motor but for pump control"
"Use the same error handling pattern as FB_Conveyor"Provide Examples
Show the AI what you want:
Create a state machine like this pattern:
CASE nState OF
0: (* Idle *)
IF bStart THEN nState := 10; END_IF
10: (* Running *)
IF bStop THEN nState := 0; END_IF
END_CASE
But for a 5-step wash cycle process.Ask for Alternatives
"Show me two different ways to implement this debounce logic"
"What's a better way to structure this state machine?"What to Avoid
Don't Be Vague
// Avoid these
"Make it better"
"Add some error handling"
"Fix this"Don't Ask for Too Much at Once
Break large requests into smaller steps:
// Instead of:
"Create a complete HVAC control system"
// Do this:
Step 1: "Create FB_TemperatureControl for heating/cooling"
Step 2: "Create FB_FanControl for ventilation"
Step 3: "Create FB_HVACMain that coordinates temperature and fan control"Iteration is Key
Don't expect perfection on the first try. It's normal to:
- Make an initial request
- Review the result
- Ask for modifications
- Repeat until satisfied