Skip to content

Commit

Permalink
reduce overhead of digitalWrite() and analogWrite()
Browse files Browse the repository at this point in the history
Effective on most parts. t861 still needs similar treatment, there are
like 20-30 bytes to save there too. (#334)
  • Loading branch information
SpenceKonde committed Jul 24, 2019
1 parent a11135f commit bedf9d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions avr/cores/tiny/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void analogWrite(uint8_t pin, int val)
if( timer == TIMER0A){
// connect pwm to pin on timer 0, channel A
sbi(TCCR0A, COM0A1);
cbi(TCCR0A, COM0A0);
//cbi(TCCR0A, COM0A0);
OCR0A = val; // set pwm duty
} else
#endif
Expand All @@ -124,7 +124,7 @@ void analogWrite(uint8_t pin, int val)
if( timer == TIMER0B){
// connect pwm to pin on timer 0, channel B
sbi(TCCR0A, COM0B1);
cbi(TCCR0A, COM0B0);
//cbi(TCCR0A, COM0B0);
OCR0B = val; // set pwm duty
} else
#endif
Expand All @@ -135,7 +135,7 @@ void analogWrite(uint8_t pin, int val)
if( timer == TIMER1A){
// connect pwm to pin on timer 1, channel A
sbi(TCCR1A, COM1A1);
cbi(TCCR1A, COM1A0);
//cbi(TCCR1A, COM1A0);
#ifdef OC1AX
cbi(TCCR1D, OC1AV);
cbi(TCCR1D, OC1AU);
Expand Down Expand Up @@ -172,7 +172,7 @@ void analogWrite(uint8_t pin, int val)
if(timer == TIMER1A){
// connect pwm to pin on timer 1, channel A
sbi(TCCR1, COM1A1);
cbi(TCCR1, COM1A0);
//cbi(TCCR1, COM1A0);
OCR1A = val; // set pwm duty
} else
#endif
Expand All @@ -181,7 +181,7 @@ void analogWrite(uint8_t pin, int val)
if( timer == TIMER1B){
// connect pwm to pin on timer 1, channel B
sbi(TCCR1A, COM1B1);
cbi(TCCR1A, COM1B0);
//cbi(TCCR1A, COM1B0);
#ifdef OC1BV
sbi(TCCR1D, OC1BV);
cbi(TCCR1D, OC1BU);
Expand All @@ -196,7 +196,7 @@ void analogWrite(uint8_t pin, int val)
if( timer == TIMER1B){
// connect pwm to pin on timer 1, channel B
sbi(GTCCR, COM1B1);
cbi(GTCCR, COM1B0);
//cbi(GTCCR, COM1B0);
OCR1B = val; // set pwm duty
} else
#endif
Expand Down
12 changes: 6 additions & 6 deletions avr/cores/tiny/wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ static void turnOffPWM(uint8_t timer)
#if defined(TCCR0A) && defined(COM0A1)
if( timer == TIMER0A){
cbi(TCCR0A, COM0A1);
cbi(TCCR0A, COM0A0);
//cbi(TCCR0A, COM0A0);
} else
#endif

#if defined(TCCR0A) && defined(COM0B1)
if( timer == TIMER0B){
cbi(TCCR0A, COM0B1);
cbi(TCCR0A, COM0B0);
//cbi(TCCR0A, COM0B0);
} else
#endif

#if defined(TCCR1A) && defined(COM1A1)
if( timer == TIMER1A){
cbi(TCCR1A, COM1A1);
cbi(TCCR1A, COM1A0);
//cbi(TCCR1A, COM1A0);
} else
#endif
#if defined(TCCR1E) //attiny861
Expand All @@ -104,7 +104,7 @@ static void turnOffPWM(uint8_t timer)
#if defined(TCCR1) && defined(COM1A1)
if(timer == TIMER1A){
cbi(TCCR1, COM1A1);
cbi(TCCR1, COM1A0);
//cbi(TCCR1, COM1A0);
#ifdef OC1AX
cbi(TCCR1D, OC1AX);
#endif
Expand All @@ -114,7 +114,7 @@ static void turnOffPWM(uint8_t timer)
#if defined(TCCR1A) && defined(COM1B1)
if( timer == TIMER1B){
cbi(TCCR1A, COM1B1);
cbi(TCCR1A, COM1B0);
//cbi(TCCR1A, COM1B0);
#ifdef OC1BV
cbi(TCCR1D, OC1BV);
#endif
Expand All @@ -124,7 +124,7 @@ static void turnOffPWM(uint8_t timer)
#if defined(TCCR1) && defined(COM1B1)
if( timer == TIMER1B){
cbi(GTCCR, COM1B1);
cbi(GTCCR, COM1B0);
//cbi(GTCCR, COM1B1);
} else
#endif

Expand Down

0 comments on commit bedf9d0

Please sign in to comment.