# EEVblog Electronics Community Forum

## Electronics => Beginners => Topic started by: ManlishPotato on September 19, 2019, 07:41:13 pm

Title: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 19, 2019, 07:41:13 pm
Hey y'all
I'd like to make a tank circuit with a coil and capacitor in parallel. To power it i need a really frequent square wave. 1 mhz would be nice but maybe about a 500-600 mhz minimum. I was thinking of using a arduino directly interfacing the ports to produce the wave, using it to control a mosfet to power the circuit.
Yet the signal pretty much stays the same no matter how much i increase the voltage. I cant't check exactly want the value was right now , but i thing it hade about 1-2v voltage drop across the mosfet which seems like a lot, and like i said i cant get the voltage top much higher than 4.5-4.9v. It had peaks of about 5.2 i think.

Is this the wrong approach? How could you accomplish this for cheap?
//Benji
https://imgur.com/a/JjfIlp2 (https://imgur.com/a/JjfIlp2)
Title: Re: Fast square wave with arduino and mosfet
Post by: MarkF on September 19, 2019, 08:23:05 pm
The Arduino pin voltage is not high enough to turn on the MOSFET if you have the load on the low side as you have it.
You want your tank circuit on the high side.  Even so, you will need a logic-level MOSFET in order to fully turn it on.

[attachimg=1]
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 19, 2019, 08:30:05 pm
Isn't FQP30N06L logic level? Also, with the voltages i measured i had no load connected, like in schematic, i had only the oscilloscope connected.
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 19, 2019, 08:32:50 pm
BTW, why do you use i resistor in series to the gate of the mosfet, isn't mosfets voltage driven unlike bjt's?
Title: Re: Fast square wave with arduino and mosfet
Post by: MarkF on September 19, 2019, 08:47:53 pm
- I had not looked up your MOSFET.  A quick look appears like it is.

- In your circuit R1 is the load.  Which when the MOSFET is turned on the voltage across R1 rises and will turn off the MOSFET unless you raise the gate voltage to compensate.  (The load is on the low side.)

[attachimg=1]

- The series limits the gate current.  A MOSFET gate has a capacitance which you charge when you apply a voltage.  Also, you can have oscillations without the resistor.

(https://www.researchgate.net/profile/Quan_Sun14/publication/304033424/figure/fig1/AS:543824340164609@1506669234954/Equivalent-circuit-of-the-MOSFET.png)
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 19, 2019, 09:04:24 pm
Wow i didn't think of that! That makes sense, as i increase the voltage the more back flow i get. I'll have to try that tomorrow and post the result. Thanks for a great response!
Title: Re: Fast square wave with arduino and mosfet
Post by: MarkF on September 19, 2019, 09:15:48 pm
I expect 50 to 100 ohm will work best.
Title: Re: Fast square wave with arduino and mosfet
Post by: djacobow on September 20, 2019, 01:11:57 am
I think with a 16 MHz Arduino, your highest possible toggle speed is 2.67 MHz.

cli();
while (1) {
PORTD |= 0x8;
PORTD &= ~0x8;
}

Looks like that's 6 instructions.
Title: Re: Fast square wave with arduino and mosfet
Post by: MarkF on September 20, 2019, 01:54:47 am
Entry #18 in this topic https://forum.arduino.cc/index.php?topic=4324.0

If you know the state of the other pins on the port, then you could do something like:

while (1) {
PORTD = 0b00001000;
PORTD = 0b00000000;
}

for a 4Mhz 25% duty cycle signal (1 tick ON, 3 ticks OFF) or

while (1) {
PORTD = 0b00001000;
asm("nop");
asm("nop");
PORTD = 0b00000000;
}

for a 2.6666Mhz 50% duty cycle (3 ticks ON, 3 ticks OFF)
Title: Re: Fast square wave with arduino and mosfet
Post by: ledtester on September 20, 2019, 03:26:29 am
You can toggle an atmega GPIO with a single instruction by writing a 1 to the corresponding PIN bit:

https://www.avrfreaks.net/forum/toggle-state-output-pin (https://www.avrfreaks.net/forum/toggle-state-output-pin)

Title: Re: Fast square wave with arduino and mosfet
Post by: ledtester on September 20, 2019, 04:09:59 am
Hey y'all
I'd like to make a tank circuit with a coil and capacitor in parallel. To power it i need a really frequent square wave. 1 mhz would be nice but maybe about a 500-600 mhz minimum.

What are the values of your capacitor and inductor?
And what exactly do you want to accomplish?

To get a tank circuit to ring you don't need to continually excite it. Once excited it will ring on its own at its resonant frequency. Also, you don't have to directly couple it to your signal source. You can excite the tank by just wrapping a wire carrying your square wave around the inductor a few times. Have a look at this page in the section "Measuring LC tank circuits":

http://www.giangrandi.ch/electronics/ringdownq/ringdownq.shtml (http://www.giangrandi.ch/electronics/ringdownq/ringdownq.shtml)

Just a fast rising edge is enough to transfer energy into the tank, so your signal source doesn't have to pulse at a fast frequency.
Title: Re: Fast square wave with arduino and mosfet
Post by: Mechatrommer on September 20, 2019, 04:27:33 am
I think with a 16 MHz Arduino, your highest possible toggle speed is 2.67 MHz.

cli();
while (1) {
PORTD |= 0x8;
PORTD &= ~0x8;
}

Looks like that's 6 instructions.
4 instructions minimum. 2 ops to toggle pin on and off, 2 ops for goto. hence 16MHz / 4 ops = 4MHz maximum, but only in asm...
Title: Re: Fast square wave with arduino and mosfet
Post by: ledtester on September 20, 2019, 04:54:28 am
You could always unroll the loop and on a 16 Mhz atmega328 achieve 8 Mhz for about 2 milliseconds at a time with only a 100ns glitch between runs.

On a atmega2560 the 8  Mhz pulse train would last for around 16 ms.
Title: Re: Fast square wave with arduino and mosfet
Post by: T3sl4co1l on September 20, 2019, 07:30:24 am
Millihertz or megahertz?  It matters, rather a lot.

You can still connect an Arduino to something that can make 600MHz, but it's going to be a frequency synthesizer chip, something fit for purpose -- nothing the Arduino has direct participation in, only setting registers.  It's also not going to drive as much power as one of those transistors can, and you need special RF transistors to amplify it if you need to.

Tim
Title: Re: Fast square wave with arduino and mosfet
Post by: mikerj on September 20, 2019, 07:48:38 am
Maybe I missed something, but why is the OP trying to toggle a port pin as fast as possible through bit bashing rather than using a PWM output?
Title: Re: Fast square wave with arduino and mosfet
Post by: radiolistener on September 20, 2019, 10:20:08 am
Millihertz or megahertz?  It matters, rather a lot.

You can still connect an Arduino to something that can make 600MHz

He talking about 500-600 milliHertz (0.5 - 0.6 Hz)
Title: Re: Fast square wave with arduino and mosfet
Post by: MarkF on September 20, 2019, 04:40:58 pm
I believe you have all missed the boat here.

If you read the words around his frequency numbers
"To power it i need a really frequent square wave. 1 mhz would be nice but maybe about a 500-600 mhz minimum.",
I believe he miss typed and would like to drive his circuit with a 1 MHz square wave and would settle for a 500-600 KHz frequency.

Really frequent does not indicate milliHertz.

And 500-600 mhz is not less than 1 mhz.
Title: Re: Fast square wave with arduino and mosfet
Post by: Mechatrommer on September 20, 2019, 05:13:26 pm
frequent is a subjective term, almost useless in engineering term. one can say he bought a DSO every day (11uHz), but damn thats "frequent"
Title: Re: Fast square wave with arduino and mosfet
Post by: MarkF on September 20, 2019, 05:18:42 pm
frequent is a subjective term, almost useless in engineering term. one can say he bought a DSO every day (11uHz), but damn thats "frequent"

A little "common sense" goes a long way!
Title: Re: Fast square wave with arduino and mosfet
Post by: fourfathom on September 20, 2019, 05:45:20 pm
Assuming we are talking about a square wave in the 0.5 to 1.0 MHz region, let's look at the LC tank circuit.  I suppose the purpose is to get a clean, low-spurious output (jitter, harmonics, etc), signal.  This will look somewhat like a sinewave at the filter output.  Will this be used directly, or will it be sent to a logic stage for squaring-up?  This affects the design of the tank circuit.  In fact, if the tank load impedance is relatively low, for maximum efficiency and minimal power dissipation in the MOSFET driver, a simple LC tank may not be the best approach.  When using a square wave drive you usually want an inductive input impedance to allow the MOSFET to spend as little time as possible in the linear region.  Look at "Class E" amplifier networks, or perhaps a simple "Tee" filter.  These details will depend on the spectral purity and the power levels desired.

As for the Arduino loop, how many cycles do the bit-test and manipulation operations require?  Something like this should give you a 50% duty-cycle:

while(1){
}
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 20, 2019, 06:50:40 pm
1. I indeed ment 1MHz and kHz500-kHz600 minimum (was writing late)
2. I don't really need help with the coding bit, but thanks for the suggestions! (Although i believe you can achieve a 16MHz squarewave locked at 50% with a normal atmega328)

Unfortunately i didn't really have much time to try it out today (so the way i actually wired it might be wrong) but i'll include a picture of the dso (with a low frequency of about 490Hz) and a schematic. I think i have somewhat of an idea whats wrong, but i'd rather not say because it could extremely stupid haha. I'll try to answer some of the other questions you had individually.

PS. super impressed by the amount and quality of replies!
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 20, 2019, 06:53:51 pm
Accidentally used a 150ohm resistor, will a have to try a smaller value next time!
Quote
I expect 50 to 100 ohm will work best.
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 20, 2019, 07:01:55 pm
Quote
What are the values of your capacitor and inductor?
And what exactly do you want to accomplish?
Sorry! Can't check what the value of the cap was right now, and I don't know the inductance of the coil, that was the start of the project, to observe the resonant frequency, to calculate the inductance. And that other stuff you said was pretty interesting, I'll have to try that out if i can't get this to work.
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 20, 2019, 07:06:51 pm
Assuming we are talking about a square wave in the 0.5 to 1.0 MHz region, let's look at the LC tank circuit.  I suppose the purpose is to get a clean, low-spurious output (jitter, harmonics, etc), signal.  This will look somewhat like a sinewave at the filter output.  Will this be used directly, or will it be sent to a logic stage for squaring-up?  This affects the design of the tank circuit.  In fact, if the tank load impedance is relatively low, for maximum efficiency and minimal power dissipation in the MOSFET driver, a simple LC tank may not be the best approach.  When using a square wave drive you usually want an inductive input impedance to allow the MOSFET to spend as little time as possible in the linear region.  Look at "Class E" amplifier networks, or perhaps a simple "Tee" filter.  These details will depend on the spectral purity and the power levels desired.

As for the Arduino loop, how many cycles do the bit-test and manipulation operations require?  Something like this should give you a 50% duty-cycle:

while(1){
}

Wow I'll have to read through your reply a couple of times to understand it. But really, i'm not looking for efficiency and exactness, i just want to get in the ballpark of the right resonant frequency, to calculate the inductance of the coil.
Title: Re: Fast square wave with arduino and mosfet
Post by: fourfathom on September 20, 2019, 07:19:57 pm
Wow I'll have to read through your reply a couple of times to understand it. But really, i'm not looking for efficiency and exactness, i just want to get in the ballpark of the right resonant frequency, to calculate the inductance of the coil.

In that case most of what I said is pretty useless.  But you may still want to only lightly couple the FET to the tank circuit, otherwise the drain capacitance will effect the resonant frequency.
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 20, 2019, 07:21:48 pm
Wow I'll have to read through your reply a couple of times to understand it. But really, i'm not looking for efficiency and exactness, i just want to get in the ballpark of the right resonant frequency, to calculate the inductance of the coil.

In that case most of what I said is pretty useless.  But you may still want to only lightly couple the FET to the tank circuit, otherwise the drain capacitance will effect the resonant frequency.
Ok! What do you mean by "lightly couple the FET"?
Title: Re: Fast square wave with arduino and mosfet
Post by: ledtester on September 20, 2019, 07:28:55 pm
Can't check what the value of the cap was right now, and I don't know the inductance of the coil, that was the start of the project, to observe the resonant frequency, to calculate the inductance.

Just excite the tank with a sharp impulse and observe the frequency of the oscillations.

Here's a circuit which will excite a tank at its resonant frequency:

[attach=1]

Then just measure the frequency and from knowing the cap value you can get the inductance.

Discussion of how it works:

https://electronics.stackexchange.com/questions/282451/how-is-this-oscillator-circuit-supposed-to-work
Title: Re: Fast square wave with arduino and mosfet
Post by: MarkF on September 20, 2019, 07:56:16 pm
I made some annotations on your last circuit and have a few thoughts:

- I assume you are powering the circuit by +6V through R1.
- Remove R2 as it is not needed.
- IF YOU CONTINUE TO CONNECT YOUR SCOPE AS INDICATED, YOU WILL NOT HAVE IT LONG.
Or you will short out your circuit.  Actually, I don't see how you managed so far unless you are powering the circuit from a battery.

[attachimg=2]

- You want to connect the scope GND clip to your circuit GND.  Then probe across the MOSFET as shown.

[attachimg=1]
Title: Re: Fast square wave with arduino and mosfet
Post by: MarkF on September 20, 2019, 08:11:52 pm
A quick refresher:

Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 20, 2019, 08:38:02 pm
That's a good pointer, but the power supply and arduino that i'm using are actually mains earth isolated, or floating :)
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 20, 2019, 08:41:18 pm
Quote
I assume you are powering the circuit by +6V through R1.
Oh and this is true, forgot mark it  :)
Title: Re: Fast square wave with arduino and mosfet
Post by: fourfathom on September 21, 2019, 12:12:01 am
Ok! What do you mean by "lightly couple the FET"?

Rather than connect the FET directly to the LC tank, use (perhaps) a small capacitor between the drain and the tank -- much smaller than the tank capacitor.  You would need a resistor from drain to V+ since the tank inductor is no longer providing DC current to the FET.  You do this to reduce the de-tuning effect of the FET drain capacitance, and to reduce the heavy damping of the FET during the "on" state.

What are the values you intend for the tank inductor and capacitor?  The resonant frequency?  How will you be measuring the ringing tank signal frequency?  What kind of accuracy are you trying to get?  All these factors matter.
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 21, 2019, 12:46:38 pm
Quote
Rather than connect the FET directly to the LC tank, use (perhaps) a small capacitor between the drain and the tank -- much smaller than the tank capacitor.  You would need a resistor from drain to V+ since the tank inductor is no longer providing DC current to the FET.  You do this to reduce the de-tuning effect of the FET drain capacitance, and to reduce the heavy damping of the FET during the "on" state.

What are the values you intend for the tank inductor and capacitor?  The resonant frequency?  How will you be measuring the ringing tank signal frequency?  What kind of accuracy are you trying to get?  All these factors matter.

Can't check the values right now since i'm not in the office. I'll post an update on Monday once i get a chance to check it out. But i can say that the resonant frequency is or more or less unknown and that's the purpose of the experiment, to use the resonant frequency to calculate the inductance. I'm not really looking for accuracy, only to get in the ballpark of the right value.
Oh and i'm using a digital oscilloscope to view the experiment.
Title: Re: Fast square wave with arduino and mosfet
Post by: ledtester on September 21, 2019, 01:05:00 pm
The default circuit for the Falstad simulator shows how to excite a tank with just a switch:

The 10R - 1H - 15 uF side is your tank, the 10R representing the internal resistance of the tank.

The 100R is there to limit the current through the inductor when you hold down the switch.

Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 21, 2019, 02:23:42 pm
Quote
The default circuit for the Falstad simulator shows how to excite a tank with just a switch:

The 10R - 1H - 15 uF side is your tank, the 10R representing the internal resistance of the tank.

The 100R is there to limit the current through the inductor when you hold down the switch.

That's pretty cool!
I guess what basically i'm suggesting is to replace the button operated switch with a mosfet, and turn it off and on at just the right time to achieve stable oscillation.
Title: Re: Fast square wave with arduino and mosfet
Post by: fourfathom on September 21, 2019, 04:11:02 pm
I guess what basically i'm suggesting is to replace the button operated switch with a mosfet, and turn it off and on at just the right time to achieve stable oscillation.

That "stable oscillation" part is going to be quite tricky.  Driving the LC tank with a mosfet, 50% duty-cycle, at anywhere the natural resonant frequency of the tank will just show you the frequency of the driving squarewave.  Even lightly-coupled to the tank as I have mentioned, the frequency will be forced by the driving signal.

Your best bet may be to set the driving frequency to be much lower than the tank resonant frequency (say 10x or 100x lower), and with your scope observe the ringing that follows the "off" portion of the driving waveform.  You should initially see a high voltage transient ringing at the tank resonant frequency that decays over time.  The amplitude and duration depends on mainly the "Q" of the inductor and the speed of the mosfet cutoff.  You will still want to compensate for the mosfet drain capacitance and scope probe capacitance.  You will want a current-limiting resistor in the drain circuit, and do be careful that the transient voltage doesn't exceed the mosfet specs.
Title: Re: Fast square wave with arduino and mosfet
Post by: ledtester on September 21, 2019, 05:58:58 pm
I guess what basically i'm suggesting is to replace the button operated switch with a mosfet, and turn it off and on at just the right time to achieve stable oscillation.

If your goal is just to get a stable trace on your DSO so that you can measure the period, as fourfathom said, you only need to pulse the tank once in a while -- like once a second or perhaps once every 1/10th of a second.

If your goal is to produce a continuous signal at the resonant frequency of the tank then I would recommend the LM311 circuit I referred to above. It naturally finds the right time to inject a new impulse. This is important as to not affect the frequency of the oscillation.

You have the same situation when pushing someone on a swing set... if you push them at the bottom of the swing trajectory you will make them go higher without affecting the period and frequency of their motion. If you push them at any other point you will change the amount of time it takes to complete the next swing.

Title: Re: Fast square wave with arduino and mosfet
Post by: alsetalokin4017 on September 22, 2019, 02:43:01 am
Screenshots below show a tank circuit ringing in response to a square pulse from a mosfet, and a tank circuit excited by "scratching" the terminals of a 9v battery to produce a spiky pulse. The frequency of the inductive ringdown is easily measured in each case, and it's a good exercise in scoposcopy, especially using the single shot mode to capture the "scratch" ringdown. This frequency, along with the known capacitance or inductance, can then be used in your favourite tank circuit calculator to determine the unknown value.
http://www.1728.org/resfreq.htm (http://www.1728.org/resfreq.htm)

This video may also be of interest to the OP:

Title: Re: Fast square wave with arduino and mosfet
Post by: JustMeHere on September 22, 2019, 05:35:05 pm
BTW, why do you use i resistor in series to the gate of the mosfet, isn't mosfets voltage driven unlike bjt's?

This is to stop the mosfet pin from drawing/sinking too much current when it changes state.  It looks like a small cap when it does this.  So it behaves as a straight short for a (very) brief time.

There should also be a high value pull down between this resistor (100k to 1M) and the pin.  This will stop the pin from floating during programming and chip start up.
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 25, 2019, 01:45:53 pm
Update! 25-09-2019
Hey! I have finally had som time to work on the project!
I was able to excite the tank by using a push button like in the schematic suggested by ledtester :) That gave me a stable ish frequency that when converted comes reasonably close to the actual value. The values were 0.15 mH and 10mH and the cap was a 2.2nF ceramic capacitor. I have tried to use a mosfet in place of the P Button, but that gave me an inaccurate frequency. I tried to "lightly" couple the fet like fourfathom suggested, but i had no luck with this, could you suggest which values of coupling capacitor and resistor from drain to V+ should be used?
I included a schematic with the mosfet and the produced waveform after the push button is released.

Would it be possible to get close to the actual resonant frequency, or should i use something like a bjt or igbt instead?
Lots of thanks!
//Benji
Title: Re: Fast square wave with arduino and mosfet
Post by: fourfathom on September 25, 2019, 07:40:40 pm
Here's a very simple circuit and simulation waveform.  I'm using a 2n3904 bipolar transistor and a 10K resistor for the LC tank stimulus coupling.  Actually, with the inductor and capacitor values in your LC tank, the output capacitance of the transistor (either bipolar or mosfet) is fairly inconsequential, but the 10K resistor does serve to limit the transistor current and reduce the voltage peaks on the ringing tank circuit.  If I drop this resistor to 100 Ohms (for example), when the transistor switches off the collector voltage spikes up to 140V -- well past the collector breakdown voltage -- and then swings down negative and forward-biases the base-collector junction.  Neither of these is a good thing, and show how you need to watch the voltage spikes when dealing with an inductive load.

I have a 1KHz square wave driving the transistor, but you could go with a much narrower "on" pulse if you like.  You could replace the bipolar transistor with a mosfet if you like.

You can also insert a small diode (1n4148 or similar, cathode towards the collector) between the transistor collector and the series resistor.  This will block the reverse voltage and avoid collector-base-diode clamping.  Doing this lets you substitute a 1K resistor for the 10K to increase the stimulus current and give you a bigger tank waveform voltage to measure.

The tank voltages and duration of ringing will somewhat depend on the inductor series resistance.  I assumed a resistance of 10 Ohms in my simulations.  Lower resistance will give you a slightly bigger ringing voltage and a much longer ringing duration.  Looking at the damping on your waveform, I would guess that the inductor resistance is closer to 100 Ohm.
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 26, 2019, 01:27:42 pm
Ok i've tried the schematic you sent me, it gave a nice oscillation, but the frequency was wrong! It had a frequency of about 4.90kHz, whereas it should be closer to 33.93 kHz. Any ideas what the reason of this could be?
I was using a BC337 npn bjt transistor and a 1n5255b zener diode (which i hope is a good stand-in to the diode you were using since i didn't hava any on hand).
The voltage was still +7v and the cap and coil values are the same. The base resistor was the same you were using, 1k.

The images are respectively using the following resistors:
10k
1k
560
220
Title: Re: Fast square wave with arduino and mosfet
Post by: fourfathom on September 26, 2019, 04:25:09 pm
Ok i've tried the schematic you sent me, it gave a nice oscillation, but the frequency was wrong! It had a frequency of about 4.90kHz, whereas it should be closer to 33.93 kHz. Any ideas what the reason of this could be?
I was using a BC337 npn bjt transistor and a 1n5255b zener diode (which i hope is a good stand-in to the diode you were using since i didn't hava any on hand).
The voltage was still +7v and the cap and coil values are the same. The base resistor was the same you were using, 1k.

The images are respectively using the following resistors:
10k
1k
560
220

Are you sure about the component values?  I agree, your 10mH / 2.2nF tank should resonate around 33.9 KHz.

The frequency of the ringing tank circuit will only be affected by the values of L and C, and any stray reactance in the circuit.  The zener you used has a reasonable low capacitance when reverse-biased, and even if you removed it from the circuit the tank ringing frequency will be virtually unchanged.  Your transistor is a fine choice for this circuit (as long as the ringing voltage doesn't exceed the Vce breakdown voltage, which it doesn't).  The transistor output capacitance is about 15pF, which is trivial here given the 2.2nF tank capacitor.

I notice in your previous post you also show a 4.9 KHz tank oscillation frequency.  I suspect that your inductor is not really 10mH, or possibly the capacitor is not 2.2nF (or both).

Another interesting thing is that your ringing tank voltage is much smaller than I get in my simulation (with a 1K series resistor I get 20V P-P but you get about 3.7V P-P).  Can you measure the DC resistance of your inductor?  In my simulation I have the inductor resistance at 100 Ohms, which is pretty high for a 10mH part.

Finally, in your previous schematics you show "DSO", which I assume is your digital storage oscilloscope connected directly across the tank circuit.  Is this a differential measurement?  The top of the tank is at +7V so I hope your scope ground isn't connected there.  The fact that the tank voltage goes negative when the transistor switches off tells me that the +7V rail is your ground reference.  I don't see how this will affect the resonant frequency, but it might be simpler to measure the tank signal relative to DC ground.  There will of course be a +7V offset.

Title: Re: Fast square wave with arduino and mosfet
Post by: alsetalokin4017 on September 26, 2019, 10:58:43 pm
Here's where we would like to see photos of the components.

Sure enough the scope trace, measured by the horizontal graticule markers, agrees with the "numbers in boxes" 4.9 kHz displayed by the scope (although there is some error there due to the way the Rigol measures frequency when the screen isn't completely filled with the waveform). And sure enough your favorite tank calculator says, given the stated tank component values, that the ring frequency should be about 33.9 kHz. And as we have seen the simulation also agrees. And we believe that the schematic of the probing connection, while "unorthodox" should still yield the correct resonant frequency.

So please let's have a nice look at the components in question so we can verify their values, as that seems to be the only explanation for the discrepancy.
Title: Re: Fast square wave with arduino and mosfet
Post by: fourfathom on September 26, 2019, 11:10:15 pm
The fact that the tank voltage goes negative when the transistor switches off tells me that the +7V rail is your ground reference.  I don't see how this will affect the resonant frequency, but it might be simpler to measure the tank signal relative to DC ground.  There will of course be a +7V offset.

When I wrote the above comment I got my reference points turned upside down.  It looks like your 'scope "ground" reference is on the driven side of the tank circuit, and the probe point is on the +7V rail.  If this is a true high-impedance differential measurement this shouldn't matter.  If somehow your actual scope ground is connected to the driven side of the tank, then this could dramatically affect the oscillation amplitude and frequency.

And yes, some photos of the components might give us a better idea of what's going on.
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on September 27, 2019, 03:33:36 pm
Aaaaand apparently i'm an idiot!
Yes i had the oscilloscope hooked up in parallel to the tank circuit, exactly like in the schematic with normal 10x probe. I'm pretty new to oscilloscope's, so i'm still kinda learning where to place the probes for accurate readings. I know how to do it safely, i'm just not familiar to all the intricacies of the practice just yet. The circuit is virtually the same, this time i was using a 560ohm resistor. I included some pictures of the waveform down below, one with 10mH inductor, and one with 0.15mH. Using a resonant freq calculator gives us reasonable values of 11.105mH and 0.1332mH.
In these i had the probe ground connected to the lowest ground in the circuit and the other end connected to negative side of tank circuit.
I also included some pictures of the circuit of anyone is still curious :)

The conversation might go on, but i would like to thank fourfathom and anyone who helped me find a solution!
//Benji
Title: Re: Fast square wave with arduino and mosfet
Post by: fourfathom on September 27, 2019, 03:57:39 pm
Yes i had the oscilloscope hooked up in parallel to the tank circuit, exactly like in the schematic with normal 10x probe.

It's working!!!  Great news!

To be honest, your probing "technique" is a problem that that most of us old-timers would't have been considering when troubleshooting this circuit.  You must be using a floating (non-grounded) power supply, or (shudder) not have your 'scope grounded, because otherwise you would have short-circuited the power supply through the inductor.  Usually we clip the scope probe ground to "circuit ground".  If we want to measure a signal relative to some other voltage (directly across the tank circuit in your case) we will use two probes and subtract the signals.

Could you measure the inductor resistance for me? (might as well measure both of them.)  I'm still curious about the amplitude and "damping" differences between your circuit and my simulation.  It's probably due to resistance.

And thank you for sticking with this and reporting back.  I'm here to a large extent for the "puzzles".  My wife likes crosswords, and I like circuits!
Title: Re: Fast square wave with arduino and mosfet
Post by: ManlishPotato on October 07, 2019, 01:44:20 pm
For anyone still interested, here is the final schematic i used to achieve my goal!
I also included a picture of the final soldered project :)
Title: Re: Fast square wave with arduino and mosfet
Post by: ledtester on October 07, 2019, 07:04:50 pm
Using the ring-down method:

http://www.giangrandi.ch/electronics/ringdownq/ringdownq.shtml (http://www.giangrandi.ch/electronics/ringdownq/ringdownq.shtml)

the Q of your tank is around 19.