Now that my circuit is finally working as intended, I continued to make the discharge modification.
On the scope shot with the number ending in 3248, you can see the normal operation.
The blue trace is the "probed" ISR surrounding the ADC read cycle.
You can see that the capacitor slowly discharges during the sampling period. This means that due to the almost 200 ns jitter caused by the interrupt latency, there will be differences in the value read by the ADC. Not much, but we're dealing with ppb sensitivity, and I simply assume that every bit helps. Obviously, the discharge is higher than normal because I used a x10 scope probe to see the voltage level.
I modified the ISR a bit further with my proposed solution, and by using a digital port to discharge the capacitor at a planned point, while keeping the voltage level flat during the sampling period. Flat meaning that there will still be some discharge due to leakage and loading but this is as far as we can go with this solution. I used a free port, D10 and connected that through a 1K resistor directly to A0. The 10M resistor is removed from the circuit.
The code changes are as follows:
At the very beginning of the code, I added this:
// add a decharge for C1 after the ADC read cycle
const int decharge = 10; // Decharge pin for C1. Port is toggled between hi-0Z input and output driven low
const int probe = 12; // create a probing signal within the ISR
In setup(), I added this:
pinMode(decharge,INPUT); // setup the port that will decharge C1
pinMode(probe,OUTPUT); // setup the port to allow a probe inside de ISR
Here is the modified ISR:
// Timer1 capture interrupt routine - this runs at rising edge of 1PPS on D8
ISR (TIMER1_CAPT_vect)
{
timer1CounterValue = ICR1; // read the captured timer1 200ns counter value
digitalWrite(probe, 1); // create a signal to probe the scope
TIC_Value = analogRead(A0); // ns value
digitalWrite(probe, 0); // stop the probe
pinMode(decharge,OUTPUT); // change port from hi-Z to output
digitalWrite(decharge, 0); // force it to ground to decharge C1
PPS_ReadFlag = true; // gives the decharge cycle some time as well
pinMode(decharge,INPUT); // revert the port back to hi-Z
}
The "probes" are not there forever, when you're done, you can comment them out.
The next scope shot, ending with 4047, shows the C1 voltage level with the blue trace, and the probe around the ADC cycle in yellow. (channels are reversed from the previous picture) The voltage level is now very flat throughout, even though I still have my x10 probe connected.
Right after the ADC cycle ended, the voltage is forced to ground getting the hardware prepared for the next cycle. The timing works out very well, the discharge during one instruction and with 1K in series only takes a few micro seconds to complete. The 1K is only there because I don't like shortening capacitors, even though the stored energy in this case is minute.
My Isotemp replacement for the Bliley OCXO finally arrived, so I can start the full testing procedure again. Up until now, I had been using my modified FY6600 Waveform Generator as a replacement. You can set the frequency down in the micro Hz to make tuning by hand to the 1PPS possible.
Enjoy,
Paul