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;
}
}
