Q:

Read analog port set as output

I have a PWM analog port that is outputting a frequency, is it possible to do an analogRead on the same pin and get a correct value? If so, will reading that port disrupt the freq output on the pin? This is being done on a Teensy 3.2 device. My goal is to output the freq visually on an OLED. Tnx.

A:

You want the voltage that would be read by a voltmeter? If you know what value you set for PWM, you know the voltage that is generated.
But if you are curious,  you can connect the PWM output to ADC pin and read for example a 100 values and calculate the average. You will see that at the same resulution of PWM and ADC, you get as average of ADC values the same value as you set for PWM.
This is for M0:
void setup()
{
  Serial.begin(115200);
  while (!Serial);

  analogWriteResolution(10);

  for (int i = 0; i < 1024; i += 10) {
    analogWrite(7, i);
    delay(100);
    long sum = 0;
    int n = 0;
    unsigned long start_time = millis();
    while (millis() - start_time < 100) {
      sum += analogRead(A1);
      n++;
    }
    Serial.print(i);
    Serial.print(' ');
    Serial.println(sum / n);
  }
}

void loop()
{
}

