Skip to content

Commit 81efcf3

Browse files
meithecatteRahix
authored andcommitted
atmega-hal: configure TC1 like all the other timers on atmega1280/2560
Due to a missing write to the WGM bits in the TCCR1B register, PWM running off of TC1 was generating a frequency roughly two times slower. This commit fixes this issue.
1 parent 4387daf commit 81efcf3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

mcu/atmega-hal/src/simple_pwm.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,16 @@ avr_hal_generic::impl_simple_pwm! {
318318
timer: crate::pac::TC1,
319319
init: |tim, prescaler| {
320320
tim.tccr1a.modify(|_r, w| w.wgm1().bits(0b01));
321-
tim.tccr1b.modify(|_r, w| match prescaler {
322-
Prescaler::Direct => w.cs1().direct(),
323-
Prescaler::Prescale8 => w.cs1().prescale_8(),
324-
Prescaler::Prescale64 => w.cs1().prescale_64(),
325-
Prescaler::Prescale256 => w.cs1().prescale_256(),
326-
Prescaler::Prescale1024 => w.cs1().prescale_1024(),
321+
tim.tccr1b.modify(|_r, w| {
322+
w.wgm1().bits(0b01);
323+
324+
match prescaler {
325+
Prescaler::Direct => w.cs1().direct(),
326+
Prescaler::Prescale8 => w.cs1().prescale_8(),
327+
Prescaler::Prescale64 => w.cs1().prescale_64(),
328+
Prescaler::Prescale256 => w.cs1().prescale_256(),
329+
Prescaler::Prescale1024 => w.cs1().prescale_1024(),
330+
}
327331
});
328332
},
329333
pins: {

0 commit comments

Comments
 (0)