SpenceKonde / megaTinyCore

Arduino core for the tinyAVR 0/1/2-series - Ones's digit 2,4,5,7 (pincount, 8,14,20,24), tens digit 0, 1, or 2 (featureset), preceded by flash in kb. Library maintainers: porting help available!
Other
551 stars 143 forks source link

Lost PWM on PA3 using Tiny 412 from 2.2.7 to 2.2.8 #335

Closed ldalep closed 3 years ago

ldalep commented 3 years ago

After downloading 2.2.8 into an old program that worked long time ago the PWM on PA3 quit. Hardware still works because blink turns the pin on and off. Do I have to go back and retro 2.1.5 to prove this or is there something obvious missing. PWM works fine on PA2, PA1

This Works

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(PIN_PA3, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(PIN_PA3, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(PIN_PA3, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

This wont

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(PIN_PA3, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  analogWrite(PIN_PA3, 64);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  analogWrite(PIN_PA3, 0);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

YUP Broke between 2.2.7 and 2.2.8 -

SpenceKonde commented 3 years ago

Yup. Actually, everyone lost PWM on half the TCA pins. Pure typo, 0x40 instead of 0x04. 5ae2da14d141df1b400bcbb52a35f0d4bf6f6186

ldalep commented 3 years ago

Darn an I just started to look at bit_mask when I decided to take a nap - maybe next time

SpenceKonde commented 3 years ago

bit_mask < 0x40 for all pins with TCA0 PWM at that point in the code flow so that's a clue ;-)

it's supposed to check if it's > 0x04, to separate the HCMP channels WO3, WO4, WO5, typically on bits 3, 4, and 5 of a port, since whether a channel is outputting PWM depends on the xCMPnEN bits in TCA0.SPLIT.CTRLB. (where x is H for 3~5, L for 0~2), and n is 0~2 (channel number modulo 3). But they had to put a stupid gap between the LCMP and HCMP channels otherwise it would be exactly equal to the bit_mask for the pin! So if bit_mask > 0x04 (ie, the bit thats set is higher than bit 2), we have to leftshift it 1 to get the bit to set (or clear, for turnOffPWM() )

ldalep commented 3 years ago

Are you sure about turnOffPWM - I can't turn off PA3 - x01 is as low as I can go - other PWM turn off. 2.2.7 works for all

SpenceKonde commented 3 years ago

Are you using the version from the 2.2.x branch? I don't think i propagated the fix to master since 2.2.x is the one I;m doing the release from - master is only fit for 2-series development currently

On Wed, Feb 24, 2021 at 8:01 PM ldalep notifications@github.com wrote:

Are you sure about turnOffPWM - I can't turn off PA3 - x01 is as low as I can go - other PWM turn off.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/335#issuecomment-785498360, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTXEW6MGTCKYPDHWI7IVQ3TAWOOZANCNFSM4YDALQ7A .

--


Spence Konde Azzy’S Electronics

New products! Check them out at tindie.com/stores/DrAzzy GitHub: github.com/SpenceKonde ATTinyCore https://github.com/SpenceKonde/ATTinyCore: Arduino support for all pre-2016 tinyAVR with >2k flash! megaTinyCore https://github.com/SpenceKonde/megaTinyCore: Arduino support for all post-2016 tinyAVR parts! DxCore https://github.com/SpenceKonde/DxCore: Arduino support for the AVR Dx-series parts, the latest and greatest from Microchip! Contact: spencekonde@gmail.com

SpenceKonde commented 3 years ago

yeah I can't automatically merge changes to 2.2.x forward to master anymore because I accidentally merged master into 2.2.x and had to revert it, so now any pull gets the commits that turn the proto 2.3.0 back into 2.2.x. and obviously we don;t want those. will have to manually fix that issue or something :-(

On Wed, Feb 24, 2021 at 8:01 PM ldalep notifications@github.com wrote:

Are you sure about turnOffPWM - I can't turn off PA3 - x01 is as low as I can go - other PWM turn off.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/335#issuecomment-785498360, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTXEW6MGTCKYPDHWI7IVQ3TAWOOZANCNFSM4YDALQ7A .

--


Spence Konde Azzy’S Electronics

New products! Check them out at tindie.com/stores/DrAzzy GitHub: github.com/SpenceKonde ATTinyCore https://github.com/SpenceKonde/ATTinyCore: Arduino support for all pre-2016 tinyAVR with >2k flash! megaTinyCore https://github.com/SpenceKonde/megaTinyCore: Arduino support for all post-2016 tinyAVR parts! DxCore https://github.com/SpenceKonde/DxCore: Arduino support for the AVR Dx-series parts, the latest and greatest from Microchip! Contact: spencekonde@gmail.com

SpenceKonde commented 3 years ago

but not doing that now.

On Wed, Feb 24, 2021 at 8:01 PM ldalep notifications@github.com wrote:

Are you sure about turnOffPWM - I can't turn off PA3 - x01 is as low as I can go - other PWM turn off.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/335#issuecomment-785498360, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTXEW6MGTCKYPDHWI7IVQ3TAWOOZANCNFSM4YDALQ7A .

--


Spence Konde Azzy’S Electronics

New products! Check them out at tindie.com/stores/DrAzzy GitHub: github.com/SpenceKonde ATTinyCore https://github.com/SpenceKonde/ATTinyCore: Arduino support for all pre-2016 tinyAVR with >2k flash! megaTinyCore https://github.com/SpenceKonde/megaTinyCore: Arduino support for all post-2016 tinyAVR parts! DxCore https://github.com/SpenceKonde/DxCore: Arduino support for the AVR Dx-series parts, the latest and greatest from Microchip! Contact: spencekonde@gmail.com

ldalep commented 3 years ago

Ok ... what I did was use 2.2.x - I 'm a bit confused how would I have been able to turn on PA3 at all if I hadn't been using the one you fixed - I did notice a lot of the series 2 stuff in the menus

SpenceKonde commented 3 years ago

Well, I just found yet another bug here o_o I am baffled as to how you could have made PWM come out of PA3 with the version I had checked in period. Am testing this myself before I do 2.2.9 release

There were also 2 commits that brought these changes - first the analogWrite() fix, then the turnOffPWM fix, a few minutes after I mentioned "turnOffPWM" for the first time in this conversation.

SpenceKonde commented 3 years ago

Oh, of course, PA3's PWM wasn't broken by the most recent thing I fixed, that was PA7's PWM

SpenceKonde commented 3 years ago

Anyway, it's confirmed working now with

const uint8_t pins[]={PIN_PA1,PIN_PA2,PIN_PA3,PIN_PA7};
void setup() {
  // put your setup code here, to run once:
  pinMode(PIN_PA1,OUTPUT);
  pinMode(PIN_PA2,OUTPUT);
  pinMode(PIN_PA3,OUTPUT);
  pinMode(PIN_PA7,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  static byte i = 0;
  static byte p = 0;
  i += 16;
  analogWrite(pins[p],i);
  delay(500);
  if (i == 0) { p++; }
  if (p > 3) {p = 0;}
}

Releasing 2.2.9 - thanks for reporting this one.

ldalep commented 3 years ago

THANK YOU THANK YOU - I am back to where I started ..... Is there a donation place that I can help out. I am a poor old Microwave test engineer retired so my contribution to bug fixing is not of the same level that you do. I am now going to see if the external crystal working on the 1614 can be put it to sleep and wake it up with knowing how much elapsed time has happened I will be home free on this project- Thanks again Dr.... serious need to donate something!