On an Arduino Uno, I have a sketch akin to this:
void setup()
{
// Generate some PWM signal on Pin 5, using Timer 0.
pinMode(5, OUTPUT);
TCCR0A = 0b00110011;
TCCR0B = 0b00001000;
OCR0A = 0x80;
OCR0B = 0x20;
TIMSK0 = 0b00000100;
Serial.begin(115200);
}
void loop()
{
// Just write the result of millis to the terminal.
unsigned long ms = millis();
char s[100];
sprintf(s, "%lu\r\n", ms);
Serial.print(s);
}
Setup timer 0 to generate a PWM signal, setup the serial port, constantly print the result of millis()
to the terminal.
The numbers printed to the console do not increase as expected, but stay "0".
Similarly, if I use micros
, "4" is printed constantly.
How's that?