← index #15814Issue #15687
Off-topic · high · value 0.638
QUERY · ISSUE

Raspberry Pi Pico ADC changes the sampling rate in Free-running Sampling mode

openby leezishengopened 2024-09-09updated 2024-09-11
bug

Port, board and/or hardware

Raspberry Pi Pico

MicroPython version

MicroPython v1.23.0 ,RPI_PICO-20240602-v1.23.0

Reproduction

def configure_adc_sample_rate(self, sample_rate):
    """
    Configure the ADC sampling rate. Due to unknown reasons, the DIV register cannot be configured here. The actual sampling period is fixed at 65
    :param sample_rate: Desired sample rate (Hz)
    :return: None
    """
    # Ensure that the sampling rate is within a reasonable range
    if sample_rate <= 0 or sample_rate > 48_000_000:
        raise ValueError("sample rate out of range")

    # Calculate divider value
    total_period = 48_000_000 / sample_rate
    int_part = int(total_period) - 1
    frac_part = int((total_period - int_part - 1) * 256)
    div_value = mem32[DMA_ADC_Transfer.DIV_REG]

    
    # Write the sampling period to the DIV register
    mem32[DMA_ADC_Transfer.DIV_REG] = div_value | (int_part << 8) | frac_part

Expected behaviour

I am configuring the ADC sampling rate here. Due to unknown reasons, the DIV register cannot be configured here. The actual sampling period is fixed at 65.
Can anyone help me what is going wrong here?

Observed behaviour

(base) PS D:\lee\windows terminal\terminal-1.17.11461.0> mpremote connect COM8
Connected to MicroPython at COM8
Use Ctrl-] or Ctrl-x to exit this shell

div_value = mem32[DMA_ADC_Transfer.DIV_REG]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'mem32' isn't defined
from machine import mem32
div_value = mem32[DMA_ADC_Transfer.DIV_REG]
div_value
12582656
total_period = 48_000_000 / 48000
total_period = 48_000_000 / 480000
total_period
100.0
int_part = int(total_period) - 1
frac_part = int((total_period - int_part - 1) * 256)
mem32[DMA_ADC_Transfer.DIV_REG] = div_value | (int_part << 8) | frac_part
mem32[DMA_ADC_Transfer.DIV_REG]
12582656
total_period = 48_000_000 / 480000
int_part = int(total_period) - 1
frac_part = int((total_period - int_part - 1) * 256)
mem32[DMA_ADC_Transfer.DIV_REG] = div_value | (int_part << 8) | frac_part
mem32[DMA_ADC_Transfer.DIV_REG]
12582656

Additional Information

<img width="554" alt="a91a38f1944c012e122d14c44dcbc40" src="https://github.com/user-attachments/assets/bf2fc3ad-9186-4a46-82b2-0262dbcb828a">

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

PICO2 internal temperature sensor not accessible at ADC(4)

closedby CGsamaopened 2024-08-21updated 2025-03-03
bug

Port, board and/or hardware

PICO2

MicroPython version

RPI_PICO2-20240809-v1.24.0-preview.201.g269a0e0e1

Reproduction

from machine import ADC
temp_sensor = ADC(4)

Expected behaviour

able to read ADC

Observed behaviour

ValueError: Pin doesn't have ADC capabilities

Additional Information

adc channel defined at https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf section 12.4.6.
tried both 4 and 8 no luck

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied