Jeremy - ty for this code, it’s very useful. I need to do this on a Pi Pico 2 W. https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf
Please could you comment about how I can read all three ADC’s (26, 27, 28) “simultaneously"?
I think I have mostly figured this out - please could you comment?
Edit to rp_devices.py for the slight change to the DMA see 12.6.1 of the rp2350 Datasheet
The four most-significant bits of TRANS_COUNT (CH0_TRANS_COUNT) are redefined as the MODE field, which defines
what happens when TRANS_COUNT reaches zero:
DMA_TRANS_COUNT_FIELDS = {
"MODE": 28<<BF_POS | 4<<BF_LEN | BFUINT32,
"COUNT": 0<<BF_POS | 28<<BF_LEN | BFUINT32
}
# Channel-specific DMA registers
DMA_CHAN_REGS = {
"READ_ADDR_REG": 0x00|UINT32,
"WRITE_ADDR_REG": 0x04|UINT32,
"TRANS_COUNT_REG": 0x08|UINT32,
"TRANS_COUNT": (0x08,DMA_TRANS_COUNT_FIELDS),
"CTRL_TRIG_REG": 0x0c|UINT32,
"CTRL_TRIG": (0x0c,DMA_CTRL_TRIG_FIELDS)
}
Some simple changes to adc_test.py.
Firstly - they can only be read round robin and not simultaneously. So to do that ...
All three GPIO pins need to be enabled as ADC pins and pads.
Does adc.CS.READY need to be checked after: adc.CS.EN = 1 ? I have not seen the value go high ...
ADC_CHAN_0 = 0 # Only refer to channel zero below ...
# Enable the ADC pins and pads
ADC_PIN_26 = 26
ADC_PIN_27 = 27
ADC_PIN_28 = 28
pin_26 = devs.GPIO_PINS[ADC_PIN_26]
pin_27 = devs.GPIO_PINS[ADC_PIN_27]
pin_28 = devs.GPIO_PINS[ADC_PIN_28]
pad_26 = devs.PAD_PINS[ADC_PIN_26]
pad_27 = devs.PAD_PINS[ADC_PIN_27]
pad_28 = devs.PAD_PINS[ADC_PIN_28]
pin_26.GPIO_CTRL_REG = devs.GPIO_FUNC_NULL
pin_27.GPIO_CTRL_REG = devs.GPIO_FUNC_NULL
pin_28.GPIO_CTRL_REG = devs.GPIO_FUNC_NULL
pad_26.PAD_REG = 0
pad_27.PAD_REG = 0
pad_28.PAD_REG = 0
Then round robin needs to be enabled ...
# Sample all the ADC channels round robin
adc.CS.RROBIN = 0x07 # Mask, set bits 0, 1, 2 for channels 0, 1, 2
# Start reading channel 0
adc.CS.AINSEL = ADC_CHAN_0 # Start at channel 0
Set number of samples to some multiple of 3
NSAMPLES = 12
Do I need to read the value of adc.CS.AINSEL to ensure the corresponding channel value is being returned- I suppose the better way to do this is to not START_MANY
Do I need to do anything to set the security levels? These differ from the Pico 1 to the Pico 2.
Why is dma_chan.CTRL_TRIG.DATA_SIZE set to 1? The ADC is 12 bits - should this be 2? From: 12.6.2.1 “
READ_ADDR and WRITE_ADDR contain the address the channel will next read from, and write to, respectively. These registers update automatically after each read/write access, incrementing to the next read/write address as required. The size of the increment varies according to:
the transfer size: 1, 2 or 4 byte bus accesses as per CH0_CTRL_TRIG.DATA_SIZE
And from section 12.4.3.5
if the DMA transfer size is set to 8 bits (so that the DMA transfers to a byte array in memory), set FCS.SHIFT to pre-shift the FIFO samples to 8 bits of significance.
FCS.SHIFT is not set in the code and adc_buff is allocated as a 2 byte array e.g. array.array('H', (0 for _ in range(NSAMPLES)))
Jeremy - ty for this code, it’s very useful. I need to do this on a Pi Pico 2 W. https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf
Please could you comment about how I can read all three ADC’s (26, 27, 28) “simultaneously"?
I think I have mostly figured this out - please could you comment?
Edit to rp_devices.py for the slight change to the DMA see 12.6.1 of the rp2350 Datasheet
The four most-significant bits of TRANS_COUNT (CH0_TRANS_COUNT) are redefined as the MODE field, which defines
what happens when TRANS_COUNT reaches zero:
Some simple changes to adc_test.py.
Firstly - they can only be read round robin and not simultaneously. So to do that ...
All three GPIO pins need to be enabled as ADC pins and pads.
Does adc.CS.READY need to be checked after: adc.CS.EN = 1 ? I have not seen the value go high ...
Then round robin needs to be enabled ...
Set number of samples to some multiple of 3
NSAMPLES = 12Do I need to read the value of adc.CS.AINSEL to ensure the corresponding channel value is being returned- I suppose the better way to do this is to not START_MANY
Do I need to do anything to set the security levels? These differ from the Pico 1 to the Pico 2.
Why is dma_chan.CTRL_TRIG.DATA_SIZE set to 1? The ADC is 12 bits - should this be 2? From: 12.6.2.1 “
And from section 12.4.3.5
FCS.SHIFT is not set in the code and adc_buff is allocated as a 2 byte array e.g. array.array('H', (0 for _ in range(NSAMPLES)))