SpenceKonde / ATTinyCore

Arduino core for ATtiny 1634, 828, x313, x4, x41, x5, x61, x7 and x8
Other
1.53k stars 301 forks source link

ATtiny841 PWM works with 1.5.2 but not with 2.0.0 #813

Open bjfischb opened 8 months ago

bjfischb commented 8 months ago

PWM for ATtiny841 works with 1.5.2 but not with 2.0.0

Here's the code I'm running. Selecting the digitalWrite version works for both cores; the analogWrite version works for 1.5.2 but not 2.0.0

#define PIN_LED_INDICATOR PIN_PB2
#define FADEON
#define OSCCAL_REG_NAME OSCCAL0 //841 uses OSCCAL0; others use OSCCAL

void setup() {
  OSCCAL_REG_NAME = 0x1D; //tuned for this particular part

#ifdef FADEON
  pinMode(PIN_LED_INDICATOR, OUTPUT);
  analogWrite(PIN_LED_INDICATOR, 200);
#else
  pinMode(PIN_LED_INDICATOR, OUTPUT);
  digitalWrite(PIN_LED_INDICATOR, HIGH);
#endif

  Serial.begin(19200); 
  delay(100);
  Serial.println(F("Welcome to BareChip"));
}

void loop() {
  stdBlink();
}

void stdBlink() {
#ifdef FADEON 
  analogWrite(PIN_LED_INDICATOR, 64);
  delay(1000);
  analogWrite(PIN_LED_INDICATOR, 200);
  delay (1000);
#else   
  digitalWrite(PIN_LED_INDICATOR, LOW);  
  delay(200);                     
  digitalWrite(PIN_LED_INDICATOR, HIGH);    
  delay(800);                       
#endif  
}
ahshah commented 5 months ago

Confirmed.. not seeing PWM on my basic LED setup.
Commit that broke PWM: 6152259049ac9b81f896871c0733c5289308fd5e

I've proposed a fix here: https://github.com/ahshah/ATTinyCore/tree/Tiny841_PWM_Fix Please sync and test it and confirm it works. Once you do I can create a pull request.