Arduino Due Simple Function Generator Example

Поделиться
HTML-код
  • Опубликовано: 5 янв 2018
  • First project with Arduino Due: Simple function/waveform generator from the Arduino website.
    Generates Sine, Triangle, Sawtooth and Square waves from 1 Hz to 170 Hz and beyond.
    Obviously not the best "function generator" but helps get a basic understanding of the concepts.
    Sketch duplicated here (original site tutorial seems to be gone in 2021)
    github.com/GadgetReboot/DueSi...
    Patreon: / gadgetreboot
  • НаукаНаука

Комментарии • 46

  • @electronicsideas1361
    @electronicsideas1361 Год назад +2

    exit status 1
    'analogWriteResolution' was not declared in this scope

  • @bhavaprasad4807
    @bhavaprasad4807 4 года назад +2

    I got the all waves but i want to aquire the data from Anolog pins (only sinewave). is it possible?? thank you

  • @shakeelahmed8284
    @shakeelahmed8284 4 года назад

    yesterday I did this one over my due board it was fine and was changing its waveforms but when i connected it to the oscilloscope for verification then it was not providing a significant change in frequency. the frequency was varying between 800mHZ to 1-79HZ. can you please help me to sort out this problem?

  • @owenchang4833
    @owenchang4833 4 года назад

    Hi, can i change the frequency without potentiometer?
    I want to control my output frequency by code, for example: every 10 seconds the frequency will +1khz.
    Thanks for your sharing

  • @sachindas5834
    @sachindas5834 5 лет назад

    Byte error is occur when uploading the code what is the solution???

  • @damainx
    @damainx 5 лет назад

    I made this, but, cannot get a 'sine' wave out of it. Saw, box, others ok, but no sine. Also, I think there's an error in the code on the Arduino page; sample = constrain(t_sample, 0, oneHzSample);

  • @marcarguilles5222
    @marcarguilles5222 7 месяцев назад

    Can i use Arduino uno for this

  • @EricBalcon
    @EricBalcon 4 года назад +1

    Hello, thanks for your tutorial, this is interesting. I was wondering since the Due works with Dacs if it was possible to simply work a sin(x) function to create a sin wave instead of working with a table of parameters ?

    • @pablopugaperez6214
      @pablopugaperez6214 4 года назад

      Actually a pretty good question. It´s possible but probably you´re going to need to add more stuff (another pot) and solve the part of math (for all the waves). But for a sine wave you could use maybe 2 pots one for the amplitude and the other one for the frequency. But you will have to map the reading values of both of them. So the formula we are going to use is A*sin(B) where A is the value of the first pot and the responsable value for the amplitude of the wave, and then the part B corresponds to the second pot and the one in charge of the frequency, this one is a litlle more complicate cause the way that math works. So for B we are going to need a "lenght" value, I mean, the map values range of this pot could be betwen 0.01 and 0.001 (that´s our "lenght"). So the only left is making the itteration for B. Hope it helps, it´s just the first thing that comes to my mind. I would like to be more explicit but english is no my first language so...

    • @believeornot12
      @believeornot12 3 года назад

      It should work but your max frequency will be lower because of all of the calculation. For each sample, you need to do sine of x. Table lookup is much faster.

  • @uniqueinfo1866
    @uniqueinfo1866 4 года назад

    Does it work with Arduino Uno?

  • @iulencabeza6454
    @iulencabeza6454 Год назад

    What is the offset? 1.65 V?

  • @laalaiwafa5194
    @laalaiwafa5194 3 года назад

    can you give me library of arduino Due :proteus

  • @believeornot12
    @believeornot12 3 года назад

    There is a fundamental design (perhaps implementation) flaw. taking the analog read on the sample time in loop() won't yield a consistent value. The number will jump up and down by a couple of digit.

  • @taoxu7920
    @taoxu7920 6 лет назад

    hi , do you think it can speed up the frequency to 15KHZ?

    • @GadgetReboot
      @GadgetReboot  6 лет назад +1

      From what I remember the maximum frequency I saw at the time was the best they could do probably because of the processor clock rate and the number of samples in the waveform and the time it took to send them out to the DAC but I’m not sure if there’s room for improvement in the algorithm. I would like to think there’s a way to speed it up so maybe a future project idea when I get some free time.

  • @sudipkong1120
    @sudipkong1120 5 лет назад +1

    thanks alot

  • @faisaltanoli3955
    @faisaltanoli3955 5 лет назад +1

    Why 12bit (4096) levels ? can we increase?

    • @GadgetReboot
      @GadgetReboot  5 лет назад

      That’s the limit for the hardware resolution. We could increase it by using a different DAC and generating a larger waveform table to take it advantage of it.

  • @randyfernandez7282
    @randyfernandez7282 5 лет назад +2

    how high the voltage can be tuned?

    • @GadgetReboot
      @GadgetReboot  5 лет назад +1

      There is an offset from both ground and upper rails so the output is about 0.5 to 2.7 V. It can be scaled using an op amp like this
      ardupiclab.blogspot.com/2015/07/how-to-modify-analog-output-range-of.html

    • @randyfernandez7282
      @randyfernandez7282 5 лет назад +2

      Thank you sir, one more thing..will it be more efficient (in term of the output) if I use external DAC chip..I couldnt find any source for this or am I missing something..hmmm

    • @GadgetReboot
      @GadgetReboot  5 лет назад

      schianorobotics.altervista.org/Arduino_DUE___DAC_MCP4922.pdf
      That document shows one external SPI controlled DAC that’s available in 12 bit like the built-in one and the output can go closer to 5 V although it may be a little expensive.
      Since it doesn’t have any extra components that will introduce errors like an op amp, it may give a more accurate output but I’m not sure if the maximum frequency would be about the same as the internal or slightly slower due to the overhead of interfacing.
      So depending what’s more important between cost or maximum frequency or output voltage swing with minimal offset, maybe this would work better than scaling the built-in one with a bunch of components.
      I ordered a different part with I think only 10 bits but it’s SPI so when I get that I will be checking what kind of frequency I can get out of it.

    • @randyfernandez7282
      @randyfernandez7282 5 лет назад

      @@GadgetReboot hello sir, i have a problem in compiling..i tried to do it from scratch since the get code link are broken..how exactly i can get waveforms.h ? i am not sure whether i am doing it right or not because i am new to adruino..do i need to compile both set of codes and save it in one folder or something?

    • @GadgetReboot
      @GadgetReboot  5 лет назад +1

      It's been a while since I did it so I quickly loaded mine and it compiled, so I started over with a new test folder and copying the code manually from the page, and found one problem at least from the web code.
      In FunctionGenerator.ino, in the loop there was a compile error saying something about t_sample, so I changed it to just "sample" like this:
      change from: sample = constrain(t_sample, 0, oneHzSample);
      to: sample = constrain(sample, 0, oneHzSample);
      Other than that, I manually copied and pasted the code text from the web page tutorial into new files within the Arduino IDE and then saved them by the same names as the tutorial, and in the same folder.
      For waveforms.h I had to go into the folder after saving it from Arduino IDE so I could rename it properly and copy it out of the sub folder that the IDE stored it in as an INO file. Tedious but in the end using the IDE as my text editor was the safest because using a normal text editor sometimes won't work - there may be hidden extra character codes that mess it up when compiling.
      So both files go in the same folder, then you open FunctionGenerator.ino and compile just that (with the correct arduino board target chosen of course for the project hardware).
      When the FunctionGenerator project is loaded It should also have a tab that auto-loaded waveforms.h since it was a listed include file in the main sketch anyway.

  • @yazanhassan9350
    @yazanhassan9350 5 лет назад

    i can increase the voltage up 2.3v ???????????????????????????????pleas answer me quickly

    • @GadgetReboot
      @GadgetReboot  5 лет назад +2

      The peak output voltage on this chip was 2.8 V so to get it larger would require some sort of external circuit like an op amp.

    • @yazanhassan9350
      @yazanhassan9350 5 лет назад

      @@GadgetReboot thank you

  • @PyccoloSantos
    @PyccoloSantos Год назад

    Oi, nice video bro, but I am getting the error 'analogWriteResolution' was not declared in this scope
    ', can you pls help, thank you so much.

    • @GadgetReboot
      @GadgetReboot  Год назад +1

      The first thing to confirm is make sure the Due board is chosen in the IDE before compiling because that command is only available on certain boards so it gives the error if the wrong board is targeted. Otherwise I think that project is 4 or 5 years old so I'm not sure if anything got broken in the IDE support for it over the years.
      I just tried compiling in IDE 1.8.13 and it was successful, using Arduino Due as the board, and the board file installed to support Due is Arduino SAM Boards (32-bits ARM Cortex-M3) version 1.6.11

    • @PyccoloSantos
      @PyccoloSantos Год назад

      @@GadgetReboot Tnx for the reply, I gonna try again soom, ty once again.

  • @dode08541twety
    @dode08541twety 5 лет назад +1

    do you think I can do it with UNO??

    • @GadgetReboot
      @GadgetReboot  5 лет назад +2

      UNO runs a lot slower, has less memory to store waveform samples, and doesn’t have a built in DAC. But I wonder what is possible still even adding an external DAC. Maybe I will try that and do a video on it.

    • @GadgetReboot
      @GadgetReboot  5 лет назад +2

      I have tested an external I2C DAC with Uno and it ran very slow so that’s not practical, I’m not sure how much better an SPI DAC might perform. Maybe another future thing I can investigate.
      ruclips.net/video/tLsg6vYcRXA/видео.html

  • @ashokpandys9676
    @ashokpandys9676 2 года назад +1

    Nice

  • @vonniecorrigan2040
    @vonniecorrigan2040 2 года назад

    Every the ad says it is!

  • @Massimiliano69
    @Massimiliano69 4 года назад

    the original code is wrong:
    sample = map(analogRead(A0), 0, 4095, 0, oneHzSample);
    sample = constrain(t_sample, 0, oneHzSample);
    the correct one is:
    ....
    int sample, t_sample;
    ....
    t_sample = map(analogRead(A0), 0, 4095, 0, oneHzSample);
    sample = constrain(t_sample, 0, oneHzSample);

    • @juancarlos1549
      @juancarlos1549 Год назад

      Don't work too.... the problem with this code always is the same thing
      'analogWriteResolution' was not declared in this scope
      '

  • @gabrielespadero7790
    @gabrielespadero7790 5 лет назад +1

    Can i also do it in Mega2560?

    • @GadgetReboot
      @GadgetReboot  5 лет назад +1

      I don’t have a mega but looking up the specs, it only runs at 16 MHz compared to around 84 MHz on Due, and that’s going to be the big limiting factor on how fast of a frequency can be generated by cycling through the look up table to generate the waveform as fast as possible.
      I also did not see any digital outputs listed in the specification so an external DAC would have to be used. I tested an I2C DAC on Uno and it was very slow so an SPI May work better. If that works on Uno at a high enough output waveform frequency, that should also work on mega.
      ruclips.net/video/tLsg6vYcRXA/видео.html

    • @gabrielespadero7790
      @gabrielespadero7790 5 лет назад

      @@GadgetReboot okay thanks..how did you compile the codes from the site? I also have the codes from the site but i didnt know how to compile it. I have some problems with it

    • @GadgetReboot
      @GadgetReboot  5 лет назад

      They give the source code as highlighted text for two required files on that project page so I clicked to get the code at the bottom of each highlighted code area, and it opened each up in it’s own new window, then I highlighted the text and put it into a text editor and saved it as each required file name
      FunctionGenerator.ino
      Waveforms.h
      I saved them both in the same Arduino project folder called FunctionGenerator (folder name has to match the INO name), then I made sure I chose Due as the board I’m using and it compiled.

  • @a3qn
    @a3qn 3 года назад +1

    looks like project has been deleted from Arduino website.

    • @GadgetReboot
      @GadgetReboot  3 года назад +1

      I put the sketch on github for reference github.com/GadgetReboot/DueSimpleFunctionGenerator
      Haven't tested it but it must have been left in working condition the last time it was used.
      I'm working on a better Due function generator now actually for creating audio synth projects and it can produce more realistically useful frequencies than this one. It will be uploaded hopefully this month.