From f265d1725f27581069addbc75a1a323616dd147f Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 6 Aug 2014 17:39:52 -0400 Subject: [PATCH] PWM on pin 4 (TIMER1B). This fixes issue #36 (for Arduino 1.5.x at least). It uses initVariant() to put Timer1 into PWM mode and a hacky #define alias (TCCR1A for GTCCR) so that analogWrite() will set the right bit in the right register to connect the timer PWM output to the pin. Also, the pre-scale factor and PWM frequency are probably wrong (or, at least, not the same as on other AVRs). --- attiny/variants/tiny8/pins_arduino.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/attiny/variants/tiny8/pins_arduino.h b/attiny/variants/tiny8/pins_arduino.h index e64b887..09fd0aa 100755 --- a/attiny/variants/tiny8/pins_arduino.h +++ b/attiny/variants/tiny8/pins_arduino.h @@ -51,8 +51,15 @@ static const uint8_t A3 = 9; #define analogPinToChannel(p) ( (p) < 6 ? (p) : (p) - 6 ) +#define TCCR1A GTCCR + #ifdef ARDUINO_MAIN +void initVariant() +{ + GTCCR |= (1 << PWM1B); +} + // these arrays map port names (e.g. port B) to the // appropriate addresses for various functions (e.g. reading // and writing) tiny45 only port B @@ -106,7 +113,7 @@ const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { TIMER0B, NOT_ON_TIMER, NOT_ON_TIMER, - NOT_ON_TIMER, + TIMER1B, NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER,