Author Topic: Fast square wave with arduino and mosfet  (Read 1305 times)

0 Members and 1 Guest are viewing this topic.

Offline ManlishPotato

  • Contributor
  • Posts: 26
  • Country: se
Fast square wave with arduino and mosfet
« 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?
Thanks in advance
//Benji
https://imgur.com/a/JjfIlp2
« Last Edit: September 19, 2019, 07:46:43 pm by ManlishPotato »
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 1393
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #1 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.

« Last Edit: September 19, 2019, 09:13:40 pm by MarkF »
 

Offline ManlishPotato

  • Contributor
  • Posts: 26
  • Country: se
Re: Fast square wave with arduino and mosfet
« Reply #2 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.
 

Offline ManlishPotato

  • Contributor
  • Posts: 26
  • Country: se
Re: Fast square wave with arduino and mosfet
« Reply #3 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?
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 1393
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #4 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.)



- 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.

« Last Edit: September 19, 2019, 08:55:22 pm by MarkF »
 
The following users thanked this post: ManlishPotato

Offline ManlishPotato

  • Contributor
  • Posts: 26
  • Country: se
Re: Fast square wave with arduino and mosfet
« Reply #5 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! 
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 1393
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #6 on: September 19, 2019, 09:15:48 pm »
Start with a series resistor of 100 Ω.
I expect 50 to 100 ohm will work best.
 

Offline djacobow

  • Super Contributor
  • ***
  • Posts: 1050
  • Country: us
  • takin' it apart since the 70's
Re: Fast square wave with arduino and mosfet
« Reply #7 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.
 
The following users thanked this post: ManlishPotato

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 1393
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #8 on: September 20, 2019, 01:54:47 am »
A quick Google search yielded:
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)
 

Offline ledtester

  • Frequent Contributor
  • **
  • Posts: 535
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #9 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



 

Offline ledtester

  • Frequent Contributor
  • **
  • Posts: 535
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #10 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

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.
 
The following users thanked this post: ManlishPotato

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 9146
  • Country: my
  • reassessing directives...
Re: Fast square wave with arduino and mosfet
« Reply #11 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...
if something can select, how cant it be intelligent? if something is intelligent, how cant it exist?
 

Offline ledtester

  • Frequent Contributor
  • **
  • Posts: 535
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #12 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.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 13954
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Fast square wave with arduino and mosfet
« Reply #13 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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 
The following users thanked this post: ManlishPotato

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 2155
  • Country: gb
Re: Fast square wave with arduino and mosfet
« Reply #14 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?
 

Offline radiolistener

  • Frequent Contributor
  • **
  • Posts: 928
  • Country: ua
Re: Fast square wave with arduino and mosfet
« Reply #15 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)
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 1393
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #16 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.
 
The following users thanked this post: ManlishPotato

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 9146
  • Country: my
  • reassessing directives...
Re: Fast square wave with arduino and mosfet
« Reply #17 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"
if something can select, how cant it be intelligent? if something is intelligent, how cant it exist?
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 1393
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #18 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!
 

Offline fourfathom

  • Regular Contributor
  • *
  • Posts: 235
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #19 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){
  digitalWrite(OUTPIN, !digitalRead(OUTPIN);
  }
 
The following users thanked this post: ManlishPotato

Offline ManlishPotato

  • Contributor
  • Posts: 26
  • Country: se
Re: Fast square wave with arduino and mosfet
« Reply #20 on: September 20, 2019, 06:50:40 pm »
Sorry for the radio silence!
To answer you questions:
 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!
 

Offline ManlishPotato

  • Contributor
  • Posts: 26
  • Country: se
Re: Fast square wave with arduino and mosfet
« Reply #21 on: September 20, 2019, 06:53:51 pm »
Accidentally used a 150ohm resistor, will a have to try a smaller value next time!
Quote
Start with a series resistor of 100 Ω.
I expect 50 to 100 ohm will work best.
 

Offline ManlishPotato

  • Contributor
  • Posts: 26
  • Country: se
Re: Fast square wave with arduino and mosfet
« Reply #22 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.
 

Offline ManlishPotato

  • Contributor
  • Posts: 26
  • Country: se
Re: Fast square wave with arduino and mosfet
« Reply #23 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){
  digitalWrite(OUTPIN, !digitalRead(OUTPIN);
  }

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.
 

Offline fourfathom

  • Regular Contributor
  • *
  • Posts: 235
  • Country: us
Re: Fast square wave with arduino and mosfet
« Reply #24 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf