ATtiny85 Template Code
Code snippets for the ATtiny85
Main Page
Files
File List
Globals
All
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
pwm.c
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*
2
* PWM output helpers
3
*---------------------------------------------------------------------------*
4
* 14-May-2014 ShaneG
5
*
6
* These functions provide simulated analog output using PWM channels on
7
* TIMER0
8
*--------------------------------------------------------------------------*/
9
#include <avr/io.h>
10
#include "
iohelp.h
"
11
17
void
pwmInit
() {
18
TCCR0A = (3<<WGM00);
// Enable fast PWM mode
19
TCCR0B = (1<<CS00);
// No prescaler
20
}
21
30
void
pwmOut
(
PWM
pwm, uint8_t value) {
31
// Make sure the pin is an output
32
DDRB |= (1 << pwm);
33
if
(pwm==
PWM0
) {
34
TCCR0A |= (2<<COM0A0);
35
OCR0A = value;
36
}
37
else
if
(pwm==
PWM1
) {
38
TCCR0A |= (2<<COM0B0);
39
OCR0B = value;
40
}
41
}
42
PWM1
PWM output 1 (PB1)
Definition:
iohelp.h:106
PWM
enum _PWM PWM
iohelp.h
pwmOut
void pwmOut(PWM pwm, uint8_t value)
Definition:
pwm.c:30
pwmInit
void pwmInit()
Definition:
pwm.c:17
PWM0
PWM output 0 (PB0)
Definition:
iohelp.h:105
shared
pwm.c
Generated on Wed Jun 4 2014 17:16:48 for ATtiny85 Template Code by
1.8.6