element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
NanoRama
  • Challenges & Projects
  • Project14
  • NanoRama
  • More
  • Cancel
NanoRama
Blog Nano function generator - Ep.1
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join NanoRama to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: amgalbu
  • Date Created: 3 May 2020 8:24 AM Date Created
  • Views 1839 views
  • Likes 6 likes
  • Comments 2 comments
  • nanoramach
Related
Recommended

Nano function generator - Ep.1

amgalbu
amgalbu
3 May 2020
image

NanoRama

Enter Your Project for a chance to win a Nano Grand Prize bundle for the most innovative use of Arduino plus a $400 shopping cart!

Submit an EntrySubmit an Entry  Back to homepage image
Project14 Home
Monthly Themes
Monthly Theme Poll

 

I think Nanorama initiative is a great idea, so I would really love to contribute, so this is a project I started to work on.

Unfortunately, because of lockdown, I don’t have full access to my laboratory, but nothing can stop a maker (well, except may be the maker’s wife, but that’s another matter), thus I can not test on a real board: I will provide more details as soon as restrictions will fade

From time to time, while debugging embedded software, I need to run the same sequence of digital inputs. For example, if you have an issue when a particular sequence of events occurs, or when a certain sequence of buttons is pressed by the user. So, why not build a programmable function generator?

I want to do something lean-and-mean, because it’s something I will use just few times. I do not want to connect a display, make up all the menus with the buttons to navigate, etcetera.

Do you remember the old good piece of hardware like this one?

image

where the only interface was a serial connection and menus were built using VT100 escape sequences?

Well, I want to build an interface like that: I will configure the function generator by means of a VT100 terminal interface

Luckily, there is a library that wraps VT100 escape sequences into a set of handy functions. This is the starting point to build a menu-based UI

image

Since I have some time to spend on this project, my function generator will implement the following functions

  1. Sine wave
  2. Square wave (PWM)
  3. Triangle wave
  4. Sawtooth wave
  5. User-defined

I have a spare Arduino Nano, so this will be the target board for this project. After all, I think it is a good choice because it is small in size and the same board is shipped in 3.3V and 5V version. This means I can use the same firmware to generate signal with different amplitudes

The Arduino Nano, however, does not have a DAC converter, so the analog waveforms must be generated by means of a PWM and a low-pass filter.

As a quick reminder, the dc value, given the on and off time, can be calculated using the following formula

image

You can find a great explanation at this link

https://create.arduino.cc/projecthub/Arduino_Scuola/build-a-simple-dac-for-your-arduino-4c00bd

 

The PWM frequency on Arduino Nano is 480 Hz (or 960 Hz on pin 5 and 6). So we need to design a low pass filter that cuts well below this frequency (let’s say about 10 Hz – this means that the max frequency of a sin wave we can generate should be less than about 2 Hz in order not to attenuate the signal)

I am going to use a passive filter, because I expect to have loads that takes less than 10mA. So the circuit for the low-pass filter is very simple:

image

The cut-off frequency is given by the formula

image

With R = 6,8 kOhm and C = 2.2 uF, the cut-off frequency is 10,64 Hz, which is good

 

Back to the code, the analog waveforms are generated using lookup tables generated using this site

https://www.daycounter.com/Calculators/

 

Each table has 128 samples. Every main cycle, I perform the following code

image

I should evaluate whether to use a linear interpolation between two table’s point to get a better accuracy

For the user-defined functions, we can enter a sequence of high and low and the duration of each step

 

The source (still work in progress) is available on github

https://github.com/sataur-code/nano-function-generator

  • Sign in to reply

Top Comments

  • amgalbu
    amgalbu over 5 years ago in reply to dubbie +1
    Thank you Dubbie Dubbie! I will try to complete this project as soon as possible! Bye
  • amgalbu
    amgalbu over 5 years ago in reply to dubbie

    Thank you Dubbie Dubbie!

    I will try to complete this project as soon as possible!

     

    Bye

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dubbie
    dubbie over 5 years ago

    Sa Taur,

     

    This is something that I have often thought of making, as it just seems so useful, but I have never been motivated enough to actually do anything about making one. I am looking forward to seeing your solution as I may then want to make one as well. I too like text based user interfaces as I started my programming with Turbo Pascal and Turbo C where text based menu systems were 'the thing'.

     

    Dubbie

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube