Generate sinusoidal reference signal - Page 1
Forum section: electronics / projects

author: Faringdon
author_rank: Super Contributor
timestamp: August 04, 2021, 07:07:18 pm
content: 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/

author: TimFox
author_rank: Super Contributor
timestamp: August 04, 2021, 07:20:14 pm
content: 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.

author: Miyuki
author_rank: Frequent Contributor
timestamp: August 04, 2021, 07:20:47 pm
content: Today, just take any MCU with integrated DAC, or external if you already have a MCU without itFlexible, cheap a just one chip/module

author: Faringdon
author_rank: Super Contributor
timestamp: August 04, 2021, 08:24:35 pm
content: QuoteThanks, 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?

author: dmendesf
author_rank: Frequent Contributor
timestamp: August 04, 2021, 10:19:08 pm
content: Make a table with excel/Matlab/etc and use it.

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 04, 2021, 10:30:35 pm
content: 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.

author: oPossum
author_rank: Super Contributor
timestamp: August 05, 2021, 02:12:19 am
content: DDS using ATmega328.50 Hz sine and 100 Hz rectified sineOutput is PWM so a low pass filter is required.Code:#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 SineOCR1B = 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 / 50OCR1A = OCR1B = 180;TIFR1 = ~0;TIMSK1 = 0x20;__asm__ __volatile__ ("sei" ::: "memory");for(;;);return 0;}

author: trobbins
author_rank: Frequent Contributor
timestamp: August 05, 2021, 03:16:07 am
content: Soundcard output? Use cap for isolation and to allow biasing to whatever DC level you have on the 'application' side, given you say 'unipolar'.