How to create very fast square pulses with Arduino ( up to 4 MHz with Arduino NANO, UNO, & MEGA2560

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ย. 2020
  • digitalWrite command of Arduino is very slow and with that you can only achieve 150 kHz signals (full period, ON and OFF) at best.
    In this video I show you that using port manipulation and while loop you can get up to 4 MHz signals (ON period less than OFF period) and 2.66 MHz with 50% duty cycle.
    Also you will learn how to produce multiple signals at exactly the same time. this is something which is useful if you want to make a pulse with a multilevel converter, I mean at sometimes you want to drive the switches independently to make sine wave or other waveform, but if you want make a lightning impulse with the multilevel converter, it is necessary to turn on all switches at the same time.
    At the end I summarized the results and based on this experimental work I concluded the number of clock cycles that it takes to run each command. If you see some mistake somewhere, let me know.
    The probe and scope should have sufficient bandwidth to capture the signals properly. I used the probe at 10X to increase the bandwidth. Even so steel the signal is filtered a bit.
    The following pages/videos are good references to look at:
    www.arduino.cc/en/Reference/P...
    roboticsbackend.com/arduino-f...
    • Port Register Control ...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 60

  • @Francesco-bu1hh
    @Francesco-bu1hh ปีที่แล้ว

    I am new to the Arduino ( i normally use PIC micros) and was looking for a good explanation on PWM. I have found this excellent video. Well done!

  • @anotherviewer614
    @anotherviewer614 6 หลายเดือนก่อน +1

    Highly underrated video. thank you for the info!

  • @markflint9089
    @markflint9089 ปีที่แล้ว +1

    High quality information and well presented. Thank you.

  • @sambitprakashmohanty4103
    @sambitprakashmohanty4103 2 ปีที่แล้ว

    Continue this series sir. That is amazing.

  • @superprojb
    @superprojb 2 ปีที่แล้ว

    Really great video. Thank you!

  • @Riddle-Me-This-Puzzles
    @Riddle-Me-This-Puzzles 3 ปีที่แล้ว

    WOW! Well done!

  • @mosquid
    @mosquid ปีที่แล้ว

    This is crazy. Much much appreciated

  • @martinryser5439
    @martinryser5439 ปีที่แล้ว

    Thank you so much! This is very helpful also for my projekt.

  • @protorbs_nft_clubofficial141
    @protorbs_nft_clubofficial141 3 ปีที่แล้ว

    you are doing a great job

  • @BaudirenergieDe
    @BaudirenergieDe 2 ปีที่แล้ว

    Great Tutorial!!! Thanks a lot.

  • @rockryu83
    @rockryu83 2 ปีที่แล้ว +7

    Very useful ,Thank you...
    How to change frequency? (10kHZ- 20Khz - 40khz) to achieve frequency adjustment?

  • @mantookaibarta3073
    @mantookaibarta3073 2 ปีที่แล้ว +1

    Nice Explanation, very informative. I am interested in how to use ASM code in C, Please refer some tutorials and books. Thank you.

  • @RHV2601TW
    @RHV2601TW 2 ปีที่แล้ว

    Great help man, thx!

  • @dr.kaganayanoglu2656
    @dr.kaganayanoglu2656 2 ปีที่แล้ว

    great job, thanks a lot

  • @diptanshumalviya7547
    @diptanshumalviya7547 3 ปีที่แล้ว

    Thank you, sir, for making such an information video, Please Sir, Continue the series of Arduino Video. Please Please Sir, Make such Video like that. I love your channel. make more video sir.

  • @moinshaikh6684
    @moinshaikh6684 ปีที่แล้ว

    Jabraad be bhaiwa!

  • @charithajayasooriya4899
    @charithajayasooriya4899 ปีที่แล้ว

    thank you soo much you explain it so so good

  • @wernerpeter9706
    @wernerpeter9706 7 หลายเดือนก่อน

    When you work with Timer/Counter and Output Compare Register you have less code, full control of PWM times and faster frequency. The best part is, that the Arduino processes this internally and can continue to execute any other code. Inverted outputs and even dead times between PWM signals are also programmable without blocking the MC.

  • @hosseinashkboos5188
    @hosseinashkboos5188 2 ปีที่แล้ว

    Very Good thank you.

  • @taiwosanyaolu8276
    @taiwosanyaolu8276 2 ปีที่แล้ว

    Thank you.. Please can you help with the oscilloscope setup? Thanks.

  • @darkstatehk
    @darkstatehk 2 ปีที่แล้ว

    Is it possible to poll an input pin using the same primordial code, at higher frequencies?

  • @jack91522
    @jack91522 ปีที่แล้ว

    Bit banging really depends on the rest of the code and will make if difficult to control your duty cycle

  • @josesosa7796
    @josesosa7796 2 ปีที่แล้ว

    Thanks

  • @georgeklitsiotis1517
    @georgeklitsiotis1517 2 ปีที่แล้ว

    I am working on a project that needs to push even faster. For that reason I am using an ARM powered arduino due. Should I use the same commands or are the ports different for the DUE (Cheers by the way. Nice tutorial)

    • @HVE
      @HVE  2 ปีที่แล้ว

      DUE needs completely different commands, the chip is different.

    • @adelamrouche3842
      @adelamrouche3842 2 ปีที่แล้ว

      @@HVE
      I am working on a project that needs to send 3 ID over 3 carriers frequencies via 3 LED
      These code is it useful for my project
      Thank you.nice tutorial

  • @icarossavvides2641
    @icarossavvides2641 หลายเดือนก่อน

    I think if the XOR operation is implemented a higher toggling frequency could be attained?

  • @FalconSmart
    @FalconSmart ปีที่แล้ว

    Do you know how to generate a same frequency PWM pulse with an external trigger using Arduino Uno? So basically want to realize a digital delay generator. For example, I have a sync signal of 120Hz, and I hope to use this feed into the Arduino, then I can change the delay (0.1ms - 5ms range), and then output a 120Hz, 50% duty cycle signal. Thank you.

  • @jamespohlmann3246
    @jamespohlmann3246 ปีที่แล้ว +1

    Wonderful and very helpful video! One thing that doesn't make sense to me: why is the high value only ~600mV? I replicated this on my Arduino Mega and had a dV of 576mV. I would have expected the high value to be 3.3V or 5V depending on the board. Thank you!

    • @HVE
      @HVE  ปีที่แล้ว

      I used a 1:10 ratio probe in my measurements

  • @alexlo7708
    @alexlo7708 11 หลายเดือนก่อน

    I wonder now what will happen if we do the same to uno r4.

  • @Impulsetech36
    @Impulsetech36 4 หลายเดือนก่อน

    is it same port number for Uno R4 minima as the one you show for uno?

  • @aminkadi-haja569
    @aminkadi-haja569 4 หลายเดือนก่อน

    For a project of mine, i need to create high frequency soundwaves through a transducer. My main problem is that I dont have any idea how to accurate supply my transducer with these high frequency signals and still know what frequency I am providing to it. Basically I want to supply frequency range from 1.6MHz to 2.5MHz in steps of 0.1MHz. Is there any way to know beforehand what kind of frequency I am supplying?
    I can get to 4.05MHz(Max) and I want to accurately delay this to the range of 1.6MHz to 2.5MHz, how to do that?

  • @roshankhanal9364
    @roshankhanal9364 2 ปีที่แล้ว

    can i get 1mhz signal using arduino uno. what is the procedure?

  • @Buciasda33
    @Buciasda33 2 ปีที่แล้ว

    Thank you, very useful.
    Can you show us Fast PWM? (More than 65kHz)
    I can't figure out the prescalers and pins assigned

    • @HVE
      @HVE  2 ปีที่แล้ว +1

      I will give it a try and when it is ready will make a video about it. do you want to make a sine wave after PWM filtering or you mean something else ?

    • @Buciasda33
      @Buciasda33 2 ปีที่แล้ว

      @@HVE
      Thanks, I think I have tried everything, but give it a shot anyway.
      No need for sine wave.
      If you can get 125kHz or 250kHz PWM on the 328p it would be amazing.
      So far, I have succeeded, up to 4MHz output without PWM, on pin 8, the Following:
      DDRB = B11111110; // I think this puts pin 8 as output, but double check, it might have all the bits flipped.
      void loop() {
      while(true) { // faster than void loop() from what I've heard, but I'll double check.
      // Port Manipulation:
      PORTB = B00000001;
      PORTB = B00000000;
      }
      }
      Then add or remove delays with the following:
      __asm__("nup
      \t");
      You can add or remove those NOP operations to get close to what you want, but they will affect both frequency and duty cycle.
      I'm still trying to mix and match frequencies and duty cycles, but it's a mess.
      I'll probably have to rely on internal timers and comparators instead of throwing NOP's at the problem.

    • @roshankhanal9364
      @roshankhanal9364 2 ปีที่แล้ว

      @@HVE can i get 1mhz signal using arduino uno. what is the procedure?

  • @dr.kaganayanoglu2656
    @dr.kaganayanoglu2656 2 ปีที่แล้ว

    How should I think to set the dutycycle? How much will this frequency change with another command?

    • @HVE
      @HVE  2 ปีที่แล้ว

      Depending on the code you have, you should see how many commands you used in your code and where there are placed. in general to get high frequency you do not want to add many instruction in your code. the duty cycle can easily be set based on the on/of time of the time of the output pin.

  • @mipa3868
    @mipa3868 ปีที่แล้ว

    what are you using to view thw waveform?

  • @thabangcoleen3739
    @thabangcoleen3739 2 ปีที่แล้ว

    How to achieve a 100KHz with 0.44 cycle?

  • @sarwarn2107
    @sarwarn2107 ปีที่แล้ว

    Is this port manipulation possible with Blue Pill STM32?

  • @bossrx4067
    @bossrx4067 6 หลายเดือนก่อน

    What is the name of the program used to display the signal?

  • @HS-hz4fx
    @HS-hz4fx ปีที่แล้ว

    is it possible to delay in nano second

  • @cargames4885
    @cargames4885 2 ปีที่แล้ว +1

    in which software you done the oscilloscope simulation

    • @HVE
      @HVE  2 ปีที่แล้ว

      It is the software of the oscilloscope. It is not a simulation, there is a real scope and this software is the interface to see the data.

  • @georgealbo
    @georgealbo 2 ปีที่แล้ว

    can i reach 5 MHz frequency and use it to control Mosfet to driver load 12v 1 A thanks

    • @HVE
      @HVE  2 ปีที่แล้ว

      Which type of mosfet do you want to drive ? Arduino can not supply much current, so you must use a proper gate driver most likely. And anyway 5 Mhz with Arduino nano you probably will not be able to achieve. Maybe try Arduino DUE, but that requires different coding to achieve high speed.

  • @nin1ten1do
    @nin1ten1do 2 ปีที่แล้ว

    can i get sample code for 1MHZ 2 signals 180¨ Phase shift and duty 50%,49%,48%,47%?

    • @HVE
      @HVE  2 ปีที่แล้ว +1

      For 50% duty cycle it is possible but for the other numbers at 1Mhz, you need a faster processor. To write the code you can watch the video again from 15:30.
      probably you need something like this (I have not tested it):
      void setup() {
      DDRD=B00001100;
      }
      void loop() {
      while(true){
      __asm__("nop
      \t""nop
      \t""nop
      \t""nop
      \t""nop
      \t");
      PORTD = B00000100;
      __asm__("nop
      \t""nop
      \t");
      __asm__("nop
      \t""nop
      \t""nop
      \t""nop
      \t""nop
      \t");
      PORTD = B00001000;
      }
      }
      ----------------------------------------
      PORTD = B00001000 --> 1 cycle
      while loop: 2 cylces
      5 cycle delay
      ---------------------
      PORTD = B00000100 ---> 1 cycle
      2 cycles delay
      5 cycles delay
      in total 16 cycle each, which gives you a 1 Mhz frequency.

  • @georgealbo
    @georgealbo 2 ปีที่แล้ว

    iam asking about this oscilloscope how you connected to arduino

    • @HVE
      @HVE  2 ปีที่แล้ว

      Scope has a probe and you can connect the probe to Arduino pins

  • @user-wf9zj1pn1w
    @user-wf9zj1pn1w 2 ปีที่แล้ว

    What is the name of program you used it for osillscope

    • @HVE
      @HVE  2 ปีที่แล้ว +1

      It is Hantek6022BE, you need to have this digital scope, connect it with usb cable to your computer, install its program on your computer, and then you will be able to see the waveforms on in that software

  • @ravirao5798
    @ravirao5798 2 ปีที่แล้ว

    Hi,
    Gr8 Video.
    Pl Can you share the Simillar Video For DUE ...
    Thanks in Advance

  • @warrior7740
    @warrior7740 5 หลายเดือนก่อน

    yes, it’s very fast and use low memory space

  • @the-beneficiary1809
    @the-beneficiary1809 ปีที่แล้ว

    Hi Sir great video very information, Would you be so kind as to let me know what software you are using for the simulation you are displaying?

    • @HVE
      @HVE  ปีที่แล้ว +1

      Thanks, this is the software of the digital oscilloscope that i have. What is demonstrated is not a simulation, it is an actual measurement.

  • @andracarotta3351
    @andracarotta3351 3 ปีที่แล้ว

    great job, thanks a lot