high frequency interrupt based sinewave generation AVR

Discussion in 'Embedded Systems and Microcontrollers' started by sadiq_bokhari, Jul 27, 2015.

  1. sadiq_bokhari

    Thread Starter New Member

    May 8, 2015
    11
    0
    Hi, i've written a code to generate a sinewave using the DAC of my Atmega128, we have been asked to use interrupts for this purpose, and minimum sample rate is 32, the frequency range being 5Hz - 5000Hz
    for higher frequencies the interrupts become very frequent and sometimes the program does not take the input because of this or just gets stuck
    what could i do to resolve this issue ?
     
  2. DickCappels

    Moderator

    Aug 21, 2008
    2,656
    632
    Use a faster clock.
     
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    And/or tighter code.
     
  4. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,909
    2,170
    and instrument the code to see (with a scope) what's happening (with I/O toggles) when the code is being optimized for speed.

    Loop-back testing main line code:
    Code (C):
    1.  
    2.         ringBufS_put(L.tx2b, 0b000000000);
    3.         ringBufS_put(L.tx2b, 0b111111111);
    4.         ringBufS_put(L.tx2b, 0b011111111);
    5.         ringBufS_put(L.tx2b, 0b111111111);
    6.         ringBufS_put(L.tx2b, 0b011111111);
    7.         ringBufS_put(L.tx2b, 0b111111111);
    8.         ringBufS_put(L.tx2b, 0b011111111);
    9.         ringBufS_put(L.tx2b, 0b111111111);
    10.         ringBufS_put(L.tx2b, 0b000000000);
    11.  
    12.         ringBufS_put(L.tx1b, 0b000000000);
    13.         ringBufS_put(L.tx1b, 0b111111111);
    14.         ringBufS_put(L.tx1b, 0b011111111);
    15.         ringBufS_put(L.tx1b, 0b111111111);
    16.         ringBufS_put(L.tx1b, 0b011111111);
    17.         ringBufS_put(L.tx1b, 0b111111111);
    18.         ringBufS_put(L.tx1b, 0b011111111);
    19.         ringBufS_put(L.tx1b, 0b111111111);
    20.         ringBufS_put(L.tx1b, 0b000000000);
    21.  
    22.         send_lcd_data('F');
    23.         send_lcd_data('R');
    24.         send_lcd_data('E');
    25.         send_lcd_data('D');
    26.  
    27.         start_tx1();
    28.         start_tx2();
    29.         start_lcd();
    30.         while (!ringBufS_empty(L.tx2b));
    31.         while (!ringBufS_empty(spi_link.tx1b));
    32.  
    Top trace: logic high main cpu time, logic low in ISR cpu time showing transmit/receive interrupts.
    bottom three: different ISR trigger toggles RS232 1&2 rx, SPI I/O burst and idle periods.
    [​IMG]
    [​IMG]
    Detail in I/O bursts.
    [​IMG]
     
    Last edited: Jul 30, 2015
    JohnInTX likes this.
Loading...