diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-01-25 06:46:37 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-01-25 06:46:37 +0000 |
| commit | a950266a7501c5534ebd7c477d42d29ac25cf472 (patch) | |
| tree | d548c46ba46a285bc3bc8555ed3f0875648922ef | |
| parent | 0549a9dbaac8726e5d37d87f8f14b8524915c8c9 (diff) | |
| parent | c9f29534d6f3fd5bcf2cee09e70667373a8dc179 (diff) | |
Merge #590
590: Stop PWM before assigning the new sequence r=huntc a=huntc
I had introduced a small bug in my last PR where I assigned the sequence before stopping the PWM. I now stop the PWM before doing that now.
Also, corrected a math comment.
Co-authored-by: huntc <[email protected]>
| -rw-r--r-- | embassy-nrf/src/pwm.rs | 4 | ||||
| -rw-r--r-- | examples/nrf/src/bin/pwm_sequence.rs | 2 | ||||
| -rw-r--r-- | examples/nrf/src/bin/pwm_sequence_ppi.rs | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 61a282833..a77cd6332 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs | |||
| @@ -149,6 +149,8 @@ impl<'d, T: Instance> SequencePwm<'d, T> { | |||
| 149 | return Err(Error::SequenceTimesAtLeastOne); | 149 | return Err(Error::SequenceTimesAtLeastOne); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | self.stop(); | ||
| 153 | |||
| 152 | let r = T::regs(); | 154 | let r = T::regs(); |
| 153 | 155 | ||
| 154 | r.seq0 | 156 | r.seq0 |
| @@ -165,8 +167,6 @@ impl<'d, T: Instance> SequencePwm<'d, T> { | |||
| 165 | .cnt | 167 | .cnt |
| 166 | .write(|w| unsafe { w.bits(sequence.len() as u32) }); | 168 | .write(|w| unsafe { w.bits(sequence.len() as u32) }); |
| 167 | 169 | ||
| 168 | self.stop(); | ||
| 169 | |||
| 170 | r.enable.write(|w| w.enable().enabled()); | 170 | r.enable.write(|w| w.enable().enabled()); |
| 171 | 171 | ||
| 172 | // defensive before seqstart | 172 | // defensive before seqstart |
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs index 561bc1dd1..56c865d1c 100644 --- a/examples/nrf/src/bin/pwm_sequence.rs +++ b/examples/nrf/src/bin/pwm_sequence.rs | |||
| @@ -18,7 +18,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 18 | 18 | ||
| 19 | let mut config = SequenceConfig::default(); | 19 | let mut config = SequenceConfig::default(); |
| 20 | config.prescaler = Prescaler::Div128; | 20 | config.prescaler = Prescaler::Div128; |
| 21 | // 1 period is 1000 * (128/16mhz = 0.000008s = 0.008ms) = 8ms | 21 | // 1 period is 1000 * (128/16mhz = 0.000008s = 0.008ms) = 8us |
| 22 | // but say we want to hold the value for 5000ms | 22 | // but say we want to hold the value for 5000ms |
| 23 | // so we want to repeat our value as many times as necessary until 5000ms passes | 23 | // so we want to repeat our value as many times as necessary until 5000ms passes |
| 24 | // want 5000/8 = 625 periods total to occur, so 624 (we get the one period for free remember) | 24 | // want 5000/8 = 625 periods total to occur, so 624 (we get the one period for free remember) |
diff --git a/examples/nrf/src/bin/pwm_sequence_ppi.rs b/examples/nrf/src/bin/pwm_sequence_ppi.rs index 213ef5ed7..f03c5716a 100644 --- a/examples/nrf/src/bin/pwm_sequence_ppi.rs +++ b/examples/nrf/src/bin/pwm_sequence_ppi.rs | |||
| @@ -20,7 +20,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 20 | 20 | ||
| 21 | let mut config = SequenceConfig::default(); | 21 | let mut config = SequenceConfig::default(); |
| 22 | config.prescaler = Prescaler::Div128; | 22 | config.prescaler = Prescaler::Div128; |
| 23 | // 1 period is 1000 * (128/16mhz = 0.000008s = 0.008ms) = 8ms | 23 | // 1 period is 1000 * (128/16mhz = 0.000008s = 0.008ms) = 8us |
| 24 | // but say we want to hold the value for 250ms 250ms/8 = 31.25 periods | 24 | // but say we want to hold the value for 250ms 250ms/8 = 31.25 periods |
| 25 | // so round to 31 - 1 (we get the one period for free remember) | 25 | // so round to 31 - 1 (we get the one period for free remember) |
| 26 | // thus our sequence takes 5 * 250ms or 1.25 seconds | 26 | // thus our sequence takes 5 * 250ms or 1.25 seconds |
