サークルで活動するには参加が必要です。
「サークルに参加する」ボタンをクリックしてください。
※参加を制限しているサークルもあります。
-
from: 生成門さん
2026/09/08 20:41:10
icon
AIとの対話(AIとAIによるピコマシンのコラボの最終版)
python
"""
=====================================================================
Anti-Entropy Pulse Generator (VIC/AEG: Pico-Machine)
Firmware Version 1.1 - Full Integrated Flicker Edition (Reviewed)
=====================================================================
- 出力ピン: GPIO15(高速ゲートドライバ TC4427 の IN A へ直結)
- 状態機械: SM0
- デューティ: 黄金分割(ON=0.618 / OFF=0.382)
- 変調: ロジスティック写像による1/f風カオスゆらぎ
- 役割:
PIO = 急峻なON/OFFの刃
CPU = 周期の動的更新
注意:
- 完全フローティング(電池 / モバイルバッテリー)駆動が前提
- PC(USB)接続しながらの生体照射は禁止
- まずはPico単体でGPIO15の波形確認を行うこと
=====================================================================
"""
import rp2
from machine import Pin
import machine
import time
# =========================================================
# 1. クロック設定
# =========================================================
# 仕様上の目標: 137MHz
# 不安定な場合は自動的に125MHzへ戻す
TARGET_FREQ = 137000000
FALLBACK_FREQ = 125000000
def setup_clock():
try:
machine.freq(TARGET_FREQ)
freq_now = machine.freq()
print("clock set:", freq_now)
return freq_now
except Exception as e:
print("137MHz failed:", e)
machine.freq(FALLBACK_FREQ)
freq_now = machine.freq()
print("fallback clock:", freq_now)
return freq_now
SM_FREQ = setup_clock()
# =========================================================
# 2. PIOプログラム
# =========================================================
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def ir_asym_pulse():
label("top")
pull(block) # CPUから32bit受信
out(x, 16) # ONカウント
out(y, 16) # OFFカウント
set(pins, 1) # 立ち上がり優先
label("on_loop")
jmp(x_dec, "on_loop")
set(pins, 0) # 立ち下がり
label("off_loop")
jmp(y_dec, "off_loop")
jmp("top")
# =========================================================
# 3. StateMachine 初期化
# =========================================================
PIN_OUT = 15
SM_ID = 0
output_pin = Pin(PIN_OUT, Pin.OUT)
sm = rp2.StateMachine(
SM_ID,
ir_asym_pulse,
freq=SM_FREQ,
set_base=output_pin
)
# =========================================================
# 4. ユーティリティ
# =========================================================
def make_counts(period_counts):
"""
総カウントを黄金比デューティに分割して32bitへパッキング
下位16bit=ON, 上位16bit=OFF
"""
period_counts = int(period_counts)
if period_counts < 2:
period_counts = 2
on_c = int(period_counts * 0.618)
off_c = period_counts - on_c
if on_c < 1:
on_c = 1
if off_c < 1:
off_c = 1
return (on_c & 0xFFFF) | ((off_c & 0xFFFF) << 16)
def period_from_hz(target_hz, sm_freq):
if target_hz <= 0:
target_hz = 1.0
return max(2, int(sm_freq / float(target_hz)))
def push_if_room(period_counts):
"""
FIFOが満杯ならスキップして詰まりを防ぐ
"""
if sm.tx_fifo() < 4:
sm.put(make_counts(period_counts))
# =========================================================
# 5. モードとカオス初期値
# =========================================================
# モード1: 低周波帯(内臓寄り)
# モード2: 高周波帯(背中・表層寄り)
current_mode = 1
k = 0.352
MODE_SWITCH_MS = 15000
UPDATE_MS = 10
print("=====================================================")
print(" VIC/AEG Pico-Machine FW 1.1")
print(" pin = GPIO{}".format(PIN_OUT))
print(" freq = {} Hz".format(SM_FREQ))
print(" duty = ON0.618 / OFF0.382")
print("=====================================================")
# =========================================================
# 6. 起動
# =========================================================
# モード1の中央付近から開始
init_hz = 25.0
sm.put(make_counts(period_from_hz(init_hz, SM_FREQ)))
sm.active(1)
last_mode_switch = time.ticks_ms()
last_update = time.ticks_ms()
# =========================================================
# 7. メインループ
# =========================================================
while True:
now = time.ticks_ms()
# --- 10msごとにゆらぎ更新 ---
if time.ticks_diff(now, last_update) >= UPDATE_MS:
# 4倍ロジスティック写像
k = 4.0 * k * (1.0 - k)
# 数値の枯渇・固着を避ける軽い保護
if k <= 0.000001 or k >= 0.999999:
k = 0.352
if current_mode == 1:
# 10〜40Hz
target_hz = 10.0 + (k * 30.0)
else:
# 1000〜3000Hz
target_hz = 1000.0 + (k * 2000.0)
period_counts = period_from_hz(target_hz, SM_FREQ)
push_if_room(period_counts)
last_update = now
# --- 15秒ごとにモード切替デモ ---
if time.ticks_diff(now, last_mode_switch) >= MODE_SWITCH_MS:
current_mode = 2 if current_mode == 1 else 1
last_mode_switch = now
print("mode -> {}".format(current_mode))
time.sleep_ms(1)サークルで活動するには参加が必要です。
「サークルに参加する」ボタンをクリックしてください。
※参加を制限しているサークルもあります。
コメント: 全0件


