I have a breadboard ATMeg328p chip, configured with the 16Mhz external crystal and the UNO bootloader, controlling a MOSFET switch to spin a disco ball. I'm using PWM on pin ~3 via the digitalWrite function.
I really like the set-up, the light bouncing around the room, and the project in general but the set-up just stops working after approximately 10 minutes. If I switch it off and then back on, it continues working again until another 10 minutes have elapsed.
I've checked the voltage to the chip and it is steady at 5.04 V so I don't see it as a brown-out situation. Also, I looked at the forums and saw some mention of serial.print causing issues with buffers. I went back through the sketch and removed all the serial.print statements I had in there. They were definately affecting the timing of the PWM digitalWrites but removing them, and changing the duration of the digitalWrite functions, hasn't stopped the problem.
The code is very simple.
#define LED 7
int fr = 8000; // frequency - du
int du = 2000;
int j = 0;
void setup()
{
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(LED, OUTPUT);
}
void loop()
{
if (j<2)
{
digitalWrite(LED, HIGH);
Serial.print("Wrote HIGH ");
Serial.print(j);
Serial.println("th time");
delay(500);
digitalWrite(LED, LOW);
delay(500);
}
j++;
digitalWrite(3, HIGH);
delayMicroseconds(du);
digitalWrite(3, LOW);
delayMicroseconds(fr);
}
It seems that a buffer is overflowing somewhere. The chip just resets itself continuously if I don't switch it off and back on again, but I'm not aware of filling any buffers using the code I'm using.
Any suggestions?
thanks
Sarge