{"id":1219,"date":"2024-06-24T14:22:12","date_gmt":"2024-06-24T14:22:12","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=1219"},"modified":"2024-08-11T15:14:17","modified_gmt":"2024-08-11T15:14:17","slug":"waveform-generation","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=1219","title":{"rendered":"Waveform Generation"},"content":{"rendered":"<p>We previously learn about flash memory and how to program it. In this article we build a waveform generator. In that we uses four different switches to generate four different waveform i.e. Saw tooth, square, triangular and sinusoidal. We can get the desire analog signal from the Atmel AVR digital output with the help of DAC (Digital to analog converter).<\/p>\n<p>If we develop at the outputs of the microcontroller an appropriate resistance network have the possibility of developing by the control of the outputs over the resistance an adder with whose assistance, we can produce a proportional tension for the numerical values. Let\u2019s look at the 8bit DAC Ladder circuit bellow-<\/p>\n<style>\/*! elementor - v3.22.0 - 17-06-2024 *\/<br \/>\n.elementor-widget-image{text-align:center}.elementor-widget-image a{display:inline-block}.elementor-widget-image a img[src$=\".svg\"]{width:48px}.elementor-widget-image img{vertical-align:middle;display:inline-block}<\/style>\n<p>\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"1383\" height=\"447\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8bit-ladder.jpg\" alt=\"\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8bit-ladder.jpg 1383w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8bit-ladder-300x97.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8bit-ladder-1024x331.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8bit-ladder-768x248.jpg 768w\" sizes=\"(max-width: 1383px) 100vw, 1383px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t<\/p>\n<p>Here the output value is-<img decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/8bit-ladder-output.jpg\" alt=\"\" width=\"1369\" height=\"55\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/c-structure-1.jpg\" alt=\"\" width=\"200\" height=\"37\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/math-function-of-C.jpg\" alt=\"\" width=\"1331\" height=\"580\" \/><\/p>\n<p>A sinusoidal signal can be define as \u2013<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/float.jpg\" alt=\"\" width=\"16\" height=\"16\" \/>sin(X) = Amplitude x sin(2\u1d28\u0192 + \u0424) = Asin(2\u1d28\u0192 + \u0424)<\/p>\n<p>Assume,<\/p>\n<p>A = Amplitude = 1<\/p>\n<p>\u0192 = frequency = 1Hz<\/p>\n<p>\u0424 = Angle = \u00a0<\/p>\n<p>Sample Sinusoidal wave into 8bit, n=8<\/p>\n<p>\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"349\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/sin-wave.jpg\" alt=\"\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/sin-wave.jpg 840w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/sin-wave-300x125.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/sin-wave-768x319.jpg 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t<\/p>\n<p>Since the output vary from 0V to 5V.<\/p>\n<p>DC offset voltage = 2.5V.<\/p>\n<p>So sinusoidal wave output is<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/basic-step-2.jpg\" alt=\"\" width=\"1413\" height=\"238\" \/><\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;avr\/io.h&gt;\n#include&lt;util\/delay.h&gt;\n#include&lt;math.h&gt;\n#define PI          3.14159265\n#define AMPLITUDE   2.5\n#define FREQUENCY   1.0\n#define DURATION    1.0\n#define SAMPLE_RATE 256\n#define VREF        5.0\n#define MAX_VALUE   255\nuint8_t sin_value&#x5B;256];     \/\/sinewave sample 255 times\nuint8_t wave_out;\nint main(void)\n{\nDDRD = 0xFF; \/\/Define for output\nint num_samples=(int)(DURATION*SAMPLE_RATE);\ndouble time_step=DURATION\/num_samples;\nfor(int i=0;i&lt;num_samples;i++)\n{\n\tdouble time=i*time_step;\n\tdouble sin_wave=2.5+AMPLITUDE*sin(2.0*PI*FREQUENCY*time);\n\tsin_value&#x5B;i]=(uint8_t)((sin_wave\/VREF)*MAX_VALUE);\n}\nwhile(1)\n{\n\tfor(uint8_t i=0;i&lt;256;i++)\n\t{\n\n\t\tPORTD=sin_value&#x5B;i];\n\t\t_delay_us(78);\n\t}\n}\nreturn 0;\n}\n<\/pre><\/div>\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Invertersine-wave-genator.rar\" style=\"border-radius:10px;padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-upper-heading-font-size wp-block-paragraph\"><strong><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Invertersine-wave-genator.rar\">Inverter(sine wave genator).rar<\/a><\/strong><\/p>\n<\/div>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Here the variable sin_value[i] has a value-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nsin_value&#x5B;256]= \n{\n0x80,0x83,0x86,0x89,0x8c,0x8f,0x92,0x95,0x98,0x9c,0x9f,0xa2,0xa5,0xa8,0xab,0xae,\n0xb0,0xb3,0xb6,0xb9,0xbc,0xbf,0xc1,0xc4,0xc7,0xc9,0xcc,0xce,0xd1,0xd3,0xd5,0xd8,\n0xda,0xdc,0xde,0xe0,0xe2,0xe4,0xe6,0xe8,0xea,0xec,0xed,0xef,0xf0,0xf2,0xf3,0xf5,\n0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfc,0xfd,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,\n0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfd,0xfc,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,\n0xf6,0xf5,0xf3,0xf2,0xf0,0xef,0xed,0xec,0xea,0xe8,0xe6,0xe4,0xe2,0xe0,0xde,0xdc,\n0xda,0xd8,0xd5,0xd3,0xd1,0xce,0xcc,0xc9,0xc7,0xc4,0xc1,0xbf,0xbc,0xb9,0xb6,0xb3,\n0xb0,0xae,0xab,0xa8,0xa5,0xa2,0x9f,0x9c,0x98,0x95,0x92,0x8f,0x8c,0x89,0x86,0x83,\n0x80,0x7c,0x79,0x76,0x73,0x70,0x6d,0x6a,0x67,0x63,0x60,0x5d,0x5a,0x57,0x54,0x51,\n0x4f,0x4c,0x49,0x46,0x43,0x40,0x3e,0x3b,0x38,0x36,0x33,0x31,0x2e,0x2c,0x2a,0x27,\n0x25,0x23,0x21,0x1f,0x1d,0x1b,0x19,0x17,0x15,0x13,0x12,0x10,0x0f,0x0d,0x0c,0x0a,\n0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x03,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0x00,\n0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x05,0x06,0x07,0x08,\n0x09,0x0a,0x0c,0x0d,0x0f,0x10,0x12,0x13,0x15,0x17,0x19,0x1b,0x1d,0x1f,0x21,0x23,\n0x25,0x27,0x2a,0x2c,0x2e,0x31,0x33,0x36,0x38,0x3b,0x3e,0x40,0x43,0x46,0x49,0x4c,\n0x4f,0x51,0x54,0x57,0x5a,0x5d,0x60,0x63,0x67,0x6a,0x6d,0x70,0x73,0x76,0x79,0x7c\n};\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We store the value in Flash memory using const uint8_t sin_wave[256] PROGMEM. We also developed saw tooth, square and triangle wave variable value. Download the wave.h file. One interesting thing that we can store our variable in .h file and use it our main program. Our main program as follow-<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/************************************************************************************************\n*************************************************************************************************\nThis program will genarate different wavefrom according to switch\n\t\tPINB0---------Sawtooth\n\t\tPINB1---------Square\n\t\tPINB2---------Triangle\n\t\tPINB3---------SinWave\n************************************************************************************************\n***********************************************************************************************\/\n#include&lt;avr\/io.h&gt;\n#include&lt;util\/delay.h&gt;\n#include &quot;wave.h&quot;\nconst uint8_t *Wave&#x5B;4]PROGMEM ={Sawtooth,Square,Triangle,SinWave};\nuint8_t generarion,data;\nint main(void)\n{\nDDRB&amp;=(~((1&lt;&lt;DDB0)|(1&lt;&lt;DDB1)|(1&lt;&lt;DDB2)|(1&lt;&lt;DDB3)));\nPORTB|=(1&lt;&lt;PB0)|(1&lt;&lt;PB1)|(1&lt;&lt;PB2)|(1&lt;&lt;PB3);\ndata=PINB&amp;0b00001111;\nDDRD=0xFF;\nwhile(1)\n\t{\n\tdata=PINB&amp;0b00001111;\n\tif(data==0b00001110)\n\t{\n\t\tfor(int i=0;i&lt;256;i++)\n\t\t{\n\t\t\tgenerarion=(uint8_t*)pgm_read_word(&amp;Wave&#x5B;0]&#x5B;i]);\n\t\t\t_delay_ms(1);\n\t\t\tPORTD=generarion;\n\t\t}\n\t}\n\tif(data==0b00001101)\n\t{\n\t\tfor(int i=0;i&lt;256;i++)\n\t\t{\n\t\t\tgenerarion=(uint8_t*)pgm_read_word(&amp;Wave&#x5B;1]&#x5B;i]);\n\t\t\t_delay_ms(1);\n\t\t\tPORTD=generarion;\n\t\t}\n\t}\n\tif(data==0b00001011)\n\t{\n\t\tfor(int i=0;i&lt;256;i++)\n\t\t{\n\t\t\tgenerarion=(uint8_t*)pgm_read_word(&amp;Wave&#x5B;2]&#x5B;i]);\n\t\t\t_delay_ms(1);\n\t\t\tPORTD=generarion;\n\t\t}\n\t}\n\tif(data==0b00000111)\n\t{\n\t\tfor(int i=0;i&lt;256;i++)\n\t\t{\n\t\t\tgenerarion=(uint8_t*)pgm_read_word(&amp;Wave&#x5B;3]&#x5B;i]);\n\t\t\t_delay_ms(1);\n\t\t\tPORTD=generarion;\n\t\t}\n\t}\n\t}\nreturn 0;\n}\n<\/pre><\/div>\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Different-Function-Generator.rar\" style=\"padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-text-color has-link-color has-upper-heading-font-size wp-elements-0ff03a46a126aff89ff9e5a8e69779a6 wp-block-paragraph\" style=\"color:#080808\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Different-Function-Generator.rar\">Different Function Generator.rar<\/a><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>We previously learn about flash memory and how to program it. In this article we build a waveform generator. In that we uses four different switches to generate four different waveform i.e. Saw tooth, square, triangular and sinusoidal. We can get the desire analog signal from the Atmel AVR digital output with the help of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1219","post","type-post","status-publish","format-standard","hentry","category-flash-memory"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1219"}],"version-history":[{"count":46,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1219\/revisions"}],"predecessor-version":[{"id":2559,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1219\/revisions\/2559"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}