pulse modulation added

This commit is contained in:
Ayzen
2026-09-01 18:09:03 +03:00
parent 4c6292d6aa
commit 62e0430668
9 changed files with 123 additions and 16 deletions
+20 -4
View File
@@ -22,6 +22,7 @@ from .constants import (
AD9102_SRAM_SAMPLE_MAX,
AD9102_SRAM_SAMPLE_MIN,
AD9102_WAVE_MAX_CHUNK_SAMPLES,
AD9102_WAVE_PERIOD_US_MAX,
AD9102_WAVE_SAMPLE_MAX,
AD9102_WAVE_SAMPLE_MIN,
AD9833_FREQ_WORD_MAX,
@@ -533,8 +534,12 @@ class LaserController:
len(waveform_bytes),
)
def upload_ad9102_waveform(self, samples: Sequence[int]) -> None:
"""Upload and commit a custom AD9102 waveform from signed 14-bit samples."""
def upload_ad9102_waveform(self, samples: Sequence[int], pat_period_us: int = 0) -> None:
"""Upload and commit a custom AD9102 waveform from signed 14-bit samples.
``pat_period_us`` sets the pattern repetition period in microseconds;
0 keeps the legacy back-to-back playback.
"""
if not samples:
raise InvalidParameterError("samples", "At least two samples are required")
sample_list = [self._validate_wave_sample(sample, index) for index, sample in enumerate(samples)]
@@ -544,13 +549,24 @@ class LaserController:
"samples",
f"Sample count must be in range [{AD9102_SRAM_SAMPLE_MIN}, {AD9102_SRAM_SAMPLE_MAX}]",
)
if not 0 <= int(pat_period_us) <= AD9102_WAVE_PERIOD_US_MAX:
raise InvalidParameterError(
"pat_period_us",
f"Repetition period must be in range [0, {AD9102_WAVE_PERIOD_US_MAX}] us",
)
self._send_and_expect_ok(Protocol.encode_ad9102_wave_begin(sample_count))
self._send_and_expect_ok(
Protocol.encode_ad9102_wave_begin(sample_count, int(pat_period_us))
)
for start in range(0, sample_count, AD9102_WAVE_MAX_CHUNK_SAMPLES):
chunk = sample_list[start:start + AD9102_WAVE_MAX_CHUNK_SAMPLES]
self._send_and_expect_ok(Protocol.encode_ad9102_wave_data(chunk))
self._send_and_expect_ok(Protocol.encode_ad9102_wave_commit())
logger.info("Uploaded AD9102 waveform with %d samples", sample_count)
logger.info(
"Uploaded AD9102 waveform with %d samples, period %d us",
sample_count,
int(pat_period_us),
)
def cancel_ad9102_waveform_upload(self) -> None:
"""Cancel an in-progress AD9102 custom waveform upload."""