Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Jan Kasprzak
tinyboard
Commits
522bd7b3
Commit
522bd7b3
authored
May 09, 2013
by
Jan Kasprzak
Browse files
pwm.c: switch off PLL when not needed
parent
ab58f34d
Changes
1
Hide whitespace changes
Inline
Side-by-side
projects/step-up/pwm.c
View file @
522bd7b3
...
...
@@ -11,10 +11,12 @@
* Counts from 0 to 0xFF, without OCR1C compare.
*/
static
unsigned
char
pwm_enabled
;
static
void
inline
enable_pll
()
{
/* Async clock */
PLLCSR
=
_BV
(
PLLE
);
PLLCSR
=
_BV
(
PLLE
)
|
_BV
(
LSM
)
;
/* Synchronize to the phase lock */
_delay_us
(
100
);
...
...
@@ -25,17 +27,16 @@ static void inline enable_pll()
void
init_pwm
()
{
pwm_enabled
=
0
;
power_timer1_enable
();
enable_pll
();
TCCR1
=
_BV
(
CTC1
)
|
_BV
(
CS10
);
// no clock prescaling
TCCR1
=
_BV
(
CTC1
)
|
_BV
(
CS11
);
// pll_clk/2
GTCCR
=
_BV
(
COM1B1
)
|
_BV
(
PWM1B
);
OCR1C
=
PWM_MAX
;
OCR1B
=
0
;
// initial stride is 0
DDRB
&=
~
_BV
(
PB4
);
// tristate it
DDRB
&=
~
(
_BV
(
PB4
)
);
PORTB
&=
~
_BV
(
PB4
);
// set to zero
}
...
...
@@ -54,10 +55,18 @@ void pwm_off()
{
OCR1B
=
0
;
DDRB
&=
~
_BV
(
PB4
);
PLLCSR
&=
~
(
_BV
(
PLLE
)
|
_BV
(
PCKE
));
pwm_enabled
=
0
;
}
void
pwm_set
(
uint8_t
stride
)
{
OCR1B
=
stride
;
DDRB
|=
_BV
(
PB4
);
if
(
!
pwm_enabled
)
{
enable_pll
();
DDRB
|=
_BV
(
PB4
);
pwm_enabled
=
1
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment