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; } }
the question is an oxymoron
how can I see an analog signal on a logic analyzer
Erik
So the table has 50 points, or 1000? Still it looks broken.
Clue: Put ONE cycle of a sine wave in your 50 points, sweeping from 0 to 2PI radians in 2PI/50 increments, and at your desired DC offset and amplitude. The output samples at 130 KHz (7.692ms intervals). Or reappraise your number of points to 32 or 16 or something.
Sorry not interested in doing your homework.
why do people answer all things except the asked one?! As I say I need to do this using only "timer interrupt". I dont want you to do my homework I have already done. If you dont understand the code then dont write anything. And im asking how to see analog wave on logic analyzer. not anything about code.
A logic analyzer is a tool intended to view logical levels - high or low. See any issues there? Digital high and low isn't exactly the same thing as analog curve shapes.
That's why this world got oscilloscopes - they are intended to present analog curves.
Right now, you want to use a hammer for your screws. Or zippers to build your house. Doesn't work too well.
Next thing - you want to use timers? But you aren't. The thing with timers is that you either make use of the timer interrupt. Or you poll a timer flag. Your code just ignores the timer and throws in values into the DAC as fast as your loop can manage.
When you think people are giving the wrong answers, it just might be the reverse. People give good answers, but your assumptions are wrong. Think twice about that since most people who answer you have spent 10 or 100 or 1000 times more time than you writing software.
Probably the same reason tools ask questions about their software and comprehension problems on a IDE vendors site, and haven't read the documentation for the IDE, or the chip they're using?
You don't understand the problem you're attempting to solve. Your sine table is useless, there is nothing here relating to 2600 Hz, or sine waves, you're not using a timer interrupt to pace the output, you're just jamming bogus values out the DAC and hoping that the "logic analyzer" or "oscilloscope" view is going to give you some magic clarity to the issues. It's not because you don't have the first clue about the signals and periodicity, basics that transcend the CPU or IDE used.
Try plugging your sine table into Excel and have that plot the data points.