user6936: I have this code, which puts the Arduino into CTC mode with interrupts, and outputs a square wave on PD6 (OC0A):
void setup_timer(double p_ms, double duty){
  DDRD |= (1 << 6);  // set pin 3 as output  
  TCCR0A = _BV(COM0A0); // toggle OC0A on Compare Match
  TCCR0B = _BV(WGM01); // set CTC mode WGM0[2,1,0] = 0b010 
  TIMSK0 |= _BV(OCIE0A); // Enable CTC interrupt  
  OCR0A = 128;  // set on and off time
  TCCR0B |= ( (0 << CS02) | (0 << CS01) | ( 1 << CS00)); // CS02:0 - No prescaling
  sei();
}

In the ISR (which is not shown) I want to be able to see whether OC0A (i.e. PD6) is HIGH or LOW.
I assumed that I could do a digitalRead(), but this post, Re: How to read the state of an output pin ? says:

Looking at the code the digitalRead() function just does a read of the appropriate bit in the appropriate PINx register without modifying anything, so it should work.
One catch, if it's a PWM pin the PWM will be stopped.

So, will the toggling of OCR0A be stopped?
This answer to How can I digitalRead a pin that is in pinMode OUTPUT? suggests reading PORTD directly, with
bitRead(PORTD,6);

However, will that work for PWM output or will PWM also be stopped by reading PORTD?

Addendum
I plan to use this code either as (primarily) a stand alone AVR µController (48/88/168/328 IC), but maybe in a Nano/Uno (if it will work) for testing purposes. I understand that using Timer0 will affect the operation of millis(), delay() etc., but the rest of the code will not rely on any of those functions... so I presume (maybe incorrectly) that the code will work as expected. Is that correct?
In addition, I don't intend on using a setup() & loop() program structure but rather main(). Just out of interest, would loop() work (i.e. is it reliant on Timer0)? I don't believe that it is.

user23841: If you look into the Arduino Core, you'll find this code for the digital read:
int digitalRead(uint8_t pin)
{
    uint8_t timer = digitalPinToTimer(pin);
    uint8_t bit = digitalPinToBitMask(pin);
    uint8_t port = digitalPinToPort(pin);

    if (port == NOT_A_PIN) return LOW;

    // If the pin that support PWM output, we need to turn it off
    // before getting a digital reading.
    if (timer != NOT_ON_TIMER) turnOffPWM(timer);

    if (*portInputRegister(port) & bit) return HIGH;
    return LOW;
}

That means, disabling PWM is just weird feature in digitalRead.
For reading bitRead(PORTB,3); I'm not so sure if you'll get output value of OC0A, it might be different signal line internally. However you'll get logical level on the port pin by reading bitRead(PINB,3);.

user7508: Preliminary note: If you are using any of the ATmega48/88/168/328,
then the OC0A pin is PD6, not PB3.
As four your idea of reading the PORT register (PORTD, not PORTB),
it won't work either, as that will only tell you what was the last value
that was written to the port with digitalWrite(). Here is a schematic
showing how the timer controls the output pin. It's taken from the
ATmega328P datasheet, but the other AVRs of that family behave
identically in this respect:

As shown in the schematic, the value written to the port comes from a
multiplexer and is controlled either:

by the PORT flip-flop when the timer is not generating a PWM output
or the OC0A flip-flop when it is.

Quite importantly, the timer does not write to the PORT register, it
only overrides it.
Thus, it would look like you want to read the OC0A flip-flop in your
ISR. Alas, this schematic also shows that, contrary to the PORT
flip-flop, the OC0A flip-flop is not connected to the data bus. Thus
you cannot read it, and it doesn't even have an address.
What I would recommend is to read the PIN register instead. This won't
tell you what the timer is writing to the port, but what you can read
back. However, unless the pin is loaded well beyond its absolute maximum
rating, what you read back what has been written. There is a small delay
between the write operation and the value been available to read back (a
couple of CPU cycles IIRC), but this is way shorter than the execution
time of an ISR prologue.

6936: <p>I have this code, which puts the Arduino into CTC mode with interrupts, and outputs a square wave on <code>PD6</code> (<code>OC0A</code>):</p>
<pre><code>void setup_timer(double p_ms, double duty){
  DDRD |= (1 &lt;&lt; 6);  // set pin 3 as output  
  TCCR0A = _BV(COM0A0); // toggle OC0A on Compare Match
  TCCR0B = _BV(WGM01); // set CTC mode WGM0[2,1,0] = 0b010 
  TIMSK0 |= _BV(OCIE0A); // Enable CTC interrupt  
  OCR0A = 128;  // set on and off time
  TCCR0B |= ( (0 &lt;&lt; CS02) | (0 &lt;&lt; CS01) | ( 1 &lt;&lt; CS00)); // CS02:0 - No prescaling
  sei();
}
</code></pre>
<p>In the <code>ISR</code> (which is not shown) I want to be able to see whether <code>OC0A</code> (i.e. <code>PD6</code>) is <code>HIGH</code> or <code>LOW</code>.</p>
<p>I assumed that I could do a <code>digitalRead()</code>, but this post, <a href="https://forum.arduino.cc/index.php?topic=102716.0" rel="nofollow noreferrer">Re: How to read the state of an output pin ?</a> says:</p>
<blockquote>
<p>Looking at the code the digitalRead() function just does a read of the appropriate bit in the appropriate PINx register without modifying anything, so it should work.</p>
<p>One catch, if it's a PWM pin the PWM will be stopped.</p>
</blockquote>
<p>So, will the toggling of <code>OCR0A</code> be stopped?</p>
<p><a href="https://stackoverflow.com/questions/6160963/how-can-i-digitalread-a-pin-that-is-in-pinmode-output#answer-6171551">This answer</a> to <a href="https://stackoverflow.com/questions/6160963/how-can-i-digitalread-a-pin-that-is-in-pinmode-output">How can I digitalRead a pin that is in pinMode OUTPUT?</a> suggests reading PORTD directly, with</p>
<pre><code>bitRead(PORTD,6);
</code></pre>
<p>However, will that work for PWM output or will PWM also be stopped by reading <code>PORTD</code>?</p>
<hr />
<h3>Addendum</h3>
<p>I plan to use this code either as (primarily) a stand alone AVR µController (48/88/168/328 IC), but maybe in a Nano/Uno (if it will work) for <em>testing purposes</em>. I understand that using <code>Timer0</code> will affect the operation of <code>millis()</code>, <code>delay()</code> etc., but the rest of the code will not rely on any of those functions... so I presume (maybe incorrectly) that the code will work as expected. Is that correct?</p>
<p>In addition, I don't intend on using a <code>setup()</code> &amp; <code>loop()</code> program structure but rather <code>main()</code>. Just out of interest, would <code>loop()</code> work (i.e. is it reliant on <code>Timer0</code>)? I don't believe that it is.</p>
 23841: <p>If you look into the Arduino Core, you'll find this code for the digital read:</p>

<pre class="lang-cpp prettyprint-override"><code>int digitalRead(uint8_t pin)
{
    uint8_t timer = digitalPinToTimer(pin);
    uint8_t bit = digitalPinToBitMask(pin);
    uint8_t port = digitalPinToPort(pin);

    if (port == NOT_A_PIN) return LOW;

    // If the pin that support PWM output, we need to turn it off
    // before getting a digital reading.
    if (timer != NOT_ON_TIMER) turnOffPWM(timer);

    if (*portInputRegister(port) &amp; bit) return HIGH;
    return LOW;
}
</code></pre>

<p>That means, disabling PWM is just weird feature in <code>digitalRead</code>.</p>

<p>For reading <code>bitRead(PORTB,3);</code> I'm not so sure if you'll get output value of <code>OC0A</code>, it might be different signal line internally. However you'll get logical level on the port pin by reading <code>bitRead(PINB,3);</code>.</p>
 7508: <p><strong>Preliminary note</strong>: If you are using any of the ATmega48/88/168/328,
then the OC0A pin is PD6, not PB3.</p>

<p>As four your idea of reading the PORT register (<code>PORTD</code>, not <code>PORTB</code>),
it won't work either, as that will only tell you what was the last value
that was written to the port with <code>digitalWrite()</code>. Here is a schematic
showing how the timer controls the output pin. It's taken from the
ATmega328P datasheet, but the other AVRs of that family behave
identically in this respect:</p>

<p><a href="https://i.stack.imgur.com/v0Dlg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v0Dlg.png" alt="Compare match output unit"></a></p>

<p>As shown in the schematic, the value written to the port comes from a
multiplexer and is controlled either:</p>

<ul>
<li>by the PORT flip-flop when the timer is <em>not</em> generating a PWM output</li>
<li>or the OC0A flip-flop when it is.</li>
</ul>

<p>Quite importantly, the timer does <em>not</em> write to the PORT register, it
only overrides it.</p>

<p>Thus, it would look like you want to read the OC0A flip-flop in your
ISR. Alas, this schematic also shows that, contrary to the PORT
flip-flop, the OC0A flip-flop is <em>not</em> connected to the data bus. Thus
you cannot read it, and it doesn't even have an address.</p>

<p>What I would recommend is to read the PIN register instead. This won't
tell you what the timer is writing to the port, but what you can read
back. However, unless the pin is loaded well beyond its absolute maximum
rating, what you read back what has been written. There is a small delay
between the write operation and the value been available to read back (a
couple of CPU cycles IIRC), but this is way shorter than the execution
time of an ISR prologue.</p>
