diff options
author | Bernhard Tittelbach <xro@realraum.at> | 2013-11-28 00:34:35 +0000 |
---|---|---|
committer | Bernhard Tittelbach <xro@realraum.at> | 2013-11-28 00:34:35 +0000 |
commit | 8021003e20cc112b7ac68b875b26556fda31f380 (patch) | |
tree | dc422651e0c357c26c6fcc60adf0d1fb02b27d92 /pcr-controller/pwm.c | |
parent | gas leak alarm (diff) |
update
git-svn-id: https://svn.spreadspace.org/avr/trunk@248 aa12f405-d877-488e-9caf-2d797e2a1cc7
Diffstat (limited to 'pcr-controller/pwm.c')
-rw-r--r-- | pcr-controller/pwm.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/pcr-controller/pwm.c b/pcr-controller/pwm.c index 918d37b..a4e3863 100644 --- a/pcr-controller/pwm.c +++ b/pcr-controller/pwm.c @@ -11,19 +11,23 @@ void pwm_init(void) TCCR1A = 0; TCNT1 = 0; OCR1A = 0; - TCCR1A = (1<<COM1A1) | (1<<WGM10); - TCCR1B = (1<<WGM12); + TCCR1A = (1<<WGM10); //Fast PWM, 8-bit + TCCR1B = (1<<WGM12); //Fast PWM, 8-bit + //TCCR1A |= (1<<COM1A1) // Clear OCnA/OCnB/OCnC on compare match when up-counting. Set OCnA/OCnB/OCnC on compare match when downcounting. } inline void pwm_on(void) { - TCCR1B = (TCCR1A & 0xF8) | (1<<CS10); + TCCR1A |= (1<<COM1A1); // Clear OCnA/OCnB/OCnC on compare match when up-counting. Set OCnA/OCnB/OCnC on compare match when downcounting. + TCCR1B = (TCCR1B & 0xF8) | (1<<CS10); // enable timer clock, no prescaling } inline void pwm_off(void) { - TCCR1B = (TCCR1A & 0xF8); + TCCR1A &= ~((1<<COM1A1) | (1<<COM1A0)); //normal port operation + TCCR1B = (TCCR1B & 0xF8); //no clock source, timer stopped TCNT1 = 0; + PORTB &= ~ (1 << PB5); //set pin to LOW (otherwise it will remain in state since last pwm toggle) } void pwm_set(uint8_t val) |