Board: Arduino UNO.
Micro-controller on board: Atmega 328P-PU.
LEDs connected to pins 3 and 11. Shows the two PWM waveforms.
Goal: measure current using Hall Effect sensor, ACS770ECB-200U and transfer to PC.
I found "The Serial.prints are actually set in an ISR, so they will be affecting interrupts."
and
"- -and timer interrupts are higher priority than serial interrupts - -".
This would explain why the "I'm here2" is not sent to the Serial Monitor after I set the TOIE2 bit.
Would you please direct me to a method of sending data to the Serial Monitor when using/changing Timer2 interrupt(s) for PWM.
Thank you.
void setup()
{// Put your setup code here, to run once:
Serial.begin(9600); // open serial port.
delay(20); // Put a delay in to open port.
Serial.println (F("Hello World"));
Serial.println (F("")); // Blank line.
delay(30); // Must delay 'some' to allow buffer to be xmtd.
//
unsigned long StartTime;
unsigned long time;
StartTime = micros(); //overflows (goes back to zero) after approximately 70 minutes.
//
Serial.print(F("Start Time in microsecs : ")); // Use macro F( ) to save SRAM
Serial.println(StartTime);
delay(50); // Must delay 'some' to allow buffer to be xmtd.
//
pinMode(3, OUTPUT); // Connected to Output Compare OC2 B
pinMode(11, OUTPUT); // Connected to Output Compare OC2 A
// Clear Timer Control Registers, just in case
TCCR2A = 0;
Serial.println(F("I'm here1"));
delay(50); // Must delay 'some' to allow buffer to be xmtd.
//
TIMSK2 = _BV (TOIE2); // TC2 Interrupt Mask Register. Enable the timer 2 interrupt
Serial.println(F("I'm here2"));
delay(50); // Must delay 'some' to allow buffer to be xmtd.
TIFR2 = _BV (TOV2); // TC2 Interrupt Flag Register. Clear TOV2 (by writing a 1) Overflow Flag
// Set up the Timer/Counter Control Register 2, A & B
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
// CS22=0 CS21=1 cs20=1 prescaler for 32
TCCR2B = _BV(CS21) | _BV(CS20); // This will route Tclk to Timer 2 through scaler
// Set up the Output Compare Register 2, A & B
OCR2A = 32; // This is for monitoring the pin 11
OCR2B = 50; // This is for monitoring the pin 3
//
} // end of setup
void loop() {
// put your main code here, to run repeatedly:
}
Serial Monitor shows:
Hello World
Start Time in microsecs : 50132
I'm here1