stcoder-gemma4-12b is a Gemma-4-12B-it fine-tune that writes Mikrodev LogicStudio Structured Text as a chat reply. It is published and supported as a chat-only model with no tool calling, and it is the weakest of the four fine-tuning cases in this study, so choose it only when you specifically want a non-Qwen lineage as a second opinion. The line's default is stcoder-qwen25-7b at Q8_0.
This is a fine-tune for the Structured Text coding rules of Advance Logic Builder (ALB), the IEC 61131-3 engineering environment developed by Mikrodev and shipped as Mikrodev LogicStudio. It follows Mikrodev's ST dialect, not generic IEC 61131-3 and not another vendor's conventions.
Start from the graphics memory you have. Every build below is the same fine-tune; they differ only in how heavily the weights are compressed.
Download Q8_0 (gemma4_12b-tc.q8_0.gguf, 11.80 GiB).
Q8_0 is the smallest build with no practically measurable loss against the trained weights - it is the precision we recommend for real work. Free VRAM needed: about
13.8 GiB — the file plus the 8192-token context and runtime.
Q4_K_M halves the bits per weight again. The only capability we measured across quantisations degraded sharply - tool-call composite 0.816 at Q8_0 against 0.642 at Q4_K_M, measured on the Qwen3.5-9B family, the only one of the four where tool-calling worked at all - and low-bit quantisation is a known source of drift and hallucination on long or unusual requests. Our 15-prompt code study never ran at Q4, so we have no measured code-quality figure for it: treat this as a precaution, not a measured code-quality gap.
Also published for this model. The LoRA adapter it was trained as
(lora_adapter/ in the same repository) so you can merge it at any
precision or continue training from it, and the f16 merged weights
(f16 is the merged fine-tune at full precision: the reference build, for evaluation or for producing your own quantisations.). Ready-to-run Ollama Modelfiles ship next to every build:
correct chat template, stop tokens, num_ctx 8192 — the sequence length this
model was fine-tuned at — and the system prompt.
| File | Quantisation | Size | Fit on 16 GB | Note |
|---|---|---|---|---|
gemma4_12b-tc.q4_k_m.gguf | Q4_K_M | 6.87 GiB | solid | |
gemma4_12b-tc.q6_k.gguf | Q6_K | 9.11 GiB | solid | tested in this study |
gemma4_12b-tc.q8_0.gguf | Q8_0 | 11.80 GiB | tight | recommended |
Read this first. Tool calling was trained and evaluated for this product line, but it was not usable across the line, so it was dropped as a product decision: stcoder-gemma4-12b is published and supported as a chat-only model. Measured tool-call composite was 0.816 for the Qwen3.5-9B family at Q8_0 (0.805 at Q6_K, 0.642 at Q4_K_M), 0.02-0.06 for the code-focused Qwen2.5-Coder builds, and exactly 0.00 for this Gemma family. This is the only STCoder build on Google Gemma rather than Qwen, which makes it useful as an architecturally independent cross-check: when two different lineages produce the same block, you have some evidence the request was unambiguous. That is the reason to pick it, and it is the only one supported by the data. Head-to-head figures from this study (minimal system prompt, 15 prompts per model, greedy decoding at seed 42; ChrF averaged over DELIVERED replies so the denominator is identical across models): model clean delivery ChrF composite out-tok wall stcoder-qwen25-7b 93.3% 100% (15/15) 38.5 0.844 340 5.8 s stcoder-qwen25-14b 100.0% 100% (15/15) 34.9 0.842 288 8.6 s stcoder-qwen35-9b 93.3% 93.3% (14/15) 40.9 0.845 1227 17.2 s stcoder-gemma4-12b 86.7% 100% (15/15) 35.9 0.830 401 8.5 s So its 86.7% clean (13 of 15) is the lowest of the four, and its composite 0.830 is the lowest. Its ChrF is NOT the lowest in this study: 35.9 is above the 14B's 34.9. It is the lowest of the four only in the earlier 2000-prompt evaluation (38-41 there, against 47-52 for the Qwen-based siblings), and those absolute code scores must not be used to rank models against each other: that evaluation's code holdout overlapped the training distribution by about 84%, so its code figures are inflated and weakly discriminative between models. They are cited in this card only for the within-model quant comparison. Two disclosures that bound every base-versus-fine-tune claim below. First, quantisation was not controlled in the head-to-head: the fine-tune ran at Q6_K (Ollama tag stcoder_gemma4-12b:q6) while the stock base ran the Ollama library default (base tag gemma4:12b). The run data records no quantisation for the base arms, so "effectively Q4" is an inference from the library default, not a recorded value. Second, R24 and clean rates quoted here are computed over the WHOLE reply. Base replies were prose-wrapped 66.7-100% of the time while fine-tune replies were 0-20.0%, so whole-reply scoring flatters the fine-tune; scoring only the fenced code moves the pooled base clean rate from 6.7% to 10.0%, and this model's own base figure from 6.7% (1 of 15) to 20.0% (3 of 15). The gap survives either variant, but the variant has to be named. This is also the one model where prompting alone nearly closes the gap, and in one respect closes it. Given the whole rule book in the system prompt, the stock base is 73.3% clean (11 of 15) against this fine-tune's 80.0% (12 of 15) - roughly level - and the base's mean R24 in that condition is actually HIGHER than the fine-tune's: 99.80 pooled over all 15 rows, 99.75 over its 12 delivered replies, against the fine-tune's 99.41. The fine-tune still wins the full condition on delivery (15 of 15 against 12 of 15) and on ChrF (32.9 against 24.9 over delivered replies), but if you are willing to paste a long rule preamble every session, the fine-tune buys you much less on this lineage than it does on the other three. Which one should I download. Default: stcoder-qwen25-7b at Q6_K (5.82 GiB). It is the fastest per answer (5.8 s), the smallest, joint-top on composite (0.844), and highest on ChrF at full delivery (38.5 over 15 of 15). Choose stcoder-qwen25-14b at Q4_K_M (8.37 GiB) on 16 GiB or more if you want the one model that was 100% rule-clean and 0% prose in both conditions, accepting the lowest head-to-head ChrF (34.9) and the slowest generation per token (about 50 tok/s). Choose stcoder-qwen35-9b only if you want the reasoning family, accepting one empty reply in fifteen and the slowest wall time per answer (17.2 s). Choose stcoder-gemma4-12b only for non-Qwen lineage diversity, or because you already run Gemma locally, with the caveats above.
| Model | Clean | Delivered | ChrF | Composite | Out tok | Per reply | Recommended build |
|---|---|---|---|---|---|---|---|
stcoder-qwen25-7b7B · default pick, fastest per answer | 93.3% | 15/15 | 38.5 | 0.844 | 340 | 5.8s | Q8_0 · 7.54 GiB |
stcoder-qwen25-14b14B · only one 100% clean in both conditions | 100.0% | 15/15 | 34.9 | 0.842 | 288 | 8.6s | Q8_0 · 14.62 GiB |
stcoder-qwen35-9b9B · reasoning family, highest ChrF when it answers | 93.3% | 14/15 | 40.9 | 0.845 | 1227 | 17.2s | Q8_0 · 9.11 GiB |
stcoder-gemma4-12b (this model)12B · non-Qwen lineage, weakest fine-tune case | 86.7% | 15/15 | 35.9 | 0.83 | 401 | 8.5s | Q8_0 · 11.80 GiB |
How to read this. The 14B has the highest clean rate (100%). The 9B has the highest ChrF among delivered replies (40.9) but delivered on only 14 of 15, so at full delivery the 7B leads (38.5). Composites for the 9B, 7B and 14B (0.845 / 0.844 / 0.842) are within noise of each other. Sizes are GiB throughout. If you are undecided, take stcoder-qwen25-7b at Q8_0.
Any recent release. Confirm it is running before continuing.
ollama --version
Q4_K_M (6.87 GiB) is the recommended default. Use Q6_K (9.11 GiB) on a 16 GiB card if you want the exact build used in the evaluation. Q8_0 is 11.8 GiB and needs more than 16 GiB.
hf download Mikrodev/stcoder-gemma4-12b-gguf gemma4_12b-tc.q4_k_m.gguf --local-dir .
Deterministic decoding and a short system prompt. For this model a short prompt is the better default: pasting the whole rule book lowered its clean rate from 86.7% to 80.0% and its ChrF from 35.9 to 32.9.
cat > Modelfile <<'EOF' FROM ./gemma4_12b-tc.q4_k_m.gguf PARAMETER temperature 0 PARAMETER top_p 1 PARAMETER num_ctx 8192 # the published numbers were measured with num_ctx 16384 / num_predict 8192 # num_predict 2048 is a practical local default (longest reply in the study: 708 tokens); raise it to 8192 to reproduce them or if a long block truncates PARAMETER num_predict 2048 SYSTEM """You write IEC 61131-3 Structured Text for the Mikrodev LogicStudio IDE. Reply with the code body only: variable blocks plus logic, no POU wrapper. Timer presets are INT milliseconds. Function blocks are called positionally.""" EOF
One-off import. Takes a minute or two depending on disk speed. This is a chat-only model; do not attach tool definitions to it.
ollama create stcoder-gemma4-12b:q4 -f Modelfile
You should get a short reply that is mostly one code block: VAR blocks, a TON called positionally, and a millisecond preset. No PROGRAM or FUNCTION_BLOCK line, no T#5s.
ollama run stcoder-gemma4-12b:q4 "Grain dryer discharge auger. Start button sounds a siren for 8 seconds, then the auger runs and the siren stops. Stop or any fault drops both immediately."
The head-to-head in this card used these exact Ollama tags. Fine-tunes: stcoder_qwen25-7b:q8, stcoder_qwen25-14b:q6, stcoder_qwen35-9b:q8, stcoder_gemma4-12b:q6. Bases: qwen2.5-coder:7b, qwen2.5-coder:14b, qwen3.5:9b, gemma4:12b. The base arms' quantisation was NOT recorded in the run data, so the Ollama library default (effectively Q4) is an inference, not a measurement - quantisation was not controlled across the base and fine-tune arms. The study's q6 build is a different file from the q4 default recommended above, so edit the Modelfile's FROM line to the q6 GGUF before running ollama create.
# the Modelfile written in step 3 points at the q4 file - repoint it before creating the q6 tag hf download Mikrodev/stcoder-gemma4-12b-gguf gemma4_12b-tc.q6_k.gguf --local-dir . # edit Modelfile: FROM ./gemma4_12b-tc.q6_k.gguf ollama create stcoder_gemma4-12b:q6 -f Modelfile ollama pull gemma4:12b # base arm, library default quant
Paste the block into LogicStudio and compile it. This is not optional. The rule checker used in the evaluation is reference-free and pattern-based, and in this model's own test rows it passed code that would not compile, including a FOR loop whose index variable was never declared.
These are ordinary single-purpose requests, the kind this model handles well. Type them as they are.
The same 15 requests were sent to the stock base model
(gemma4:12b) and to this fine-tune, twice: once with a short realistic
system prompt that lists no dialect rules, and once with the entire rule book pasted in.
Greedy decoding, fixed seed, identical prompts.
| Measure | Base | This fine-tune | Base + full rules | Fine-tune + full rules |
|---|---|---|---|---|
| Dialect-clean replies | 6.7% | 86.7% | 73.3% | 80.0% |
| Delivered code at all | 100.0% | 100.0% | 80.0% | 100.0% |
| R24 rule compliance | 92.55 | 99.61 | 99.75 | 99.41 |
| ChrF vs reference code | 27.7 | 35.9 | 24.9 | 32.9 |
| Output tokens (mean · median) | 2490 · 2411 | 401 · 360 | 4585 · 4362 | 921 · 354 |
| Time per reply | 34.7s | 8.5s | 63.1s | 16.5s |
| Throughput | 79.5 t/s | 72.7 t/s | 82.8 t/s | 68.4 t/s |
| Opened with prose, not code | 100.0% | 20.0% | 80.0% | 6.7% |
On throughput: the fine-tune is served here at higher precision than the stock base model (Ollama's default build is more heavily compressed), so it generates more slowly per token. Quantisation was not matched in this comparison — see the limitations.
Counted over replies that actually contained code. The upper bar is the realistic condition; the lower, lighter bar is with the full rule book in the system prompt — the difference shows which habits an instruction can fix and which it cannot.
no_named_paramminimal · full rulesno_TIME_literalminimal · full rulesno_pou_programminimal · full rulesno_power_opminimal · full rulesno_pou_fbminimal · full rulesno_based_literalminimal · full rulesno_cast_functionminimal · full rulesno_output_arrowminimal · full rulesno_structminimal · full rulesFor comparison, this fine-tune's violations across its 15 delivered
replies in the same condition: no_based_literal×1, no_cast_function×1.
Highlighted tokens are the ones that decide whether the code is accepted by the IDE. Both columns are verbatim model output.
The request: We have three identical booster pumps on a skid and I am tired of copy-pasting the same logic three times. Give me one reusable pump control block that I can instantiate once per pump. Per instance: run request, motor thermal overload contact, dry-run (low suction) switch, fault reset. Outputs: motor run command, fault flag, and a fault code for the HMI so the operator can see what tripped. Behavi
To solve this problem efficiently in Mikrodev LogicStudio, we will create a **Function Block (FB)**. This allows you to define the logic once and then "instantiate" it three times in your main program, each with its own set of inputs and outputs.
### 1. The Function Block: `FB_PumpControl`
Create a new Function Block named `FB_PumpControl`. This block handles all the timing, fault logic, and state management for a single pump.
**Variables (Declaration):**
```pascal
FUNCTION_BLOCK FB_PumpControl
VAR_INPUT
xRunRequest : BOOL; // Request from HMI/PLC to run
xOverload : BOOL; // Physical input from motor overload relay
xDryRun : BOOL; // Input from dry-run sensor
xReset : BOOL; // Reset button for faults
END_VAR
VAR_OUTPUT
xMotorRun : BOOL; // Command to the motor contactor
xFault : BOOL; // Fault status for HMI
iFaultCode : INT; // 0=OK, 1=Overload, 2=Dry Run
END_VAR
VAR
timerStart : TON; // Handles the 2s start delay
timerDryRun : TON; // Tracks the 5s grace period for dry run
timerStopLock : TON; // Handles the 10s "off" timer
END_VAR
```
**Implementation (Structured Text):**
```pascal
(* --- Fault Logic --- *)
(* Overload takes priority. If it exists, code is 1. *)
IF xOverload THEN
iFaultCode := 1;
ELSIF xDryRun AND timerDryRun.Q THEN
(* Dry run only triggers if the motor has been running for > 5s *)
iFaultCode := 2;
ELSE
iFaultCode := 0;
END_IF
no_TIME_literalno_named_paramno_output_arrowno_pou_fbHere is the reusable `PumpControl` block.
```iecst
VAR_INPUT
runReq : BOOL;
motorOver : BOOL;
dryRun : BOOL;
faultReset : BOOL;
END_VAR
VAR_OUTPUT
motorRun : BOOL;
faultFlag : BOOL;
faultCode : INT;
END_VAR
VAR
startDelay : TON;
dryRunDelay : TON;
stopDelay : TON;
latched : BOOL;
faultLatched: BOOL;
END_VAR
VAR CONSTANT
START_MS : INT := 2000;
DRYRUN_MS : INT := 5000;
STOP_MS : INT := 10000;
END_VAR
// 1. Fault detection and latching
IF motorOver OR (motorRun AND dryRun) THEN
faultLatched := TRUE;
faultCode := 0;
IF motorOver THEN faultCode := 1; END_IF;
IF (motorRun AND dryRun) THEN faultCode := 2; END_IF;
END_IF;
// 2. Fault reset
IF faultReset AND NOT motorOver AND NOT (motorRun AND dryRun) THEN
faultLatched := FALSE;
END_IF;
faultFlag := faultLatched;
// 3. Start/Stop logic
IF faultLatched THEN
motorRun := FALSE;
ELSE
// Start delay: 2s after runReq
startDelay(runReq, START_MS);
// Stop delay: 10s after runReq goes FALSE
stopDelay(NOT runReq, STOP_MS);
// Motor run command
IF startDelay.Q AND NOT stopDelay.Q THEN
motorRun := TRUE;
ELSE
motorRun := FALSE;
END_IF;
END_IF;
// 4. Dry-run evaluation: only 5s after motorRun is TRUE
IF motorRun THEN
dryRunDelay(TRUE, DRYRUN_MS);
IF dryRunDelay.Q AND dryRun THEN
faultLatched := TRUE;
faultCode := 2;
END_IF;
ELSE
dryR
no violationsMinimal system prompt, same prompt and same seed for both arms; quantisation was not controlled, so the base ran the Ollama library default while the fine-tune ran Q6_K. The base produced the general-assistant answer you would expect and broke four rules in one file. It opened with FUNCTION_BLOCK FB_PumpControl, which the IDE does not accept because the IDE owns the POU shell and the model should emit the body only. It then called its timers with named parameters and TIME literals: timerDryRun(IN := xMotorRun, PT := T#5s) and timerStopLock(IN := NOT xMotorRun, PT := T#10s), with timerStart(IN := TRUE, PT := T#2s) later in the same reply. R24 85.29, the joint-lowest of its fifteen base rows, and 5239 tokens. The fine-tune dropped the wrapper, declared START_MS / DRYRUN_MS / STOP_MS as INT millisecond constants (2000, 5000, 10000) and called each timer positionally - startDelay(runReq, START_MS). It instantiated the three pumps positionally too, p1(runReq1, motorOver1, dryRun1, faultReset1, motorRun1, faultFlag1, faultCode1), with no => arrows anywhere. R24 100, ChrF 34.4, 793 tokens. Be straight about the logic, though: the minimum-off requirement is not actually enforced. It armed stopDelay(NOT runReq, STOP_MS) and then gated the motor on NOT stopDelay.Q, which does not hold the pump out for 10 seconds before a restart. The dialect is right; the sequence needs your review.
Red spans in the base panel are the exact substrings the rule checker matched. The fine-tune panel is shown unmarked because it broke no rule on this prompt — read it against the base, line for line.
The request: Can you write the complete program for our drilling station cycle? One part per cycle: when the guard is closed, a part is present and there are no alarms, pressing Start closes the clamp, waits 1.5 s for clamp pressure to build, then the drill motor starts and the head feeds down until the down limit switch, dwells 3 s at depth, retracts until the up limit, opens the clamp after 0.8 s, and the st
To implement this in Mikrodev LogicStudio, I have structured the program using a **State Machine** (using a `CASE` statement). This is the industry-standard way to handle sequential processes like drilling cycles because it ensures that only one step happens at a time and makes debugging much easier.
Here is the complete Structured Text (ST) code.
### Variable Declarations
You should define these variables in your Global Variable List (GVL) or the local variable area of your program:
```pascal
VAR
(* Inputs *)
i_GuardClosed : BOOL; // Physical sensor for safety gate
i_PartPresent : BOOL; // Sensor detecting a part
i_StartBtn : BOOL; // Operator Start button (Momentary)
i_DownLimit : BOOL; // Limit switch at bottom of stroke
i_UpLimit : BOOL; // Limit switch at top of stroke
i_EStop : BOOL; // E-Stop Button (Normally Closed - Logic High = OK)
i_Overload : BOOL; // Drill Motor Overload sensor
i_Reset : BOOL; // Manual Reset button
(* Outputs *)
q_Clamp : BOOL; // Solenoid to close/hold clamp
q_DrillMotor : BOOL; // Main drill motor
q_FeedDown : BOOL; // Actuator/Motor for downward movement
q_StatusLamp : BOOL; // Indicator light
(* Internal Logic *)
e_State : INT := 0; // Current step in the cycle
e_PartCount : INT; // Counter for finished parts
(* Timers *)
no_TIME_literalno_named_param```iecst
VAR_INPUT
bStart : BOOL;
bGuard : BOOL;
bPartPresent: BOOL;
bDownLimit : BOOL;
bUpLimit : BOOL;
bDrillOver : BOOL;
bReset : BOOL;
bEStop : BOOL;
END_VAR
VAR_OUTPUT
bClamp : BOOL;
bDrill : BOOL;
bFeedDown : BOOL;
bFeedUp : BOOL;
bFault : BOOL;
nPartCount : INT;
END_VAR
VAR
nStep : INT;
tClamp : TON;
tDrill : TON;
tDepth : TON;
tClampOpen : TON;
END_VAR
IF bEStop OR bDrillOver THEN
bClamp := FALSE;
bDrill := FALSE;
bFeedDown := FALSE;
bFeedUp := FALSE;
bFault := TRUE;
IF bReset THEN
bFault := FALSE;
nStep := 0;
END_IF;
ELSE
bFault := FALSE;
CASE nStep OF
0: // Idle - wait for start
IF bStart AND bGuard AND bPartPresent THEN
bClamp := TRUE;
nStep := 1;
END_IF;
1: // Clamp pressure build (1.5 s)
tClamp(NOT tClamp.Q, 1500);
IF tClamp.Q THEN
bDrill := TRUE;
bFeedDown := TRUE;
nStep := 2;
END_IF;
2: // Feed down until down limit
IF bDownLimit THEN
bFeedDown := FALSE;
nStep := 3;
END_IF;
3: // Dwell at depth (3 s)
tDrill(NOT tDrill.Q, 3000);
IF tDrill.Q THEN
bFeedDown := FALSE;
bFeedUp := TRUE;
nStep := 4;
END_IF;
4: // Retract until up limit
IF bUpLimit THEN
bFeedUp := FALSE;
nStep := 5;
END_IF;
5: // Clamp open (0.8 s)
bClamp := FALSE;
tCla
no violationsMinimal system prompt. Both models chose a CASE step sequencer, so the difference is in packaging and in how the timers are written. The base wrapped its answer in tutorial prose with headings such as "### Variable Declarations", declared the three delays as bare TON instances (timer_Pressure : TON;) and then, further down the reply than the excerpt shown here, called them as timer_Pressure(IN := TRUE, PT := T#1.5s), timer_Dwell(IN := TRUE, PT := T#3.0s) and timer_Release(IN := TRUE, PT := T#0.8s) - named parameters and TIME literals in every one, two rules broken three times each, R24 91.18, ChrF 15.5, 3024 tokens. It also inverted the overload sense in IF NOT i_EStop OR NOT i_Overload THEN, which would fault the station whenever the overload contact was healthy. The fine-tune wrote the same three delays as positional calls with integer millisecond presets: tClamp(NOT tClamp.Q, 1500), tDrill(NOT tDrill.Q, 3000), tClampOpen(NOT tClampOpen.Q, 800). R24 100, ChrF 41.6, 629 tokens, no prose. The dialect is correct throughout. The arming expression is not: driving a timer from NOT its own output makes it re-arm the scan after Q goes true, so Q pulses rather than latching, and the drill motor is never de-energised on retract. Compare it against the reference sequencer, which arms each timer from the active step number instead.
Red spans in the base panel are the exact substrings the rule checker matched. The fine-tune panel is shown unmarked because it broke no rule on this prompt — read it against the base, line for line.
The request: Heater panel job. I sample the load current every scan and it is noisy, so I need the average of the last 8 samples first. From that averaged current I want the dissipated power using P = I squared times R, with R = 4.7 ohm. If the power stays above 1500 W for 3 seconds, latch an overload bit that only clears when the operator hits the reset pushbutton. Please write it in Structured Text.
To implement this logic in Mikrodev LogicStudio, we will use an array to handle the rolling average of the current samples, a standard calculation for power, and a `TON` (Timer On Delay) function block to handle the 3-second duration requirement.
Here is the Structured Text code:
```pascal
PROGRAM Heater_Control
VAR
(* Inputs *)
I_raw : REAL; // Current sampled from sensor (Amps)
Reset_PB : BOOL; // Physical Reset Pushbutton
(* Internal Processing *)
I_Buffer : ARRAY[0..7] OF REAL; // Buffer for last 8 samples
i_Idx : INT := 0; // Index for the circular buffer
I_Sum : REAL; // Sum of buffer values
I_Avg : REAL; // Averaged current
(* Constants & Calculations *)
R_Value : REAL := 4.7; // Resistance in Ohms
Power : REAL; // Calculated Power (Watts)
(* Outputs *)
Overload : BOOL; // Latch bit for over-power condition
(* Timer *)
Timer_Overload : TON; // Timer to check 3s duration
END_VAR
***
(* 1. Rolling Average Logic *)
(* Store the current sample in the buffer and increment index *)
I_Buffer[i_Idx] := I_raw;
i_Idx := (i_Idx + 1) MOD 8;
(* Calculate the sum of all samples in the buffer *)
I_Sum := 0.0;
FOR i := 0 TO 7 DO
I_Sum := I_Sum + I_Buffer[i];
END_FOR;
(* Calculate average current *)
I_Avg := I_Sum / 8.0;
(* 2. Power Calculation *)
(* P = I^2 * R *)
Pow
no_TIME_literalno_named_paramno_pou_programno_power_op```iecst VAR_INPUT rCurrentSample : REAL; bResetBtn : BOOL; END_VAR VAR_OUTPUT bOverload : BOOL; END_VAR VAR rSamples : ARRAY[0..7] OF REAL; rAvgCurrent : REAL; rPower : REAL; rR : REAL := 4.7; rOverloadTimer : TON; rSampleIdx : INT := 0; END_VAR (* 8-sample moving average *) rSamples[rSampleIdx] := rCurrentSample; rSampleIdx := rSampleIdx + 1; IF rSampleIdx >= 8 THEN rSampleIdx := 0; END_IF; rAvgCurrent := 0.0; FOR i := 0 TO 7 DO rAvgCurrent := rAvgCurrent + rSamples[i]; END_FOR; rAvgCurrent := rAvgCurrent / 8.0; (* Power calculation *) rPower := rAvgCurrent * rAvgCurrent * rR; (* Overload detection: 3 seconds above 1500 W *) rOverloadTimer(rPower > 1500.0, 3000); (* Latch/Reset logic *) IF rOverloadTimer.Q THEN bOverload := TRUE; END_IF; IF bResetBtn THEN bOverload := FALSE; END_IF; ```
no violationsMinimal system prompt. The base opened with PROGRAM Heater_Control and declared everything inside it, which the IDE rejects outright, then timed the overload with Timer_Overload(IN := (Power > 1500.0), PT := T#3s); - a named parameter and a TIME literal in one line - and reached for ** in its explanatory text. Four rules broken, R24 85.29, ChrF 36.2, 2008 tokens. The fine-tune emitted the body only, split the signals into VAR_INPUT and VAR_OUTPUT, used ARRAY[0..7] OF REAL for the eight-sample buffer, squared the current by multiplying it with itself (rAvgCurrent * rAvgCurrent * rR, no ** operator) and timed the overload positionally as rOverloadTimer(rPower > 1500.0, 3000). R24 100 against 85.29, ChrF 42.3 against 36.2, 327 tokens against 2008. This is also the clearest illustration of what R24 does not measure. Both replies wrote FOR i := 0 TO 7 DO without ever declaring i, so neither would compile as delivered, and the fine-tune exposed only bOverload as an output while keeping the averaged current and the calculated power internal, where the reference publishes all three. Add the loop index and promote the two values you want on the HMI, then compile.
Red spans in the base panel are the exact substrings the rule checker matched. The fine-tune panel is shown unmarked because it broke no rule on this prompt — read it against the base, line for line.
All 15 prompts, realistic condition (no rules in the system prompt). Prompt text is in the appendix below.
| Prompt | Base | R24 | ChrF | tok | Fine-tune | R24 | ChrF | tok | Rules the base broke |
|---|---|---|---|---|---|---|---|---|---|
analog_scale_raw_to_baranalog_math | violation | 94.12 | 35.02 | 1959 | clean | 100.0 | 42.66 | 360 | no_cast_function, no_pou_program |
setpoint_clamp_and_rampanalog_math | violation | 97.06 | 40.71 | 2511 | clean | 100.0 | 39.27 | 306 | no_pou_program |
heater_power_avg_squaredanalog_math | violation | 85.29 | 36.18 | 2008 | clean | 100.0 | 42.32 | 327 | no_TIME_literal, no_named_param, no_pou_program, no_power_op |
timer_start_delaytimer_time_based | violation | 91.18 | 23.23 | 2551 | clean | 100.0 | 44.61 | 307 | no_TIME_literal, no_named_param |
timer_blink_oscillatortimer_time_based | violation | 91.18 | 27.99 | 1811 | clean | 100.0 | 34.53 | 414 | no_TIME_literal, no_named_param |
timer_offdelay_coastdowntimer_time_based | violation | 91.18 | 19.96 | 2857 | clean | 100.0 | 33.24 | 180 | no_TIME_literal, no_named_param |
io_terminal_seal_inio_misc | violation | 88.24 | 33.63 | 2820 | clean | 100.0 | 42.55 | 399 | no_TIME_literal, no_named_param, no_pou_program |
status_word_bit_maskio_misc | violation | 94.12 | 40.25 | 1695 | violation | 97.06 | 38.85 | 351 | no_based_literal, no_pou_program |
first_out_fault_annunciatorio_misc | violation | 94.12 | 40.23 | 2874 | clean | 100.0 | 43.69 | 599 | no_pou_program, no_power_op |
machine_cycle_full_programprogram_structure | violation | 91.18 | 15.47 | 3024 | clean | 100.0 | 41.56 | 629 | no_TIME_literal, no_named_param |
reusable_pump_blockprogram_structure | violation | 85.29 | 15.09 | 5239 | clean | 100.0 | 34.44 | 793 | no_TIME_literal, no_named_param, no_output_arrow, no_pou_fb |
analog_scale_helperprogram_structure | violation | 94.12 | 33.11 | 2184 | violation | 97.06 | 25.55 | 385 | no_cast_function, no_pou_fb |
retain_counter_power_cycledata_memory | clean | 100.0 | 10.39 | 1670 | clean | 100.0 | 19.81 | 226 | — |
shared_project_valuedata_memory | violation | 97.06 | 37.0 | 1734 | clean | 100.0 | 31.78 | 278 | no_pou_fb |
machine_data_groupingdata_memory | violation | 94.12 | 6.98 | 2411 | clean | 100.0 | 23.09 | 455 | no_power_op, no_struct |
Quantisation reduces the precision of the stored weights: Q8_0 is closest to the trained values, Q6_K is a middle ground, Q4_K_M is the smallest of the three published builds. All file sizes in this card are GiB as reported by the build tooling. For this model the practical spread is narrow. The earlier internal evaluation, which ran 2000 prompts across all three quants of these same fine-tunes, put the Gemma code composite between 0.800 and 0.810 and ChrF between 38 and 41 across Q4, Q6 and Q8. Dropping from Q8_0 (11.8 GiB) to Q4_K_M (6.87 GiB) therefore costs roughly one hundredth of a composite point on the code task while saving nearly 5 GiB of VRAM. That evaluation has to be read with one caveat, and it is a large one: its code holdout overlapped the training distribution by about 84%, so the absolute code scores are inflated and weakly discriminative between models. They are usable for the within-model quant comparison above - all three quants were scored on the same contaminated holdout, so the comparison between them is still informative - and they must not be used to rank stcoder-gemma4-12b against its siblings. For cross-model figures, use the head-to-head table in this card. One correction worth stating plainly, because an earlier version of the same report showed a much larger Q4 penalty. That penalty was measured on the tool-calling task, not on code, and it belonged to the Qwen3.5-9B family (tool-call composite 0.805 at Q6_K falling to 0.642 at Q4_K_M). This Gemma family scored exactly 0.00 on tool calling at every quant, and tool calling is not part of this release in any case. Structured Text generation is comparatively tolerant of low precision here. Two build-specific notes. The head-to-head study in this card was run at Q6_K, so those clean rates and ChrF figures describe that build. And Q8_0 is 11.8 GiB and has crashed on a 16 GiB card in internal testing, so the practical ceiling on a 16 GiB workstation is Q6_K. Q4_K_M is the recommended default.
From an earlier 2,000-prompt internal evaluation of these same fine-tunes: code composite 0.800-0.810 and ChrF 38-41 across Q4/Q6/Q8. The head-to-head study on this page used the Q6_K build. File sizes are GiB.
Important caveat. That earlier evaluation's code holdout overlapped the training distribution by roughly 84%, so its absolute code scores are inflated and only weakly separate one model from another. Use those figures for the within-model quantisation comparison, which is what they are cited for here — not to rank the four models against each other. For cross-model ranking use the identical-conditions table in section 2.
240 controlled generations across four model families, 15 prompts each, run twice per model
under two prompting conditions. Greedy decoding (temperature 0, seed 42),
8,192-token budget, local Ollama on an RTX 5080 (16 GB).
temperature 0,
seed 42) at
num_ctx 16384 /
num_predict 8192. The Modelfiles published with
the models default to temperature 0.2 and num_ctx 8192 — the
sequence length the models were trained at — because that is the better interactive
default. Match the three measured values to reproduce these figures; otherwise expect
run-to-run variation.On a short, realistic system prompt this fine-tune turns a stock Gemma-4-12B from 6.7% dialect-clean into 86.7% dialect-clean (1 of 15 to 13 of 15), removes TIME literals, named parameters and POU wrappers entirely, and does it in 401 tokens and 8.5 seconds instead of 2490 tokens and 34.7 seconds. Three caveats travel with that claim, and they apply to every card in this set. Quantisation was not controlled: the fine-tune ran Q6_K while the stock base ran the Ollama library default, an inference of effectively Q4 rather than a recorded value. The R24 and clean figures are computed over the whole reply; scoring only the fenced code lifts this model's base clean rate from 6.7% to 20.0% and the pooled base rate from 6.7% to 10.0%, without closing the gap. And tool calling was dropped as a product decision, so this is a chat-only model. That said, this is the honest limit of what the model buys you. It has the lowest clean rate and the lowest composite (0.830) of the four builds in the head-to-head, and it is the only one where a stock base given the whole rule book is roughly level with the fine-tune (73.3% clean against 80.0%) and actually scores higher on mean R24 in that condition (99.80 pooled, 99.75 over delivered, against 99.41). Pick it if you want a Gemma lineage or a second opinion that is not correlated with the Qwen models. If you have not decided, the line's default is stcoder-qwen25-7b at Q6_K (5.82 GiB); take stcoder-qwen25-14b at Q4_K_M (8.37 GiB) instead if rule-cleanliness matters more than speed. Either way the code is a draft: compile it in LogicStudio and read the sequence logic before it goes near a machine.
| ID | Prompt as sent to the model |
|---|---|
analog_scale_raw_to_bar | We have a 4-20 mA pressure transmitter landing on an analog input card. The raw word comes in as an integer where 5530 counts = 4 mA and 27648 counts = 20 mA, and the transmitter is ranged 0-16 bar. Can you write the Structured Text that turns the raw count into bar, keeps the result inside 0 to 16, and sets a wire-break flag when the loop current drops under about 3.6 mA (roughly 4977 counts)? There is also an enable bit coming from the scan logic - when that is off the scaled output should read zero. |
setpoint_clamp_and_ramp | Operators type a hot water setpoint on the HMI. Anything below 40.0 degC or above 85.0 degC has to be pulled back to the nearest limit and an out-of-range warning bit raised, which the operator can acknowledge once the entry is sensible again. On top of that, the setpoint that actually goes to the controller must not jump more than 2.0 degC per PLC cycle, so ramp it toward the clamped target. Structured Text please. |
heater_power_avg_squared | Heater panel job. I sample the load current every scan and it is noisy, so I need the average of the last 8 samples first. From that averaged current I want the dissipated power using P = I squared times R, with R = 4.7 ohm. If the power stays above 1500 W for 3 seconds, latch an overload bit that only clears when the operator hits the reset pushbutton. Please write it in Structured Text. |
timer_start_delay | We've got a conveyor with a pre-start warning horn. When the operator hits the start button I need the horn to sound for 5 seconds first, then the motor kicks in and the horn goes quiet. Pressing stop, or any fault coming in, has to drop the motor and the horn straight away. Can you write the Structured Text for this? |
timer_blink_oscillator | Need a flashing warning beacon done in ST. While the machine warning flag is active the lamp should blink continuously - lit for 500 ms, then dark for 1.5 seconds, over and over. When the warning clears the lamp stays off. There's no hardware flasher relay on this panel so it has to be done in software. |
timer_offdelay_coastdown | Our extraction fan needs a run-on timer. The fan should run whenever the main motor is running, and then keep running for 30 seconds after the motor is switched off so the duct clears. Emergency stop has to cut the motor and the fan immediately, with no run-on. Also give me a flag I can put on the HMI to show that the purge is in progress. Structured Text please. |
io_terminal_seal_in | On a small booster pump skid the start pushbutton is wired to the first digital input on the CPU and the pump contactor sits on the first relay output. There is an NC stop button on the second input and the motor thermal overload aux contact on the third. Write me the ST for a normal start/stop seal-in: the start button is bouncy so it has to be held for half a second before the pump picks up, an overload trip must latch the pump out, and the lockout should only clear when the operator presses stop with the overload already reset. |
status_word_bit_mask | We poll a 16-bit status word from a VFD over Modbus TCP. The drive manual gives the bit masks in hex: 16#0001 = ready, 16#0002 = running, 16#0008 = fault, 16#0080 = at speed, and 16#0F00 holds a 4-bit warning code. Break the word out into individual booleans, pull the warning code out as a plain integer 0-15, and give me a single 'drive healthy' flag that is only true when it is ready and running with no fault and no warning. If the Modbus poll is not valid, do not trust any of it. |
first_out_fault_annunciator | I need a first-out fault annunciator for a compressor package. The trip inputs are low oil pressure, high discharge temperature, motor overload and high vibration. Whichever one trips first has to be captured and reported to the HMI so the operator can tell at a glance which fault actually caused the trip - later trips must not overwrite it. I also want a common alarm lamp, a horn that goes quiet when acknowledge is pressed while the lamp stays on, and a reset that is only accepted when all four inputs are clear again. The compressor run permissive drops out on any fault. |
machine_cycle_full_program | Can you write the complete program for our drilling station cycle? One part per cycle: when the guard is closed, a part is present and there are no alarms, pressing Start closes the clamp, waits 1.5 s for clamp pressure to build, then the drill motor starts and the head feeds down until the down limit switch, dwells 3 s at depth, retracts until the up limit, opens the clamp after 0.8 s, and the station goes back to idle ready for the next part while incrementing the part counter. E-stop or drill overload must drop every output and put the station into a fault state that only the reset button clears. I want the step sequencing and the timers in there. |
reusable_pump_block | We have three identical booster pumps on a skid and I am tired of copy-pasting the same logic three times. Give me one reusable pump control block that I can instantiate once per pump. Per instance: run request, motor thermal overload contact, dry-run (low suction) switch, fault reset. Outputs: motor run command, fault flag, and a fault code for the HMI so the operator can see what tripped. Behaviour: 2 s start delay after the run request, the dry-run switch is only evaluated 5 s after the motor has actually started, overload trips immediately, any trip latches until it is reset, and once the pump stops it has to stay off for at least 10 s before it may restart. Also show me how it gets called for the three pumps. |
analog_scale_helper | I need a small reusable routine that turns the raw analog word from our pressure transmitters into engineering units, because I have to do the same conversion for three transmitters on the line. They are 4-20 mA into a 0-32767 count input card, so 6553 counts is 4 mA and 32767 counts is 20 mA, and the measuring range is 0-250 bar. It should clamp the result to the range and set an out-of-range flag, plus a broken-wire flag when the raw count drops below 3200 (under 2 mA). A rounded integer in tenths of a bar for the HMI would be handy too. |
retain_counter_power_cycle | Line 3 bottler: a photo eye (bPartDetect) pulses once for every bottle that goes past. I need two totals out of it - a lifetime total that goes into the maintenance records, and a shift total that the supervisor clears with bShiftReset at the start of each shift. The problem is we power the cabinet down every night and in the morning both totals come back as zero, so quality has no numbers to report. Write the ST for the counting logic so the lifetime total is still correct after the panel comes back up. |
shared_project_value | Tank farm project. The level control block works out the tank level in percent and a plant-running flag. The alarm block, the Modbus reporting block and the HMI block all need to see exactly the same two values on every scan - right now each of them recalculates them on its own and they end up disagreeing with each other. Write the level control block so those two values are produced in one place and the rest of the project can use them. Inputs are rLevelRaw from the transmitter (already scaled 0-100), bPumpRunning, bValveOpen and bEStop; the published percent should stay inside 0-100 and a transmitter reading outside range has to be flagged. |
machine_data_grouping | I have three identical packaging machines in one project. For each machine I track a temperature setpoint, the actual temperature, the belt speed, a cycle counter and a state code. I would like each machine's values kept together so I can run the same monitoring logic over all three in a loop instead of copy-pasting the same block three times. Logic per machine: if it is in the running state and the actual temperature is more than 5 degrees off setpoint, or the belt speed drops below 10, fault it; count a cycle on each rising edge of that machine's cycle-done input; EStop faults all of them. Also give me how many machines are currently faulted. Write it in ST. |