Open magoldsm opened 1 month ago
Swapped out the 404 for a 1614. Interestingly, it now runs for 1590 calls before restarting!
I tried your code on an ATtiny814 and didn't see a problem. I was too lazy to hook up a device to capture the Serial output, but I added some code to blink an LED during setup to detect if the 814 crashed and restarted. It did not crash and restart.
My test code:
#define PINKY 1 // pin 3, PIN_PA5
#define RING 0 // pin 2, PIN_PA4
#define MIDDLE 6 // pin 8, PIN_PB1
#define INDEX 7 // pin 9, PIN_PB0
#define THUMB 10 // pin 13, PIN_PA3
int port = INDEX;
int writes;
void setup() {
// put your setup code here, to run once:
pinMode(port, OUTPUT);
for(int i=0; i<5; i++) { // blink the LED to show the ATtiny crash/restart
digitalWrite(port, 0); delay(200);
digitalWrite(port, 1); delay(200);
}
Serial.begin(115200);
delay(1000);
Serial.println("Starting");
auto cp = malloc(1024);
writes = 0;
}
byte data[1024]; // Taking up memory for this array made no difference.
void loop() {
Serial.print("writes: "); Serial.println(writes);
for (int i=0; i<256; i += 2) {
Serial.print('+');
analogWrite(port, i);
writes++;
delay(5);
}
Serial.println("");
Serial.print("writes: "); Serial.println(writes);
for (int i=254; i>=0; i -= 2) {
Serial.print('-');
analogWrite(port, i);
writes++;
delay(5);
}
Serial.println("");
}
byte data[1024]; will not use any memory if the data is never accessed - it will be optimized out. To prevent that, declare the array volatile. That will allow you test if it's a memory problem, which dollars to donuts it is. malloc and it's minion, the String class, are the hands of the devil on embedded systems like this. Avoid at almost any cost.
Discussed in https://github.com/SpenceKonde/megaTinyCore/discussions/1129