Skip to content

Commit

Permalink
create dac module
Browse files Browse the repository at this point in the history
  • Loading branch information
zakary-bt authored and jbeaurivage committed Jul 27, 2023
1 parent 2f9df44 commit dae176a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hal/src/thumbv6m/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl Dac {
/// internally.
pub fn set_voltage(&mut self, v_out: f32) {
let value = self.voltage_as_u16(v_out);
defmt::trace!("DATA: {}", value);
self.dac.data.modify(|_, w| unsafe { w.data().bits(value) });
self.syncbusy();
}
Expand Down Expand Up @@ -101,6 +102,6 @@ impl Dac {
/// [`voltage_as_u16`](Self::voltage_as_u16)
fn voltage_as_u16(&self, v_out: f32) -> u16 {
// 0x3FF is the maximum for a 10 bit number
(v_out / self.v_ref) as u16 * 0x3FF
((v_out / self.v_ref) * 1024.0) as u16
}
}

0 comments on commit dae176a

Please sign in to comment.