So i've been working on something using the ATMega2560 dev board and everything works great, no issues. I wanted to convert it down to the ATMega128 (MegaCore based). I can bootload the ATMega128 with no issues and load the sketch to it as well. I did change all the pinouts to match/correspond and everything works as it should, except the delay(): function, but for some odd reason, it only seems to be afftected while using an analogWrite(); function. The output is controlling a small 5v piezo buzzer.
What happens, is that the function processes, but when it comes to the delay for the beeping to stay on or off, the buzzer just chirps and doesnt run for the delay time while on. I've even raised the time and no change, also tried as a digitalWrite(); function and still no change. Here is a sample of the code that calls for 3 beeps (and when using the same code on the ATMega2560, it works as it should)...
void beep() {
for (int x = 0; x < 3; x++) {
analogWrite(Beep3, 200);
delay(200);
analogWrite(Beep3, 0);
delay(200);
}
digitalWrite(back_light, LOW);
lcd.clear();
delay(5000);
}
Pin assigments...
#define interruptPin 18 //D2 Pin 25 The interrupt pin on the main controller 1 0f 4 MCU
#define LCD_ADC A0 //A0 Pin 61 Buttons/Membrane
#define back_light A1 //A1 Pin 60 LCD Backlight
#define reset_tiny A2 //A2 Pin 59 Reset the Tiny85
#define Beep3 A3 //A3 Pin 58 Piezo Buzzer VCC
#define RX A4 //A4 Pin 57 NOT USED
#define TX A5 //A5 Pin 56 Tiny85 communication
#define power_pin 15 //D13 Pin 17 This pin controls the QV251
Setup...
void setup() {
//Initializes serial communication
pinMode(interruptPin, INPUT_PULLUP); //D2 Pin used as interrupt used for long press force sleep
pinMode(reset_tiny, OUTPUT); //A2 Pin Reset the Tiny85
pinMode(power_pin, OUTPUT); //D13 Pin This pin controls the QV251
pinMode(RX, INPUT_PULLUP); //A4 Pin NOT USED
pinMode(TX, OUTPUT); //A5 Pin Tiny85 communication
pinMode(Beep3, OUTPUT); //A3 Pin Piezo Buzzer VCC
pinMode(back_light, OUTPUT); //A1 Pin LCD Backlight
Serial.begin(57600); //Use USB to UART adapter for troubleshooting
mySerial.begin(9600); //Software serial for attiny85
startTime = millis();
//Initializes and clears the LCD screen
lcd.begin(8, 2); //(8,2) LCD
lcd.clear(); //Clears LCD
//Creates the byte for the 3 custom characters
lcd.createChar(0, menuCursor); //Creates cursor and sets first position
//Unit powers up in sleep mode
delay(100); //Delay for power on
digitalWrite(power_pin, LOW); //LCD and Tiny85 powered off
digitalWrite(reset_tiny, LOW); //Resets Tiny85
digitalWrite(TX, LOW); //Disable Tiny85 communication
Going_To_Sleep(); //Goes to sleep
}
It's a long sketch, but can pull out a lot if need be to post it entirely (just by removing all the menu items and such. My guess is theres maybe a fault with how MegaCore uses the delay(); function or perhaps an interrupt issue? either way, I've been looking and testing and looking and testing for quite some time with no luck.
Any help is appreciated