Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpi pico: reading VSYS with ADC gives incorrect values #2970

Open
soyflourbread opened this issue May 20, 2024 · 0 comments
Open

rpi pico: reading VSYS with ADC gives incorrect values #2970

soyflourbread opened this issue May 20, 2024 · 0 comments

Comments

@soyflourbread
Copy link

Hi,
I'm trying to read VSYS voltage using Raspberry Pi Pico's ADC using steps described here:
https://forums.raspberrypi.com/viewtopic.php?t=301152

However, reading it from PIN_29 using ADC gives incorrect values.
It should be around 4 volts, yet the ADC measured ~0.15 volts.

Is this a bug in embassy's ADC implementation?
The sample code I used is below:

#![no_std]
#![no_main]

use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::{gpio, pwm, uart, adc};
use embassy_time::Duration;

use {defmt_rtt as _, panic_probe as _};

embassy_rp::bind_interrupts!(struct Irqs {
    ADC_IRQ_FIFO => adc::InterruptHandler;
});

fn to_voltage(raw_voltage: u16) -> f32 {
    let mut ret = raw_voltage as f32;
    ret *= 3.23;
    ret *= 3.0;
    ret /= 65535.0;
    ret
}

#[embassy_executor::main]
async fn main(spawner: Spawner) {
    let p = embassy_rp::init(Default::default());

    let mut adc_0 = adc::Adc::new(p.ADC, Irqs, adc::Config::default());

    let mut p_voltage = adc::Channel::new_pin(p.PIN_29, gpio::Pull::None);
    let voltage = adc_0.read(&mut p_voltage).await.unwrap();
    let voltage = to_voltage(voltage);
    info!("input voltage: {}", voltage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant