Author Topic: Generate sinusoidal reference signal  (Read 488 times)

0 Members and 1 Guest are viewing this topic.

Offline Faringdon

  • Frequent Contributor
  • **
  • Posts: 280
  • Country: gb
Generate sinusoidal reference signal
« on: August 04, 2021, 07:07:18 pm »
Hi,
We  wish to get a unipolar sinusoidal reference....ie like a rectified sine....we only want 1vpk...and preferably variable to eg 0.9vpk etc.
Also 50Hz...but it will be 100Hz because its a train of positive sine "halves".
{EDIT...it doesnt have to provide any power}

We coudl just filter a square wave i am thinking.

Because this kind of approach is too many components...
https://www.eevblog.com/forum/beginners/creating-a-sinusoidaland-triangle-reference-wave-from-analog-stuff/
« Last Edit: August 07, 2021, 11:57:01 am by Faringdon »
 

Online TimFox

  • Super Contributor
  • ***
  • Posts: 3357
  • Country: us
  • Retired, now restoring antique test equipment
Re: Generate sinusoidal reference signal
« Reply #1 on: August 04, 2021, 07:20:14 pm »
If you strenuously filter a square wave, by passing it through a series of low-pass filters for example, the result will be a sine wave, not a rectified sinusoid, since the latter is a non-linear function of a sinusoid.  You could rectify the sine wave after the filter.  Varying the amplitude of the square wave will proportionally change the filter output (which is a linear function of its input).  For “reference” purposes, you must accurately quantify the filter response, as well as the square wave amplitude.
 
The following users thanked this post: Faringdon

Online Miyuki

  • Frequent Contributor
  • **
  • Posts: 610
  • Country: cz
    • Me on youtube
Re: Generate sinusoidal reference signal
« Reply #2 on: August 04, 2021, 07:20:47 pm »
Today, just take any MCU with integrated DAC, or external if you already have a MCU without it
Flexible, cheap a just one chip/module
 
The following users thanked this post: Faringdon

Offline Faringdon

  • Frequent Contributor
  • **
  • Posts: 280
  • Country: gb
Re: Generate sinusoidal reference signal
« Reply #3 on: August 04, 2021, 08:24:35 pm »
Quote
Today, just take any MCU with integrated DAC, o
Thanks, do you know where the code is for this...or is it just a case of using that function for sine, using multiplications and additions?
 

Offline dmendesf

  • Regular Contributor
  • *
  • Posts: 222
  • Country: br
Re: Generate sinusoidal reference signal
« Reply #4 on: August 04, 2021, 10:19:08 pm »
Make a table with excel/Matlab/etc and use it.
 
The following users thanked this post: Faringdon

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 7316
  • Country: fr
Re: Generate sinusoidal reference signal
« Reply #5 on: August 04, 2021, 10:30:35 pm »
Question is: what would be the requirement in terms of distortion?

If you need a "sinusoidal" signal, then obviously that means that you want "low" distortion. Because clearly a square wave will be your sine if you accept high distortion. You get the idea. Low-pass filtering a square wave will give you less distortion. The sharper the filter, the better. Note that simply filtering won't get you a rectified sine. And, any further rectifying step will introduce further distortion (non-linearity close to zero.)

So your max distortion requirement will help selecting an appropriate approach.
Another requirement to know would be about max power consumption.

One can't design without requirements. :-//
« Last Edit: August 04, 2021, 10:32:33 pm by SiliconWizard »
 
The following users thanked this post: Faringdon

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1267
  • Country: us
  • The other white meat.
Re: Generate sinusoidal reference signal
« Reply #6 on: August 05, 2021, 02:12:19 am »
DDS using ATmega328.
50 Hz sine and 100 Hz rectified sine
Output is PWM so a low pass filter is required.

Code: [Select]
#include <xc.h>

static int8_t const st[1 << 9] = {
        0,    1,    3,    4,    6,    7,    9,   10,   12,   13,   15,   17,   18,   20,   21,   23,
       24,   26,   27,   29,   30,   32,   33,   35,   36,   38,   39,   41,   42,   44,   45,   47,
       48,   50,   51,   52,   54,   55,   57,   58,   59,   61,   62,   63,   65,   66,   67,   69,
       70,   71,   73,   74,   75,   76,   78,   79,   80,   81,   82,   84,   85,   86,   87,   88,
       89,   90,   91,   93,   94,   95,   96,   97,   98,   99,  100,  101,  102,  102,  103,  104,
      105,  106,  107,  108,  108,  109,  110,  111,  112,  112,  113,  114,  114,  115,  116,  116,
      117,  117,  118,  119,  119,  120,  120,  121,  121,  121,  122,  122,  123,  123,  123,  124,
      124,  124,  125,  125,  125,  125,  126,  126,  126,  126,  126,  126,  126,  126,  126,  126,
      126,  126,  126,  126,  126,  126,  126,  126,  126,  126,  126,  125,  125,  125,  125,  124,
      124,  124,  123,  123,  123,  122,  122,  121,  121,  121,  120,  120,  119,  119,  118,  117,
      117,  116,  116,  115,  114,  114,  113,  112,  112,  111,  110,  109,  108,  108,  107,  106,
      105,  104,  103,  102,  102,  101,  100,   99,   98,   97,   96,   95,   94,   93,   91,   90,
       89,   88,   87,   86,   85,   84,   82,   81,   80,   79,   78,   76,   75,   74,   73,   71,
       70,   69,   67,   66,   65,   63,   62,   61,   59,   58,   57,   55,   54,   52,   51,   50,
       48,   47,   45,   44,   42,   41,   39,   38,   36,   35,   33,   32,   30,   29,   27,   26,
       24,   23,   21,   20,   18,   17,   15,   13,   12,   10,    9,    7,    6,    4,    3,    1,
        0,   -1,   -3,   -4,   -6,   -7,   -9,  -10,  -12,  -13,  -15,  -17,  -18,  -20,  -21,  -23,
      -24,  -26,  -27,  -29,  -30,  -32,  -33,  -35,  -36,  -38,  -39,  -41,  -42,  -44,  -45,  -47,
      -48,  -50,  -51,  -52,  -54,  -55,  -57,  -58,  -59,  -61,  -62,  -63,  -65,  -66,  -67,  -69,
      -70,  -71,  -73,  -74,  -75,  -76,  -78,  -79,  -80,  -81,  -82,  -84,  -85,  -86,  -87,  -88,
      -89,  -90,  -91,  -93,  -94,  -95,  -96,  -97,  -98,  -99, -100, -101, -102, -102, -103, -104,
     -105, -106, -107, -108, -108, -109, -110, -111, -112, -112, -113, -114, -114, -115, -116, -116,
     -117, -117, -118, -119, -119, -120, -120, -121, -121, -121, -122, -122, -123, -123, -123, -124,
     -124, -124, -125, -125, -125, -125, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126,
     -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -126, -125, -125, -125, -125, -124,
     -124, -124, -123, -123, -123, -122, -122, -121, -121, -121, -120, -120, -119, -119, -118, -117,
     -117, -116, -116, -115, -114, -114, -113, -112, -112, -111, -110, -109, -108, -108, -107, -106,
     -105, -104, -103, -102, -102, -101, -100,  -99,  -98,  -97,  -96,  -95,  -94,  -93,  -91,  -90,
      -89,  -88,  -87,  -86,  -85,  -84,  -82,  -81,  -80,  -79,  -78,  -76,  -75,  -74,  -73,  -71,
      -70,  -69,  -67,  -66,  -65,  -63,  -62,  -61,  -59,  -58,  -57,  -55,  -54,  -52,  -51,  -50,
      -48,  -47,  -45,  -44,  -42,  -41,  -39,  -38,  -36,  -35,  -33,  -32,  -30,  -29,  -27,  -26,
      -24,  -23,  -21,  -20,  -18,  -17,  -15,  -13,  -12,  -10,   -9,   -7,   -6,   -4,   -3,   -1
};

void __attribute__ ((signal, used, externally_visible)) TIMER1_CAPT_vect(void)
{
    static uint16_t n;
   
    OCR1A = 300 + st[n & 0x01FF];   //  50 Hz Sine
    OCR1B = 300 + st[n & 0x00FF];   // 100 Hz Rectified sine
    ++n;
}

int main(void)
{
    PORTB = 0x00;
    PORTC = 0x00;
    PORTD = 0x02;
    DDRB = 0xFF;
    DDRC = 0xFF;
    DDRD = 0xFE;
    TCCR1A = 0xA2;
    TCCR1B = 0x19;
    TCCR1C = 0x00;
    ICR1 = 625 - 1; // 16M / 512 / 50
    OCR1A = OCR1B = 180;
    TIFR1 = ~0;
    TIMSK1 = 0x20;
    __asm__ __volatile__ ("sei" ::: "memory");
   
    for(;;);
   
    return 0;
}
 

Offline trobbins

  • Frequent Contributor
  • **
  • Posts: 448
  • Country: au
Re: Generate sinusoidal reference signal
« Reply #7 on: August 05, 2021, 03:16:07 am »
Soundcard output?  Use cap for isolation and to allow biasing to whatever DC level you have on the 'application' side, given you say 'unipolar'.
 
The following users thanked this post: Faringdon


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf