This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How can I see sine wave on logic analyzer?

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; }
}

Parents
  • can you run this code for me

    #define BIT0 0
    #define BIT1 2
    #define BIT2 3
    #define BIT3 5
    #define BIT4 6
    #define BIT5 7
    #define BIT6 9
    #define BIT7 1
    #define BIT8 4

    #define LED_OFF P0=12
    #define LED_ON P0=7

    int main( void )
    { P1 = 0x19;

    int count=0;

    TMR0 = (1<<BIT3)|(BIT2); // divide by 1024 TMR1 = 1<<BIT7; // enable timer interrupt

    sei();

    for(;;) { // main loop // single press /* if( get_key_press( 1<<KEY0 )) { if(count<=3) count++; } */ // release after short press: task 1 // long press: task 2

    if( get_key_short( 1<<KEY0 )) { if(count<=3) count++; }

    if( get_key_long( 1<<KEY0 )) { LED1_OFF; LED2_OFF; LED3_OFF; count = 1; }

    switch(count) { case 1: LED1_OFF; LED2_OFF; LED3_OFF; break; case 2: LED2_OFF; LED3_OFF; LED1_ON; break; case 3: LED3_OFF; LED1_OFF; LED2_ON; break; case 4: LED1_OFF; LED2_OFF; LED3_ON; break; }

    // single press and repeat
    /* if( get_key_press( 1<<KEY0 ) || get_key_rpt( 1<<KEY0 )){ uint8_t i = LED_PORT;

    i = (i & 0x07) | ((i << 1) & 0xF0); if( i < 0xF0 ) i |= 0x08; count=0; }
    */ }
    }

Reply
  • can you run this code for me

    #define BIT0 0
    #define BIT1 2
    #define BIT2 3
    #define BIT3 5
    #define BIT4 6
    #define BIT5 7
    #define BIT6 9
    #define BIT7 1
    #define BIT8 4

    #define LED_OFF P0=12
    #define LED_ON P0=7

    int main( void )
    { P1 = 0x19;

    int count=0;

    TMR0 = (1<<BIT3)|(BIT2); // divide by 1024 TMR1 = 1<<BIT7; // enable timer interrupt

    sei();

    for(;;) { // main loop // single press /* if( get_key_press( 1<<KEY0 )) { if(count<=3) count++; } */ // release after short press: task 1 // long press: task 2

    if( get_key_short( 1<<KEY0 )) { if(count<=3) count++; }

    if( get_key_long( 1<<KEY0 )) { LED1_OFF; LED2_OFF; LED3_OFF; count = 1; }

    switch(count) { case 1: LED1_OFF; LED2_OFF; LED3_OFF; break; case 2: LED2_OFF; LED3_OFF; LED1_ON; break; case 3: LED3_OFF; LED1_OFF; LED2_ON; break; case 4: LED1_OFF; LED2_OFF; LED3_ON; break; }

    // single press and repeat
    /* if( get_key_press( 1<<KEY0 ) || get_key_rpt( 1<<KEY0 )){ uint8_t i = LED_PORT;

    i = (i & 0x07) | ((i << 1) & 0xF0); if( i < 0xF0 ) i |= 0x08; count=0; }
    */ }
    }

Children
  • it gives errors but i did not understand what this code about sorry im new in this thing

  • hi what errors do you get

    is anyone here good to fix them.

  • 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;
    }
    }
    

  • #define BIT0 0
    #define BIT1 2
    #define BIT2 3
    #define BIT3 5
    #define BIT4 6
    #define BIT5 7
    #define BIT6 9
    #define BIT7 1
    #define BIT8 4
    

    You might want to consider rewriting that bit so it looks more artful

    Maybe:

    #define ZERO  0
    #define ONE   2
    #define TWO   3
    #define THREE 5
    #define FOUR  6
    #define FIVE  7
    #define SIX   9
    #define SEVEN 1
    #define EIGHT 4