Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Generate DAC samples using excel

Status
Not open for further replies.

lowpowermcu

Junior Member level 2
Joined
Aug 8, 2012
Messages
20
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,425
Hi all,

I want to generate a sine wave using my Digital to Analog Converter so I think I should generate the samples using excel (sine wave at a 3 Hz and 320 samples) once done I add it as a constant array in my code.
Is there somebody who did somethink like that?

MCU Lüfter
 

It's quite easy to write a quick 10-line C program to generate the correct table. Try this:
Code:
#include <stdio.h>
#include <math.h>

#define PI 3.14159

int
main(void)
{
  int range=127;
  int numsamp=320;
  
  int i;
  double s;
  double scaled;
  
  for (i=0; i<numsamp; i++)
  {
    s=sin(2*PI*(((double)i)/((double)numsamp)));
    scaled=s*((double)range);
    printf("%d,", (int)scaled);
  }
  
  return(0);
}
If you compile it and run it on you PC, it will print the sample values on the screen (or you could direct it into a file, e.g. by typing a.out > mysamples.txt, or just copy-and-paste the screen output directly into you code.
This was the output:
Code:
0,2,4,7,9,12,14,17,19,22,24,27,29,32,34,36,39,41,43,46,48,50,53,55,57,59,62,64,66,68,70,72,74,76,78,80,82,84,86,88,89,91,93,94,96,98,99,101,102,104,105,106,108,109,110,112,113,114,115,116,117,118,119,119,120,121,122,122,123,124,124,125,125,125,126,126,126,126,126,126,126,126,126,126,126,126,126,125,125,125,124,124,123,122,122,121,120,119,119,118,117,116,115,114,113,112,110,109,108,106,105,104,102,101,99,98,96,94,93,91,89,88,86,84,82,80,78,76,74,72,70,68,66,64,62,59,57,55,53,50,48,46,43,41,39,36,34,32,29,27,24,22,19,17,14,12,9,7,4,2,0,-2,-4,-7,-9,-12,-14,-17,-19,-22,-24,-27,-29,-32,-34,-36,-39,-41,-43,-46,-48,-50,-53,-55,-57,-59,-62,-64,-66,-68,-70,-72,-74,-76,-78,-80,-82,-84,-86,-88,-89,-91,-93,-94,-96,-98,-99,-101,-102,-104,-105,-106,-108,-109,-110,-112,-113,-114,-115,-116,-117,-118,-119,-119,-120,-121,-122,-122,-123,-124,-124,-125,-125,-125,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-126,-125,-125,-125,-124,-124,-123,-122,-122,-121,-120,-119,-119,-118,-117,-116,-115,-114,-113,-112,-110,-109,-108,-106,-105,-104,-102,-101,-99,-98,-96,-94,-93,-91,-89,-88,-86,-84,-82,-80,-78,-76,-74,-72,-70,-68,-66,-64,-62,-59,-57,-55,-53,-50,-48,-46,-43,-41,-39,-36,-34,-32,-29,-27,-24,-22,-19,-17,-14,-12,-9,-7,-4,-2,
In Excel, this is what it looks like:
sine.jpg
Note that you could just save a quarter sinewave, since it is symmetrical.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top