mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-26 03:38:25 +08:00
re-impl ADC using general access methods
This commit is contained in:
parent
9e1447d104
commit
f2694f25eb
@ -183,6 +183,20 @@ class ADC:
|
||||
|
||||
@kernel
|
||||
def read_id(self) -> TInt32:
|
||||
return self.read16(_AD4115_REG_ID)
|
||||
|
||||
@kernel
|
||||
def reset(self):
|
||||
# Hold DIN high for 64 cycles
|
||||
# However, asserting CS right after the 64 cycles seems to interrupt
|
||||
# the start-up sequence.
|
||||
self.bus.set_config_mu(ADC_SPI_CONFIG, 32, SPIT_ADC_WR, CS_ADC)
|
||||
self.bus.write(0xffffffff)
|
||||
self.bus.write(0xffffffff)
|
||||
self.bus.set_config_mu(
|
||||
ADC_SPI_CONFIG | spi.SPI_END, 32, SPIT_ADC_WR, CS_ADC)
|
||||
self.bus.write(0xffffffff)
|
||||
|
||||
@kernel
|
||||
def read8(self, addr: TInt32) -> TInt32:
|
||||
self.bus.set_config_mu(
|
||||
@ -225,6 +239,13 @@ class ADC:
|
||||
ADC_SPI_CONFIG | spi.SPI_END, 32, SPIT_ADC_WR, CS_ADC)
|
||||
self.bus.write(addr << 24 | (data & 0xffffff))
|
||||
|
||||
@kernel
|
||||
def read_ch(self, channel: TInt32) -> TFloat:
|
||||
# Always configure Profile 0 for single conversion
|
||||
self.write16(_AD4115_REG_CH0, 0x8000 | ((channel * 2 + 1) << 4))
|
||||
self.write16(_AD4115_REG_SETUPCON0, 0x1300)
|
||||
self.write16(_AD4115_REG_ADCMODE, 0x8010)
|
||||
|
||||
delay(100*us)
|
||||
adc_code = self.read24(_AD4115_REG_DATA)
|
||||
return ((adc_code / (1 << 23)) - 1) * 2.5 / 0.1
|
||||
|
Loading…
Reference in New Issue
Block a user