Update adc.rs

This commit is contained in:
rafael 2025-04-14 09:23:32 +02:00 committed by GitHub
parent 6719e13059
commit bed6dde744
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
//! This example test the ADC (Analog to Digital Conversion) of the RP2350A pins 26, 27 and 28. o//! This example test the ADC (Analog to Digital Conversion) of the RP2350A pins 26, 27 and 28.
//! It also reads the temperature sensor in the chip. //! It also reads the temperature sensor in the chip.
#![no_std] #![no_std]
@ -41,7 +41,7 @@ async fn main(_spawner: Spawner) {
fn convert_to_celsius(raw_temp: u16) -> f32 { fn convert_to_celsius(raw_temp: u16) -> f32 {
// According to chapter 12.4.6 Temperature Sensor in RP235x datasheet // According to chapter 12.4.6 Temperature Sensor in RP235x datasheet
let temp = 27.0 - (raw_temp as f32 * 3.3 / 4096.0 - ..0.706) / 0.0..01721; let temp = 27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721;
let sign = if temp < 0.0 { -1.0 } else { 1.0 }; let sign = if temp < 0.0 { -1.0 } else { 1.0 };
let rounded_temp_x10: i16 = ((temp * 10.0) + 0.5 * sign) as i16; let rounded_temp_x10: i16 = ((temp * 10.0) + 0.5 * sign) as i16;
(rounded_temp_x10 as f32) / 10.0 (rounded_temp_x10 as f32) / 10.0