forked from M-Labs/nix-servo
Compare commits
7 Commits
232c9e3bb3
...
15b8b3fa6a
Author | SHA1 | Date |
---|---|---|
Florian Agbuya | 15b8b3fa6a | |
Florian Agbuya | 125611f51e | |
Florian Agbuya | 25524856b9 | |
Florian Agbuya | 79315d3d1b | |
Florian Agbuya | 8b20379427 | |
Florian Agbuya | 15a66c01fa | |
Sebastien Bourdeauducq | 2d75b4112e |
|
@ -152,6 +152,8 @@ def configure_ltc2195():
|
|||
main_adc_test_mode(spi, False)
|
||||
verify_adc_registers(spi, {0x02: 0x11}) # Verify test mode is off
|
||||
|
||||
print_adc_channels()
|
||||
|
||||
enable_adc_afe()
|
||||
|
||||
finally:
|
||||
|
|
|
@ -127,13 +127,13 @@ def configure_ad9117():
|
|||
configure_dac(spi)
|
||||
dac_self_calibration(spi)
|
||||
|
||||
# Enable DAC outputs
|
||||
spi_write(spi, 0x01, spi_read(spi, 0x01) & ~((1 << 4) | (1 << 3)))
|
||||
|
||||
power_down(0, False)
|
||||
power_down(1, False)
|
||||
manual_override(True)
|
||||
|
||||
# Enable DAC outputs
|
||||
spi_write(spi, 0x01, spi_read(spi, 0x01) & ~((1 << 4) | (1 << 3)))
|
||||
|
||||
print("AD9117 configuration completed successfully")
|
||||
return True
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
import time
|
||||
from pyfastservo import adc, dac
|
||||
from pyfastservo.common import (
|
||||
ADC_CH0_HIGH_ADDR, ADC_CH0_LOW_ADDR,
|
||||
ADC_CH1_HIGH_ADDR, ADC_CH1_LOW_ADDR,
|
||||
CH0_HIGH_WORD_ADDR, CH0_LOW_WORD_ADDR,
|
||||
CH1_HIGH_WORD_ADDR, CH1_LOW_WORD_ADDR,
|
||||
read_from_memory, write_to_memory
|
||||
)
|
||||
|
||||
def read_adc(channel):
|
||||
if channel == 0:
|
||||
return adc.read_adc_channel(ADC_CH0_HIGH_ADDR, ADC_CH0_LOW_ADDR)
|
||||
elif channel == 1:
|
||||
return adc.read_adc_channel(ADC_CH1_HIGH_ADDR, ADC_CH1_LOW_ADDR)
|
||||
else:
|
||||
raise ValueError("Invalid ADC channel")
|
||||
|
||||
def write_dac(channel, value):
|
||||
dac.set_dac_output(value, channel)
|
||||
|
||||
def read_dac(channel):
|
||||
if channel == 0:
|
||||
high_word = read_from_memory(CH0_HIGH_WORD_ADDR, 1)[0]
|
||||
low_word = read_from_memory(CH0_LOW_WORD_ADDR, 1)[0]
|
||||
elif channel == 1:
|
||||
high_word = read_from_memory(CH1_HIGH_WORD_ADDR, 1)[0]
|
||||
low_word = read_from_memory(CH1_LOW_WORD_ADDR, 1)[0]
|
||||
else:
|
||||
raise ValueError("Invalid DAC channel")
|
||||
return (high_word << 8) | low_word
|
||||
|
||||
def perform_loopback_test(channel, test_value):
|
||||
print(f"\nTesting Channel {channel}")
|
||||
print(f"Setting DAC CH{channel} output to {test_value}...")
|
||||
write_dac(channel, test_value)
|
||||
time.sleep(0.1) # Allow time for the signal to stabilize
|
||||
|
||||
print(f"Reading ADC CH{channel} value...")
|
||||
adc_value = read_adc(channel)
|
||||
print(f"ADC CH{channel} readback: {adc_value}")
|
||||
|
||||
print(f"Reading DAC CH{channel} value...")
|
||||
dac_value = read_dac(channel)
|
||||
print(f"DAC CH{channel} readback: {dac_value}")
|
||||
|
||||
if abs(test_value - adc_value) <= 2 and abs(test_value - dac_value) <= 2:
|
||||
print(f"Loopback test for Channel {channel} PASSED!")
|
||||
else:
|
||||
print(f"Loopback test for Channel {channel} FAILED!")
|
||||
print(f"Expected: {test_value}, ADC: {adc_value}, DAC: {dac_value}")
|
||||
|
||||
def main():
|
||||
test_value = 0x0FFF # Mid-range value (4095 in decimal)
|
||||
|
||||
perform_loopback_test(0, test_value)
|
||||
perform_loopback_test(1, test_value)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
12
flake.lock
12
flake.lock
|
@ -18,11 +18,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1719838683,
|
||||
"narHash": "sha256-Zw9rQjHz1ilNIimEXFeVa1ERNRBF8DoXDhLAZq5B4pE=",
|
||||
"lastModified": 1723938990,
|
||||
"narHash": "sha256-9tUadhnZQbWIiYVXH8ncfGXGvkNq3Hag4RCBEMUk7MI=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "d032c1a6dfad4eedec7e35e91986becc699d7d69",
|
||||
"rev": "c42fcfbdfeae23e68fc520f9182dde9f38ad1890",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -64,11 +64,11 @@
|
|||
"src-migen": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1715484909,
|
||||
"narHash": "sha256-4DCHBUBfc/VA+7NW2Hr0+JP4NnKPru2uVJyZjCCk0Ws=",
|
||||
"lastModified": 1721561053,
|
||||
"narHash": "sha256-z3LRhNmKZrjr6rFD0yxtccSa/SWvFIYmb+G/D5d2Jd8=",
|
||||
"owner": "m-labs",
|
||||
"repo": "migen",
|
||||
"rev": "4790bb577681a8c3a8d226bc196a4e5deb39e4df",
|
||||
"rev": "9279e8623f8433bc4f23ac51e5e2331bfe544417",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -481,7 +481,7 @@
|
|||
inherit migen misoc vivado;
|
||||
};
|
||||
packages.armv7l-linux = {
|
||||
inherit fast-servo-gateware linien-server;
|
||||
inherit fast-servo-gateware linien-server pyfastservo;
|
||||
} //
|
||||
(board-package-set { board = "zc706"; }) //
|
||||
(board-package-set { board = "fast-servo"; });
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
diff --git a/base.nix b/base.nix
|
||||
index 7eaee32..3ade454 100644
|
||||
index 7eaee32..9aa338e 100644
|
||||
--- a/base.nix
|
||||
+++ b/base.nix
|
||||
@@ -27,6 +27,11 @@ with lib;
|
||||
|
@ -14,7 +14,7 @@ index 7eaee32..3ade454 100644
|
|||
not-os.simpleStaticIp = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
@@ -84,17 +89,27 @@ with lib;
|
||||
@@ -84,17 +89,25 @@ with lib;
|
||||
};
|
||||
environment.etc = {
|
||||
"nix/nix.conf".source = pkgs.runCommand "nix.conf" {} ''
|
||||
|
@ -31,8 +31,6 @@ index 7eaee32..3ade454 100644
|
|||
+ extra-sandbox-paths = /bin/sh=${pkgs.runtimeShell} $(echo $extraPaths)
|
||||
+ max-jobs = auto
|
||||
+ sandbox = true
|
||||
+ substituters = https://cache.armv7l.xyz
|
||||
+ trusted-public-keys = cache.armv7l.xyz-1:kBY/eGnBAYiqYfg0fy0inWhshUo+pGFM3Pj7kIkmlBk=
|
||||
+ trusted-users = root
|
||||
EOF
|
||||
'';
|
||||
|
|
Loading…
Reference in New Issue