aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2021-02-17 21:46:29 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2021-02-17 21:46:29 +0100
commitef4c18417684920726edaa6d0d01c85acc3a0abd (patch)
treedd126a703824ba3e72b5a6685cd5170d68064685
parent6ce6671147d8d208348c13d54faee9caebcd2623 (diff)
downloadpicardy-ef4c18417684920726edaa6d0d01c85acc3a0abd.tar.gz
picardy-ef4c18417684920726edaa6d0d01c85acc3a0abd.tar.bz2
picardy-ef4c18417684920726edaa6d0d01c85acc3a0abd.zip
Calibrate S meter
-rw-r--r--sw/picardy/src/main.rs37
-rw-r--r--sw/picardy/src/ui.rs4
2 files changed, 31 insertions, 10 deletions
diff --git a/sw/picardy/src/main.rs b/sw/picardy/src/main.rs
index a6a3e4a..22b894b 100644
--- a/sw/picardy/src/main.rs
+++ b/sw/picardy/src/main.rs
@@ -292,14 +292,8 @@ fn main() -> ! {
}
previous_vfo = vfo;
- let s_meter_value: u16 = adc2.read(&mut s_meter).unwrap();
-
- // Avoid 0 because of log10
- let s_meter_value = f32::from(if s_meter_value == 0 { 1 } else { s_meter_value });
-
- // ADC is 12-bit, convert to dB full-scale
- let s_meter_value = 10f32 * log10f::log10f(f32::from(s_meter_value) / 4092f32);
- let s_meter_value = s_meter_value as i32;
+ let s_meter_adc_value: u16 = adc2.read(&mut s_meter).unwrap();
+ let s_meter_value = s_meter_from_adc(s_meter_adc_value);
let t_now = ticks_now();
if last_s_meter_update_time + 10 < t_now {
update_disp_required = s_meter_value != last_s_meter_value;
@@ -322,6 +316,33 @@ fn main() -> ! {
}
}
+fn s_meter_from_adc(adc : u16) -> u8 {
+ // Avoid 0 because of log10
+ let adc = f32::from(if adc == 0 { 1 } else { adc });
+ // ADC is 12-bit, convert to dB full-scale
+ let adc_db = 10f32 * log10f::log10f(adc / 4092f32);
+
+ /* Hand-calibrated lookup table */
+ if adc_db <= -35f32 {
+ 1
+ }
+ else if adc_db <= -20f32 {
+ 4
+ }
+ else if adc_db <= -12f32 {
+ 5
+ }
+ else if adc_db <= -8f32 {
+ 6
+ }
+ else if adc_db <= -7f32 {
+ 7
+ }
+ else {
+ 9
+ }
+}
+
#[interrupt]
fn TIM2() {
let timer = unsafe { &mut *CLOCK_TIMER.as_mut_ptr() };
diff --git a/sw/picardy/src/ui.rs b/sw/picardy/src/ui.rs
index 9d5a4e4..0170813 100644
--- a/sw/picardy/src/ui.rs
+++ b/sw/picardy/src/ui.rs
@@ -278,7 +278,7 @@ impl UI {
}
}
-pub fn update_disp<T: hd44780_driver::bus::DataBus>(lcd: &mut HD44780<T>, state: &State, delay: &mut Delay, s_meter_value: i32, bfo_tune_fail: bool)
+pub fn update_disp<T: hd44780_driver::bus::DataBus>(lcd: &mut HD44780<T>, state: &State, delay: &mut Delay, s_meter_value: u8, bfo_tune_fail: bool)
{
let mut string = arrayvec::ArrayString::<[_; 16]>::new();
@@ -298,7 +298,7 @@ pub fn update_disp<T: hd44780_driver::bus::DataBus>(lcd: &mut HD44780<T>, state:
if string.len() <= 16 - 4 {
// Avoids crash when frequency is very negative
- write!(string, "S{:3}", s_meter_value).unwrap();
+ write!(string, " S{:1}", s_meter_value).unwrap();
}
lcd.set_cursor_pos(0, delay).unwrap();