From e7549b73920184b291c95604b216d44cab310e4f Mon Sep 17 00:00:00 2001 From: Florian Agbuya Date: Thu, 29 Aug 2024 17:29:19 +0800 Subject: [PATCH] test write_ramp --- fast-servo/pyfastservo/dac.py | 38 +++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/fast-servo/pyfastservo/dac.py b/fast-servo/pyfastservo/dac.py index 617047f..e448ae0 100644 --- a/fast-servo/pyfastservo/dac.py +++ b/fast-servo/pyfastservo/dac.py @@ -124,6 +124,12 @@ def write_sample(channel, sample): for addr, value in zip(addresses, values): write_to_memory(addr, value) +def write_ramp(): + signal = [i for i in range(16384)] + + for value in signal: + write_sample(0, value) + def configure_ad9117(): spi = spidev.SpiDev() @@ -148,25 +154,27 @@ def configure_ad9117(): power_down(1, False) manual_override(True) - # Write sample value 0x1FFF to both channels - sample_value = 0x1FFF - write_sample(0, sample_value) # Write to channel 0 - write_sample(1, sample_value) # Write to channel 1 + write_ramp() - print(f"Sample value 0x{sample_value:04X} written to both channels") + # # Write sample value 0x1FFF to both channels + # sample_value = 0x1FFF + # write_sample(0, sample_value) # Write to channel 0 + # write_sample(1, sample_value) # Write to channel 1 - # Read back the values from memory - ch0_high = read_from_memory(CH0_HIGH_WORD_ADDR, 1)[0] - ch0_low = read_from_memory(CH0_LOW_WORD_ADDR, 1)[0] - ch1_high = read_from_memory(CH1_HIGH_WORD_ADDR, 1)[0] - ch1_low = read_from_memory(CH1_LOW_WORD_ADDR, 1)[0] + # print(f"Sample value 0x{sample_value:04X} written to both channels") - # Reconstruct the 14-bit values - ch0_value = (ch0_high << 8) | ch0_low - ch1_value = (ch1_high << 8) | ch1_low + # # Read back the values from memory + # ch0_high = read_from_memory(CH0_HIGH_WORD_ADDR, 1)[0] + # ch0_low = read_from_memory(CH0_LOW_WORD_ADDR, 1)[0] + # ch1_high = read_from_memory(CH1_HIGH_WORD_ADDR, 1)[0] + # ch1_low = read_from_memory(CH1_LOW_WORD_ADDR, 1)[0] - print(f"Read back value for channel 0: 0x{ch0_value:04X}") - print(f"Read back value for channel 1: 0x{ch1_value:04X}") + # # Reconstruct the 14-bit values + # ch0_value = (ch0_high << 8) | ch0_low + # ch1_value = (ch1_high << 8) | ch1_low + + # print(f"Read back value for channel 0: 0x{ch0_value:04X}") + # print(f"Read back value for channel 1: 0x{ch1_value:04X}") print("AD9117 configuration completed successfully") return True