Hi. I have a code that generates sine wave that shoul have 2600Hz frequency. When I run this code in Keil i can't see sine wave on logic analyzer so I dont know the frequency of sine wave. how can i solve this problem? thanks for all!
The Code
#include <stdio.h> #include <ADuC841.h>
sbit LED = 0x0B4;
void timer0(void) interrupt 1 //interrupt no. 1 for Timer 0 { TH0=0xFC; TL0=0xFB; }
void main (void) {
unsigned code values[50][2]={{0x0F, 0x7F},{0x08, 0x11},{0x01, 0x80},{0x07, 0xBF},{0x0D, 0x87}, {0x08, 0x91},{0x03, 0x68},{0x07, 0x02},{0x0B, 0xB7},{0x09, 0x88}, {0x05, 0x19},{0x05, 0xD4},{0x0A, 0x2C},{0x0A, 0xE7},{0x06, 0x78}, {0x04, 0x49},{0x08, 0xFE},{0x0C, 0x98},{0x07, 0x6F},{0x02, 0x79}, {0x08, 0x41},{0x0E, 0x80},{0x07, 0xEF},{0x00, 0x81},{0x08, 0x01}, {0x00, 0x81},{0x07, 0xEF},{0x0E, 0x80},{0x08, 0x41},{0x02, 0x79}, {0x07, 0x6F},{0x0C, 0x98},{0x08, 0xFE},{0x04, 0x49},{0x06, 0x78}, {0x0A, 0xE7},{0x0A, 0x2C},{0x05, 0xD4},{0x05, 0x19},{0x09, 0x88}, {0x0B, 0xB7},{0x07, 0x02},{0x03, 0x68},{0x08, 0x91},{0x0D, 0x87}, {0x07, 0xBF},{0x01, 0x80},{0x08, 0x11},{0x0F, 0x7F},{0x07, 0xFF}};
DACCON = 0x0D;
DAC0H = 0x08; DAC0L = 0x00;
TMOD = 0x01; // mode1 of Timer0 TH0 = 0xFC; // initial values loaded to timer TL0 = 0xFB; IE = 0x82; // enable interrupt TR0 = 1; //start timer while(1) { int i; for ( i = 0 ; i < 50; i++) { DAC0H = values[i][0]; DAC0L = values[i][1]; } LED ^= 1; } }
It would really help if you guys would read the posting instructions so your source isn't a jumbled mess of lines.
Don't post off topic noise to an existing thread, start a new one.
The sine table looks awful. How exactly did you create this, and how does blasting values to the DAC use the timer to pace the output?
your answer is not the answer to my nquestion. so if you want to insult people please do this somewhere else. as answer to your question this is a homework and i choose 2600Hz frequency. i need to generate a sine wave that has 2600 Hz frequency using timer interrupt. not anything else. Im new in this thing and i might wrote the code wrong. if this, please correct me KINDLY.
this is the code that gives the sine table value. i did run it in matlab and got the values.
clear; close all; N=1000; frekans=2600; fo=10000; for i=1:1:N x(i)=2047*cos(2*pi*frekans*i/fo); end figure; plot(x); B=input('\nCikis dosyasinin ismi *.txt = ','s'); fid=fopen(B,'w'); for i=1:1:N if (x(i) < 0) x(i)=x(i)+4096; end xx= round(x(i)); if (xx>=4096) xx=xx-4096; end %fprintf(fid,'%i \n',xx); fprintf(fid,'%4x \n',xx); end fclose(fid);
and this is the code i wrote
#include <stdio.h> #include <ADuC841.h> sbit LED = 0x0B4; void timer0(void) interrupt 1 //interrupt no. 1 for Timer 0 { TH0=0xFC; TL0=0xFB; } void main (void) { unsigned code values[50][2]={{0x0F, 0x7F},{0x08, 0x11},{0x01, 0x80},{0x07, 0xBF},{0x0D, 0x87}, {0x08, 0x91},{0x03, 0x68},{0x07, 0x02},{0x0B, 0xB7},{0x09, 0x88}, {0x05, 0x19},{0x05, 0xD4}, {0x0A, 0x2C},{0x0A, 0xE7},{0x06, 0x78}, {0x04, 0x49},{0x08, 0xFE},{0x0C, 0x98},{0x07, 0x6F}, {0x02, 0x79}, {0x08, 0x41},{0x0E, 0x80},{0x07, 0xEF},{0x00, 0x81},{0x08, 0x01}, {0x00, 0x81}, {0x07, 0xEF},{0x0E, 0x80},{0x08, 0x41},{0x02, 0x79}, {0x07, 0x6F},{0x0C, 0x98},{0x08, 0xFE}, {0x04, 0x49},{0x06, 0x78}, {0x0A, 0xE7},{0x0A, 0x2C},{0x05, 0xD4},{0x05, 0x19},{0x09, 0x88}, {0x0B, 0xB7},{0x07, 0x02},{0x03, 0x68},{0x08, 0x91},{0x0D, 0x87}, {0x07, 0xBF},{0x01, 0x80}, {0x08, 0x11},{0x0F, 0x7F},{0x07, 0xFF}}; DACCON = 0x0D; DAC0H = 0x08; DAC0L = 0x00; TMOD = 0x01; // mode1 of Timer0 TH0 = 0xFC; // initial values loaded to timer TL0 = 0xFB; IE = 0x82; // enable interrupt TR0 = 1; //start timer while(1) { int i; for ( i = 0 ; i < 50; i++) { DAC0H = values[i][0]; DAC0L = values[i][1]; } LED ^= 1; } }