Improve examples
This commit is contained in:
parent
545cc9326b
commit
7a6732adcf
@ -16,14 +16,14 @@ async fn main(_spawner: Spawner) {
|
|||||||
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
||||||
let mut pin = p.PB1;
|
let mut pin = p.PB1;
|
||||||
|
|
||||||
let mut vref = adc.enable_vref(&mut Delay);
|
let mut vrefint = adc.enable_vref(&mut Delay);
|
||||||
let vref_sample = adc.read(&mut vref);
|
let vrefint_sample = adc.read(&mut vrefint);
|
||||||
let convert_to_millivolts = |sample| {
|
let convert_to_millivolts = |sample| {
|
||||||
// From http://www.st.com/resource/en/datasheet/CD00161566.pdf
|
// From http://www.st.com/resource/en/datasheet/CD00161566.pdf
|
||||||
// 5.3.4 Embedded reference voltage
|
// 5.3.4 Embedded reference voltage
|
||||||
const VREF_MV: u32 = 1200;
|
const VREFINT_MV: u32 = 1200; // mV
|
||||||
|
|
||||||
(u32::from(sample) * VREF_MV / u32::from(vref_sample)) as u16
|
(u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
|
||||||
};
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -24,14 +24,14 @@ async fn main(_spawner: Spawner) {
|
|||||||
// Startup delay can be combined to the maximum of either
|
// Startup delay can be combined to the maximum of either
|
||||||
delay.delay_us(Temperature::start_time_us().max(VrefInt::start_time_us()));
|
delay.delay_us(Temperature::start_time_us().max(VrefInt::start_time_us()));
|
||||||
|
|
||||||
let vref_sample = adc.read_internal(&mut vrefint);
|
let vrefint_sample = adc.read_internal(&mut vrefint);
|
||||||
|
|
||||||
let convert_to_millivolts = |sample| {
|
let convert_to_millivolts = |sample| {
|
||||||
// From http://www.st.com/resource/en/datasheet/DM00071990.pdf
|
// From http://www.st.com/resource/en/datasheet/DM00071990.pdf
|
||||||
// 6.3.24 Reference voltage
|
// 6.3.24 Reference voltage
|
||||||
const VREF_MILLIVOLTS: u32 = 1210; // mV
|
const VREFINT_MV: u32 = 1210; // mV
|
||||||
|
|
||||||
(u32::from(sample) * VREF_MILLIVOLTS / u32::from(vref_sample)) as u16
|
(u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
|
||||||
};
|
};
|
||||||
|
|
||||||
let convert_to_celcius = |sample| {
|
let convert_to_celcius = |sample| {
|
||||||
@ -45,6 +45,10 @@ async fn main(_spawner: Spawner) {
|
|||||||
(sample_mv - V25) as f32 / AVG_SLOPE + 25.0
|
(sample_mv - V25) as f32 / AVG_SLOPE + 25.0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
info!("VrefInt: {}", vrefint_sample);
|
||||||
|
const MAX_ADC_SAMPLE: u16 = (1 << 12) - 1;
|
||||||
|
info!("VCCA: {} mV", convert_to_millivolts(MAX_ADC_SAMPLE));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Read pin
|
// Read pin
|
||||||
let v = adc.read(&mut pin);
|
let v = adc.read(&mut pin);
|
||||||
@ -57,7 +61,7 @@ async fn main(_spawner: Spawner) {
|
|||||||
|
|
||||||
// Read internal voltage reference
|
// Read internal voltage reference
|
||||||
let v = adc.read_internal(&mut vrefint);
|
let v = adc.read_internal(&mut vrefint);
|
||||||
info!("VrefInt: {} ({} mV)", v, convert_to_millivolts(v));
|
info!("VrefInt: {}", v);
|
||||||
|
|
||||||
Timer::after(Duration::from_millis(100)).await;
|
Timer::after(Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,14 @@ async fn main(_spawner: Spawner) {
|
|||||||
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
||||||
let mut pin = p.PA3;
|
let mut pin = p.PA3;
|
||||||
|
|
||||||
let mut vref = adc.enable_vrefint();
|
let mut vrefint = adc.enable_vrefint();
|
||||||
let vref_sample = adc.read_internal(&mut vref);
|
let vrefint_sample = adc.read_internal(&mut vrefint);
|
||||||
let convert_to_millivolts = |sample| {
|
let convert_to_millivolts = |sample| {
|
||||||
// From http://www.st.com/resource/en/datasheet/DM00273119.pdf
|
// From http://www.st.com/resource/en/datasheet/DM00273119.pdf
|
||||||
// 6.3.27 Reference voltage
|
// 6.3.27 Reference voltage
|
||||||
const VREF_MV: u32 = 1210;
|
const VREFINT_MV: u32 = 1210; // mV
|
||||||
|
|
||||||
(u32::from(sample) * VREF_MV / u32::from(vref_sample)) as u16
|
(u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
|
||||||
};
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
Loading…
Reference in New Issue
Block a user