Mikrodev/stcoder-gemma4-12b-ggufFine-tuned from google/gemma-4-12b-it apache-2.0GGUF · Ollama / llama.cpp

stcoder-gemma4-12b

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.

Base model
gemma-4-12b-itgoogle/gemma-4-12b-it
Builds
3Q4_K_M / Q6_K / Q8_0
Smallest
6.9 GiBQ4_K_M
Recommended
Q8_011.80 GiB
Dialect-clean
86.7%base: 6.7%
Tool calling
Not supportedchat only
1

Which build should you download?

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.

13.8 GiB free VRAM
Q8_0gemma4_12b-tc.q8_0.gguf · 11.80 GiB
recommended crashed on a 16 GiB card in our own testing at 8k context - if that happens, drop to Q6_K
11.1 GiB free VRAM
Q6_Kgemma4_12b-tc.q6_k.gguf · 9.11 GiB
fine — the build this study ran
8.9 GiB free VRAM
Q4_K_Mgemma4_12b-tc.q4_k_m.gguf · 6.87 GiB
not recommended

Short answer

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.

Why not Q4_K_M

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.

FileQuantisationSizeFit on 16 GBNote
gemma4_12b-tc.q4_k_m.ggufQ4_K_M6.87 GiBsolid
gemma4_12b-tc.q6_k.ggufQ6_K9.11 GiBsolidtested in this study
gemma4_12b-tc.q8_0.ggufQ8_011.80 GiBtightrecommended
2

Is this the right model for you?

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.

Table — the four models on identical measurements
Same 15 requests, realistic prompt, greedy decoding. ChrF is averaged over delivered replies so the denominator is the same for every model.
ModelCleanDeliveredChrFComposite Out tokPer replyRecommended build
stcoder-qwen25-7b
7B · default pick, fastest per answer
93.3%15/1538.50.8443405.8sQ8_0 · 7.54 GiB
stcoder-qwen25-14b
14B · only one 100% clean in both conditions
100.0%15/1534.90.8422888.6sQ8_0 · 14.62 GiB
stcoder-qwen35-9b
9B · reasoning family, highest ChrF when it answers
93.3%14/1540.90.845122717.2sQ8_0 · 9.11 GiB
stcoder-gemma4-12b (this model)
12B · non-Qwen lineage, weakest fine-tune case
86.7%15/1535.90.834018.5sQ8_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.

Read this before you start

  • Chat only — no tool calling. You describe what you need and the model writes Structured Text. Tool calling was trained and evaluated for this line: the Qwen3.5-9B family did learn it (tool-call composite 0.816 at Q8_0, falling to 0.642 at Q4_K_M) while the code-focused families scored 0.02–0.06 and the Gemma family exactly 0.00. Because it was not usable across the line, tool calling was dropped as a product decision and these builds are published and supported as chat models. Do not build an agent on them.
  • Always compile before deployment. The model produces dialect-correct code, which is not the same as correct control logic. Compile it in LogicStudio and review the logic.
  • It is a small local model. Expect to iterate on a prompt, not to receive a finished project.
3

Set-up, step by step

  1. Install Ollama

    Any recent release. Confirm it is running before continuing.

    ollama --version
  2. Download one GGUF file

    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 .
  3. Write a Modelfile next to the GGUF

    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
  4. Create the Ollama model

    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
  5. Smoke-test it

    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."
  6. Reproduce the study numbers (optional)

    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
  7. Compile before you deploy

    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.

4

What to ask it first

These are ordinary single-purpose requests, the kind this model handles well. Type them as they are.

Grain dryer discharge auger with a pre-start siren. When the operator presses start, the siren sounds for 8 seconds, then the auger motor runs and the siren goes quiet. Stop or any fault drops both immediately.
A short body-only block: VAR_INPUT / VAR_OUTPUT, a TON armed positionally with an 8000 ms constant, and the siren and motor derived from the timer output.
Fresh scenario, not one of the 15 study prompts. On the study's equivalent timer prompt this model was rule-clean, but its reply used a done-flag that it cleared again on the next scan - check that the run request is properly sealed in.
Baghouse fan run-on. The dust collector fan follows the hammer mill and keeps running 45 seconds after the mill stops so the ducting clears. Emergency stop cuts both at once. Give me a purge-in-progress flag for the HMI.
A very short block using one off-delay or on-delay timer with a 45000 ms preset, plus a purge flag derived from fan-on-while-mill-off.
Fresh scenario, not one of the 15 study prompts. Read the timer arming carefully: on the study's run-on prompt this model drove the timer from NOT bMotorRun rather than from the motor itself.
Pump-house strobe done in software. While the low-level alarm is active the strobe is lit for 250 ms then dark for 2 seconds, repeating. When the alarm clears the strobe stays off.
Two millisecond constants (250 and 2000) and a small two-state phase machine or a pair of on-delays.
Fresh scenario, not one of the 15 study prompts. On the study's blink prompt this model put the trigger input in a plain VAR block and left a placeholder comment about a tick source, so move the input to VAR_INPUT and check the phase timers actually reset.
Start/stop seal-in for a chlorine dosing pump. The start button must be held for 300 ms before the pump picks up, the thermal overload latches the pump out, and the lockout only clears when stop is pressed with the overload already reset. NC stop button, TRUE means healthy.
A debounce on-delay with a 300 ms preset, an overload latch, and a seal-in latch feeding the contactor output, plus a separate lockout output.
Fresh scenario, not one of the 15 study prompts. State the wiring convention as shown: on the study's seal-in prompt this model omitted the separate lockout output and treated the stop button as TRUE-when-pressed even though the prompt said NC.
Scale a 0-10 V tank level transmitter to metres. 0 counts is 0 V, 32767 counts is 10 V, and the tank is ranged 0-6 m. Clamp the result to 0-6, set a wire-break flag below 160 counts, and force the output to zero when the enable bit is off.
REAL constants for the raw and engineering endpoints, straight-line arithmetic with no conversion call, and IF-based clamping instead of a LIMIT function.
Fresh scenario, not one of the 15 study prompts. If you also want a rounded integer for the HMI, say "no conversion functions" explicitly: on the study's scaling-helper prompt this model reached for REAL_TO_INT(pressureBar * 10.0).
Operators enter a chilled water setpoint on the HMI. Pull anything below 6.0 or above 14.0 degC back to the nearest limit and raise an out-of-range warning the operator can acknowledge. The setpoint sent to the controller must not move more than 0.5 degC per scan.
An IF/ELSIF clamp with a warning bit, an acknowledge path, and a per-scan ramp using a 0.5 degC step constant.
Fresh scenario, not one of the 15 study prompts. A good first exercise in getting clamping without MIN/MAX/LIMIT, which the dialect forbids; the study's equivalent clamp prompt was rule-clean at R24 100.
Motor winding temperature watchdog. Average the last 16 temperature samples, and latch a trip bit if the average stays above 130.0 degC for 5 seconds. Only the reset pushbutton clears it.
A 1-D ARRAY ring buffer, an averaging loop, and a TON with a 5000 ms preset feeding a latch.
Fresh scenario, not one of the 15 study prompts, but close in spirit to one of the three contrast examples below. Expect to add the FOR loop index to the VAR block yourself: in the study's averaging prompt the model wrote FOR i := 0 TO 7 DO without ever declaring i.
Palletiser case counter. A photo eye pulses once for every case that passes. I need a lifetime total for the maintenance record and a shift total that the supervisor clears at handover. Count on the rising edge of the photo eye only.
Two counters, edge detection on the photo-eye input, and a reset that clears the shift total without touching the lifetime total.
Fresh scenario, not one of the 15 study prompts. Ask for edge detection in so many words, as above: in the study's counter prompt the model's comment said "on every rising edge" while the code tested the input level, and it also declared lifetimeCount : DINT RETAIN, a retain qualifier the dialect forbids and the pattern checker did not catch.
5

What fine-tuning changed, measured

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.

Figure 1 — dialect-clean replies out of 15
Clean means: code was delivered and it broke no dialect rule
basethis fine-tune
No rules in promptrealistic use
6.7%
86.7%
Full rule book in promptcharitable to base
73.3%
80.0%
Figure 2 — per-prompt outcome, no rules in prompt
One tick per test prompt, same order in both rows
cleanrule violation no code delivered
Base
Fine-tune
MeasureBaseThis fine-tuneBase + full rulesFine-tune + full rules
Dialect-clean replies6.7%86.7%73.3%80.0%
Delivered code at all100.0%100.0%80.0%100.0%
R24 rule compliance92.5599.6199.7599.41
ChrF vs reference code27.735.924.932.9
Output tokens (mean · median)2490 · 2411401 · 3604585 · 4362921 · 354
Time per reply34.7s8.5s63.1s16.5s
Throughput79.5 t/s72.7 t/s82.8 t/s68.4 t/s
Opened with prose, not code100.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.

6

Which dialect rules the base model breaks

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.

Figure 3 — base-model rule violations, gemma4:12b — all 9 rules it broke
bar length = share of delivered replies that broke the rule, full width = 100%
no_named_paramminimal · full rules
7/15
0/12
no_TIME_literalminimal · full rules
7/15
0/12
no_pou_programminimal · full rules
6/15
0/12
no_power_opminimal · full rules
3/15
0/12
no_pou_fbminimal · full rules
3/15
0/12
no_based_literalminimal · full rules
1/15
1/12
no_cast_functionminimal · full rules
2/15
0/12
no_output_arrowminimal · full rules
1/15
0/12
no_structminimal · full rules
1/15
0/12

For comparison, this fine-tune's violations across its 15 delivered replies in the same condition: no_based_literal×1, no_cast_function×1.

7

The same request, side by side

Highlighted tokens are the ones that decide whether the code is accepted by the IDE. Both columns are verbatim model output.

Reusable pump block: four rules broken at once, then none

reusable_pump_block · program_structure · no dialect rules in the system prompt

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

Base · gemma4:12b R24 85.29 · 5239 tok
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_fb
STCoder fine-tune R24 100.0 · 793 tok
Here 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 violations

Minimal 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.

Drilling station sequencer: three timer calls, three violations

machine_cycle_full_program · program_structure · no dialect rules in the system prompt

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

Base · gemma4:12b R24 91.18 · 3024 tok
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
STCoder fine-tune R24 100.0 · 629 tok
```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 violations

Minimal 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.

Heater overload: the POU wrapper and the TIME literal both go

heater_power_avg_squared · analog_math · no dialect rules in the system prompt

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.

Base · gemma4:12b R24 85.29 · 2008 tok
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
STCoder fine-tune R24 100.0 · 327 tok
```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 violations

Minimal 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.

8

Every test prompt and its result

All 15 prompts, realistic condition (no rules in the system prompt). Prompt text is in the appendix below.

PromptBaseR24ChrFtok Fine-tuneR24ChrFtokRules the base broke
analog_scale_raw_to_bar
analog_math
violation94.1235.021959clean100.042.66360no_cast_function, no_pou_program
setpoint_clamp_and_ramp
analog_math
violation97.0640.712511clean100.039.27306no_pou_program
heater_power_avg_squared
analog_math
violation85.2936.182008clean100.042.32327no_TIME_literal, no_named_param, no_pou_program, no_power_op
timer_start_delay
timer_time_based
violation91.1823.232551clean100.044.61307no_TIME_literal, no_named_param
timer_blink_oscillator
timer_time_based
violation91.1827.991811clean100.034.53414no_TIME_literal, no_named_param
timer_offdelay_coastdown
timer_time_based
violation91.1819.962857clean100.033.24180no_TIME_literal, no_named_param
io_terminal_seal_in
io_misc
violation88.2433.632820clean100.042.55399no_TIME_literal, no_named_param, no_pou_program
status_word_bit_mask
io_misc
violation94.1240.251695violation97.0638.85351no_based_literal, no_pou_program
first_out_fault_annunciator
io_misc
violation94.1240.232874clean100.043.69599no_pou_program, no_power_op
machine_cycle_full_program
program_structure
violation91.1815.473024clean100.041.56629no_TIME_literal, no_named_param
reusable_pump_block
program_structure
violation85.2915.095239clean100.034.44793no_TIME_literal, no_named_param, no_output_arrow, no_pou_fb
analog_scale_helper
program_structure
violation94.1233.112184violation97.0625.55385no_cast_function, no_pou_fb
retain_counter_power_cycle
data_memory
clean100.010.391670clean100.019.81226
shared_project_value
data_memory
violation97.0637.01734clean100.031.78278no_pou_fb
machine_data_grouping
data_memory
violation94.126.982411clean100.023.09455no_power_op, no_struct
9

Q4, Q6 and Q8 — what actually differs

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.

Evidence base — and its limit

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.

10

Strengths, weaknesses, and what not to use it for

Strengths

Weaknesses

Not the right tool for

11

How the numbers were produced

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).

Limitations

  • Quantisation was not matched. The fine-tune ran at higher precision than the stock base build. This plausibly helps the fine-tune on quality and demonstrably penalises it on raw throughput.
  • “Clean” is not “correct”. R24 is reference-free: it certifies that no forbidden construct appears, not that the logic works. Correctness was checked by reading the code, not by compiling it.
  • The published builds do not ship this decoding configuration. These numbers were measured greedily (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.
  • Scope. 15 prompts, one dialect, English only, no tool-calling, and the prompt set was deliberately built on the categories where this dialect diverges from standard IEC. It measures dialect fidelity on dialect-sensitive work, not general PLC competence.
  • Small sample. 15 prompts per condition per model. Treat single-prompt differences as anecdote and the aggregate as the signal.
12

In summary

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.

A

Appendix — the test prompts

IDPrompt as sent to the model
analog_scale_raw_to_barWe 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_rampOperators 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_squaredHeater 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_delayWe'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_oscillatorNeed 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_coastdownOur 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_inOn 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_maskWe 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_annunciatorI 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_programCan 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_blockWe 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_helperI 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_cycleLine 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_valueTank 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_groupingI 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.