-
Notifications
You must be signed in to change notification settings - Fork 1
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
SNS - Low Pressure Sensor #73
base: main
Are you sure you want to change the base?
Changes from 38 commits
3ac18ee
ce6e4a6
a426a6e
0d8e6d7
0258a9c
c7e1271
f38d741
f870df3
9c52983
d3c2d0b
66e2874
a5744da
2d05367
85a6522
4c8d255
af46e82
33fb3f6
321d44e
5d56d5a
875d404
5565fc6
3606a39
53a3e61
0b3c38e
bd03f7d
e0b29dd
63b51a5
5d950e0
35989f9
0bffec6
83d2e41
fd51fb2
441fab1
716d2bf
85cd1a6
0aa3a84
9825072
229c532
100ab47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::panic::PanicInfo; | ||
use defmt::*; | ||
use embassy_executor::Spawner; | ||
use embassy_stm32::adc::{Adc, AdcChannel}; | ||
use embassy_time::{Duration, Timer}; | ||
use hyped_boards_stm32f767zi::io::Stm32f767ziAdc; | ||
use hyped_sensors::low_pressure::LowPressure; | ||
use {defmt_rtt as _, panic_probe as _}; | ||
|
||
/// Test task that just continually reads pressure from low pressure sensor and prints value to console | ||
#[embassy_executor::main] | ||
async fn main(_spawner: Spawner) -> ! { | ||
let p = embassy_stm32::init(Default::default()); | ||
info!("Low pressure sensor"); | ||
|
||
let adc = Adc::new(p.ADC1); | ||
let pin = p.PA3; | ||
|
||
let mut low_pressure_sensor = LowPressure::new(Stm32f767ziAdc::new(adc, pin.degrade_adc())); | ||
|
||
loop { | ||
info!("{}", low_pressure_sensor.read_pressure()); | ||
Timer::after(Duration::from_millis(100)).await; | ||
} | ||
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're loop here will need to match on the |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#![no_std] | ||
|
||
pub mod keyence; | ||
pub mod low_pressure; | ||
pub mod temperature; | ||
pub mod time_of_flight; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use hyped_adc::HypedAdc; | ||
|
||
/// The low pressure sensor (LPS) (model: SPAN-P10R-G18F-PNLK-PNVBA-L1) is able to detect | ||
/// pressure in range from 0 to 10 bar. The sensor utilises the ADC protocol to get the | ||
/// pressure value. | ||
/// | ||
/// Links to datasheets | ||
/// (https://www.festo.com/gb/en/a/download-document/datasheet/8134897) | ||
/// (https://www.festo.com/media/catalog/203714_documentation.pdf) | ||
pub struct LowPressure<T: HypedAdc> { | ||
adc: T, | ||
} | ||
|
||
const MAX_PRESSURE: f32 = 10.0; | ||
const ADC_RESOLUTION: f32 = 4096.0; | ||
const GRADIENT_LOW: f32 = MAX_PRESSURE / ADC_RESOLUTION; | ||
|
||
impl<T: HypedAdc> LowPressure<T> { | ||
/// Create new low pressure sensor instance | ||
pub fn new(adc: T) -> LowPressure<T> { | ||
LowPressure { adc } | ||
} | ||
|
||
/// Convert ADC reading to bar unit and return value to caller | ||
/// The conversion rate is expressed as a linear function of: | ||
/// pressure = (conversion gradient) * (ADC reading) + (minimum pressure value) | ||
/// (y = mx + c0) | ||
/// where conversion gradient is | ||
/// (maximum pressure value - minimum pressure value) / (4096). | ||
/// 4096 is the maximum ADC reading value. | ||
/// Since LPS has a minimum pressure of 0 bar, c0 is 0 and was did not need to be included in | ||
/// the source code. | ||
pub fn read_pressure(&mut self) -> f32 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you'll also need to define a default |
||
let adc_val = self.adc.read_value() as f32; | ||
|
||
// convert to bar unit | ||
let bar_pressure_val: f32 = adc_val * GRADIENT_LOW; | ||
Comment on lines
+49
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirm with Samuel that this conversion is correct |
||
|
||
bar_pressure_val | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really necessary