Skip to content

Commit 352cada

Browse files
committed
HRTIM - Fix error in
1 parent 07eb18d commit 352cada

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/hrtim/capture.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ pub trait HrCapture {
5050
/// <-------------- 0 --------------> t
5151
/// Negative result | positive result
5252
/// ````
53-
fn get_signed(&self) -> i32 {
53+
fn get_signed(&self, period: u16) -> i32 {
5454
let (value, dir) = self.get();
5555

5656
match dir {
5757
CountingDirection::Up => i32::from(value),
58-
CountingDirection::Down => -i32::from(value),
58+
CountingDirection::Down => i32::from(period) - i32::from(value),
5959
}
6060
}
6161

@@ -66,18 +66,18 @@ pub trait HrCapture {
6666

6767
pub fn dma_value_to_dir_and_value(x: u32) -> (u16, CountingDirection) {
6868
let value = (x & 0xFFFF) as u16;
69-
match x & 1 << 16 != 0 {
69+
match x & (1 << 16) != 0 {
7070
true => (value, CountingDirection::Down),
7171
false => (value, CountingDirection::Up),
7272
}
7373
}
7474

75-
pub fn dma_value_to_signed(x: u32) -> i32 {
75+
pub fn dma_value_to_signed(x: u32, period: u16) -> i32 {
7676
let (value, dir) = dma_value_to_dir_and_value(x);
7777

7878
match dir {
7979
CountingDirection::Up => i32::from(value),
80-
CountingDirection::Down => -i32::from(value),
80+
CountingDirection::Down => i32::from(period) - i32::from(value),
8181
}
8282
}
8383

src/hrtim/timer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ pub trait HrTimer {
3030
/// Get period of timer in number of ticks
3131
///
3232
/// This is also the maximum duty usable for `HrCompareRegister::set_duty`
33+
///
34+
/// NOTE: The effective period in number of ticks will be twice as large as
35+
/// returned by this function when running in UpDown mode or PushPull mode.
36+
/// 4 times as large when having both modes active
3337
fn get_period(&self) -> u16;
3438

3539
/// Set period of timer in number of ticks

0 commit comments

Comments
 (0)