AnalogRead and odd results when using PWM?

I'm working on a project where I pulse a LED and modify the max brightness and the speed of the pulsing based on an analog input. I'm testing the project using two pot's before hooking it up to the final hardware. And I'm getting really weird results.

When I ONLY read the pot values, then use map() to map the input readings from analogRead to a range of 0-255 (for the PWM) the readings are stable - my serial output stays perfectly steady. Pot all the way down reads 0, pot all the way up reads 254.

However, when I then take that value, and try to analogWrite it to a PWM pin to control the brightness of an LED, the readings on the pot's get funky.

The pot all the way up will read a value higher than 254 (I am testing this with a 3.3v pro mini - so the max analogRead value from the pot is 836 or so, for the 3.3v), and the non-map'ed value will go all the way to 1023. When the pot is all the way down, instead of reading 0, it bounces around between 53 to 277 or so - the raw value being anywhere from 3 or so up to 1023.

If I comment out the analogWrite to the PWM pin and restart it, the input/read values are steady again. The sketch is below. It's driving me batty.

And again, the Arduino is a 3.3v pro mini, powered by both USB from the PC, and I tried it with a stable external power as well, and the values were jumpy.

void setup() {

    Serial.begin(38400);

    pinMode(A1, INPUT);
    pinMode(A0, INPUT);

    pinMode(3, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
      
    analogWrite(3, 0);
    analogWrite(5, 0);
    analogWrite(6, 0);
}

void loop() {
    int16_t d1 = 0; 
    int16_t d2 = 0; 
    int16_t ydiff;

    d1 = map(analogRead(A0), 0, 836, 0, 254);
    d2 = map(analogRead(A1), 0, 836, 0, 254);


    analogWrite(3, d1);
    analogWrite(5, d2);
    Serial.print(d1);
    Serial.print("/");
    Serial.println(d2);
    delay(250);
    
}

Here is the serial window output with the script as shown above. At the dashed line I inserted, I turned the pot for A0 (value d1 in the sketch) all the way down:

166/173
166/172
167/172
137/141
167/172
166/173
166/172
167/172
167/172
166/172
166/172
167/172
149/142
167/172
167/172
166/171
167/172
--- turned the pot down to 0 here:
130/172
101/172
101/172
263/172
162/160
48/172
41/140
55/160
63/172
61/143
115/172
184/172
278/172
274/172

Now, this is the output with the two analogWrite lines commented out:

71/141
71/141
71/141
71/141
71/141
71/141
71/141
71/141
71/141
-- Turned it down here:
70/141
34/141
13/141
8/141
5/141
4/141
4/141
0/141
0/141
0/141
0/141
0/141

Notice how with the analogwrite in, the second number, d2, bounced between 141 and 172, and with analogwrite commented out, it stayed a solid 141.

Why would analogWrite'ing to a PWM pin 3 effect the input being read from A0 and A1?

How are the pots wired? A picture of your setup might be helpful.

Nevermind - I figured it out. Did some more googling and found a post talking about the reference voltage. I tested my voltages and they were jumping all over. I realized that being lazy, I was using the voltage from the RAW pin to power the pots, instead of the VCC pin - RAW already had a jumper soldered to it, so I used that instead of VCC, which did not.

Once I moved the power over to VCC, the voltage remained stable and all worked as expected.