code wiki / _hdl_build / nx_hairbake_probe.nx
nx_hairbake_probe.nx source
↩ module page · 46 lines · 1663 B
1// nx_hairbake_probe.nx -- scratch v3: is the hair chain STABLE? Seed a small release and watch the
2// tip's envelope over 4200 ticks (70 s sim). Decay to zero = stable (long transient); a sustained
3// band = limit cycle = the integrator itself oscillates and no seed amplitude can fix the table.
4import "nx_syscalls.nx"
5import "nx_softdyn.nx"
6import "nx_softbind.nx"
7import "nx_hairdyn_lib.nx"
8import "nx_gate_verdict.nx"
9
10const PB_NSEG: i64 = 7
11const PB_SEGLEN: i64 = 256
12const PB_WIN: i64 = 300
13const PB_NWIN: i64 = 14
14
15func main() -> i64 {
16 let n: i64 = PB_NSEG
17 let seglen: i64 = PB_SEGLEN
18 let st: *i64 = hd_alloc(n)
19 hd_seat(st, n, 0, 0, 0, seglen)
20 var s: i64 = 0
21 while s < HD_RD_SETTLE {
22 hd_tick(st, n, 0, 0, 0, seglen, SB_K_HAIR, SB_C_HAIR, SB_MAXD_HAIR)
23 s = s + 1
24 }
25 gv_puts("V3 post-settle tip_x=" as *u8); gv_num(hd_tip_x_q8(st, n)); gv_puts("\n" as *u8)
26 let amp: i64 = PB_SEGLEN/4
27 var d: i64 = 0
28 while d < n { st[d*SD_STRIDE] = st[d*SD_STRIDE] + amp; d = d + 1 }
29 gv_puts("V3 seed amp_q8=" as *u8); gv_num(amp)
30 gv_puts(" envelope: window-max |tip_x| per " as *u8); gv_num(PB_WIN); gv_puts(" ticks\n" as *u8)
31 var w: i64 = 0
32 while w < PB_NWIN {
33 var pk: i64 = 0
34 var t: i64 = 0
35 while t < PB_WIN {
36 hd_tick(st, n, 0, 0, 0, seglen, SB_K_HAIR, SB_C_HAIR, SB_MAXD_HAIR)
37 var v: i64 = hd_tip_x_q8(st, n)
38 if v < 0 { v = 0 - v }
39 if v > pk { pk = v }
40 t = t + 1
41 }
42 gv_puts(" win " as *u8); gv_num(w); gv_puts(": " as *u8); gv_num(pk); gv_puts("\n" as *u8)
43 w = w + 1
44 }
45 return 0
46}