tone function affecting parts of code

Hello all,
I am trying to control the gates to 2 different amplifier FETs. I need 3 distinct gate voltages, -1.4, -1.1, and -0.8. To do so, I used 3 of the PWM pins, followed by a LPF and subsequent G=-1 inverting op-amp.
I have 3 conditions, to switch between these states, I have a few SPDT which I am using as digital inputs (see attached picture). PwrOn turns on voltages regulators and will be always ON during for this example. Truth table below:

RFen ModEn Vg1 Vg2
0 0 -1.4V -1.4V
0 1 -1.4V -1.4V
1 0 -1.1V -0.8V
1 1 -1.1-1.4V @100 Hz -0.8V

To control Vg1 and create the 100 Hz signal, I have an digital multiplexer being feed both the -1.4 and -1.1 signals and its address pin is tied to a digital output, pin 7. Vg2 doesn't need to modulate, to change its state, the PWM duty cycle is changed to meet the required -1.4 or -0.8V.
I was using the tone function to create the 100Hz control signal for the multiplexer. The truth table for pin 7 is:

RFen ModEn Pin 7
0 0 LOW
0 1 LOW
1 0 HIGH
1 1 tone(100Hz)

When I try and implement this: something strange happens: and I suspect is because I am switching pin 7 between a digital output and tone. The first 3 cases work in both truth tables work with the code below. When i try the fourth case, the tone function will work, Vg1 will modulate, however, Vg2 will turn off entirely! I probe the output of the PWM directly, and its off? When I toggle the RFen back to 0, the PWM turns back on, and Vg2 reads the correct -1.4V. Why would turning on the tone function turn off the PWM on a different pin?

Happy to provide more context, Thanks in advance for any help,
Sami

//Pin definitions
const int PAenable = 2;
const int PAgate = 3;
const int VCOenable = 4;
const int RefDrive = 5;
const int RefPinchOff = 6;
const int MuxOut = 7;
const int VarAtten = 9;
const int ListenEn = 10;
const int RFpwr = A0;
const int Modenable = A1;
const int PwrON = A2;




//Variables
int PADrive = 43;
int GateDrive = 56;   // 43 = 0.8V    50 = 0.96V   56 = 1.1V
int GatePinchOff = 73;  //73 = 1.42V
int ToneFreq = 100;
unsigned long VCOtimedelay = 5000;
unsigned long Buttondelay = 2500;
unsigned long PwrDelay = 1000;




void setup() {


  pinMode(PAenable, OUTPUT);              //Digital 2
  analogWrite(PAgate, GatePinchOff);      //Digital 3
  pinMode(VCOenable, OUTPUT);             //Digital 4
  analogWrite(RefDrive, GateDrive);       //Digital 5
  analogWrite(RefPinchOff, GatePinchOff); //Digital 6
  pinMode(MuxOut, OUTPUT);                //Digital 7
  analogWrite(VarAtten, 0);               //Digital 9
  digitalWrite(PAenable, LOW);            //Digital 2
  digitalWrite(VCOenable, LOW);           //Digital 4
}




void loop() {
 if (millis() > Buttondelay) {


    if (digitalRead(PwrON)) {
      
      if (digitalRead(RFpwr)) {         


        if (digitalRead(Modenable)) {
          analogWrite(PAgate, PADrive/2);    
          //digitalWrite(MuxOut, HIGH); 
          tone(MuxOut, ToneFreq);           // This tone function is causing the issues. If replaced with the digitalwrite function above, this segment of code works as expected, but missing the modulation of course.
          Serial.println("RF ON and MOD ON");
        }
        if (!digitalRead(Modenable)) {     
          analogWrite(PAgate, PADrive);      
          digitalWrite(MuxOut, HIGH);        
          Serial.println("RF ON and MOD OFF");
        }
      }
      if (!digitalRead(RFpwr)) {
        analogWrite(PAgate, GatePinchOff);   
        noTone(MuxOut);
        digitalWrite(MuxOut, LOW);          
        Serial.println("RF OFF and MOD OFF");
      }
    }
    Buttondelay = Buttondelay + 1000;
  }






}

the tone() function uses timer2
On a UNO Timer 2 controls PWM on pins 3 & 11 and Pin 9,10 on a Mega

J-M-L:
the tone() function uses timer2
On a UNO Timer 2 controls PWM on pins 3 & 11 and Pin 9,10 on a Mega

That would certainly explain it. Does timer1 control the other PWM pins? If its free, I can set up 100 Hz myself?

Does timer1 control the other PWM pins

well, each timer is associated to some pins and possibly used in some libraries.
for example if you don't use the Servo library (or another library requiring Timer1) then pins 9 & 10 on an UNO are OK for PWM.

There are 3 timers frequently used:

Timer0 is used for the timer functions, like delay(), millis() and micros(). If you change timer0 registers, this may influence the Arduino time functions ==> probably not a good idea

the Servo library uses Timer1 on Arduino Uno (Timer5 on Arduino Mega).

the tone() function uses Timer2.

Timers also are used to drive PWM:

On an Arduino UNO :

Timer 0 : pins 5 & 6 : 976.5625 Hz (8 bits > 256 values)
Timer 1 : pins 9 & 10 : 490.20 Hz (16 bits > 65536 values)
Timer 2 : pins 3 & 11 : 490.20 Hz (8 bits)

On an Arduino MEGA :

Timer 0 : pins 4 & 13
Timer 1 : pins 11 & 12
Timer 2 : pins 9 & 10
Timer 3 : pins 2, 3 & 5 (16 bits)
Timer 4 : pins 6, 7 & 8 (16 bits)
Timer 5 : pins 46, 45 & 44 (16 bits)

On a Mega you can have multiple Tone at once, in which case timers will be used in the following order: 2, 3, 4, 5, 1

Your switches are wired completely wrong. You have floating inputs when the switches are off.

aarg:
Your switches are wired completely wrong. You have floating inputs when the switches are off.

The switches are connected to ground when off? If that is wrong, whats the right way?

Ah, sorry... yeah, it will work. The switches are floating for a short time between positions, but in practice it won't matter because the capacitance of the input will hold the previous state for a while until the other set of contacts close. But it is needlessly elaborate. You can just configure the inputs with INPUT_PULLUP instead of just INPUT in the pinMode() call, to enable the internal pull up resistors, then all you need is the ground on the switches, you can eliminate the VCC and resistor connections. In the end, that is simpler and more predictable than what you have there.

If you've already laid out a PCB, you can do as I suggest and just omit R2.

aarg:
You can just configure the inputs with INPUT_PULLUP

Thanks, that’s a great shortcut. I Can drop the resistor and the area needed to route 5v to the switches.
Since I didn’t know about the internal pull-up option, I Spent the extra few cents to get ‘make before break’ switches. No one likes those undefined states. especially when these signals are controlling the gates of normally on FETs.

Thanks again, both of you. Solved my problem and learned a few new things!

J-M-L:
On an Arduino UNO :

Timer 0 : pins 5 & 6 : 976.5625 Hz (8 bits > 256 values)
Timer 1 : pins 9 & 10 : 490.20 Hz (16 bits > 65536 values)
Timer 2 : pins 3 & 11 : 490.20 Hz (8 bits)

Exactly what I was looking for! Simple fix, put my 4 pwm outputs on pin 5,6,9,10. Leaving timer 2 free for tone.
Thanks for patience and help

Cool !