little update..
I've cleaned up the code a lot in the time I've had, added watchdog timer, eeprom, and some timing libraries to keep things readable.
Then I went back to experimenting with the circuit a bit
Not the dead one soldered on board. The messy one thats on my desk with digital stuff on a breadboard.
So
@hardboiledfrog your suggestion to drive the gate resistors works pretty well!
I've got an NPN->PNP pair, and it has the functionality I want (on when pin HIGH).
Instead of using hardware PWM, I'm bitbanging the output in an interrupt routing called every 100uS with up to 200 steps 1/(200*100*10^-6) = 50Hz.
Why bitbang? It gives me more control over frequency counting!
Yep yep. just got it to work. I put a low pass filter on the gate input, connected to an NPN that drives a GPIO input. I have a rising edge interrupt and count the cycles. I can then derive a frequency, which rises as I put a work piece in! So, if I run my bitbanger at 0.5% (1 step), the thing draws just a few milliamps, and this will be a ready-idle state. , and can reliably detect when I insert the vapcap, which can activate the PID and increase duty cycle accordingly. when I remove the vapcap, the frequency drops again and I am back in idle with PID off. I haven't implemented all this yet - but it does detect insertion
The LPF and transister is a bit fiddly. I had to use a potentiometer to get the right values. I'll soon have an optoisolater with a hysteresis which should work better.
Here's the (very) sloppy code I threw together in a few minutes to see if it works. At this stage, it keeps the unit at 5% and jump to 30% when I insert the VC.
I'm very happy this works, as the photointerruptor I had didn't really work when I put it on the outsides of the glass tube. Besides, I like this feature much more
On Wednesday I should get my mouser shipment, then I'll rebuild the oscillator on my prototype board, improve the frequency meauseremt, hook it all up, and it should be good to go
Now.. zzzzz
#include <TimerOne.h>
int controllerCounter = 0;
int myPwm = 10;
#define PWM_STEP_MICROS 200
#define PWM_RESOLUTION 100
int onsteps = 0;
long count = 0;
float freq = 0;
void setup() {
pinMode(6, OUTPUT);
Timer1.initialize(PWM_STEP_MICROS);
Timer1.attachInterrupt(output_controller);
attachInterrupt(digitalPinToInterrupt(7), counter, RISING);
Serial.begin(119200);
Timer1.start();
}
void loop() {
delay(1000);
Serial.println(String(freq,3));
}
void counter() {
count++;
}
void output_controller() {
int stage = controllerCounter % PWM_RESOLUTION;
if (stage==0) {
count = 0; onsteps = 0;
}
if ( (stage < myPwm) || (freq > 400000.0 && stage < 60 ) {
digitalWrite(6, HIGH);
onsteps++;
} else {
digitalWrite(6, LOW);
}
if (stage==50) {
freq = count*1000000.0/(PWM_RESOLUTION*onsteps);
}
controllerCounter += 1;
}