Dirty sine wave generator

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Is there a way to extrapolate this D flip flop-based/XOR modified  
sine-wave generator to be a little less "steppy" using a couple more  
flops or XOR gates? or provide outputs of different phases?

I was thinking about a thing using the TinyLogic series flops/gates to  
clock it very fast.

<
http://zpostbox.ru/digital_generators_of_sine_wave_signals_2.gif



Re: Dirty sine wave generator
On 9/19/19 1:35 AM, bitrex wrote:
Quoted text here. Click to load it

Unfortunately my LTSpice sim of it with 74HC logic models shows  
glitching on some transitions that becomes worse with speed:

<https://imgur.com/a/j864h8b

Don't know yet if shows up in the real circuit.

Re: Dirty sine wave generator
Quoted text here. Click to load it

Those glitches look real to me. (it's the propogation time of the second
flip-flop) but if you're going to low-pass the output they'll disappear.
ther'll only be a slight saw-toothiness caused by that propogation delay.

If you want glitch-free build a 3 stage johnson counter  

--  
  When I tried casting out nines I made a hash of it.

Re: Dirty sine wave generator
On Thursday, September 19, 2019 at 4:31:20 PM UTC+10, Jasen Betts wrote:
Quoted text here. Click to load it
  
Quoted text here. Click to load it
  
Quoted text here. Click to load it

I suspect the glitches are built-in.

A square wave can be seen as the sum of all the odd harmonics of a sine wav
e of the same period (with the harmonic amplitude decreasing in proportion  
to harmonic number).

Bitrex is knocking out the third harmonic content of his basic square wave  
by subtracting out the first harmonic content of his triple frequency squar
e wave, but this doesn't help with higher harmonics - the odd harmonics of  
three time the frequency aren't all the odd harmonics of the base frequency
.

Not a great idea, and it doesn't get better if you try to elaborate it.

--  
Bill Sloman, Sydney

Re: Dirty sine wave generator
On Thursday, September 19, 2019 at 1:59:58 AM UTC-4, bitrex wrote:
Quoted text here. Click to load it
  
Quoted text here. Click to load it

If you think that is bad, try looking at the clock input to the first FF.
  

The circuit is a divide by three to generate (1) and the inverted signal (2
), the slowest input to the two bit DAC.  That signal should not be glitchy
.  The clock signal is the fastest signal, again, not glitchy.  When the cl
ock signal changes it takes time for that signal to propagate through the X
OR and the two FFs to be combined with the clock signal in the DAC so you g
et the glitches as the clock changes first, then the signal (2).  

To drive a glitchless DAC output with N values, you would need N-1 FFs driv
en in a thermometer code.  This is very practical and would be glitchless s
ince the glitches come from race conditions and a thermometer code only cha
nges one bit at a time.  A Johnson ring counter would do the job just fine.
  So an 8 bit register chip and an inverter (a chip or a transistor) would  
provide a thermometer code that first fills all the bits, then empties them
 in the same direction.  

000
100
110
111
011
001
000

Use equal weight resistors on the outputs and you get a triangle wave.  Tai
lor the weights with larger resistors at the ends of the thermometer code t
o shape it more like a sine wave.  I'll let you do the math.  You can casca
de more than one octal register and get a very good sine wave.  

--  

  Rick C.

  - Get 2,000 miles of free Supercharging
We've slightly trimmed the long signature. Click to see the full one.
Re: Dirty sine wave generator
On Thursday, September 19, 2019 at 9:33:21 AM UTC-4, Rick C wrote:
Quoted text here. Click to load it
  
Quoted text here. Click to load it
o  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
(2), the slowest input to the two bit DAC.  That signal should not be glitc
hy.  The clock signal is the fastest signal, again, not glitchy.  When the  
clock signal changes it takes time for that signal to propagate through the
 XOR and the two FFs to be combined with the clock signal in the DAC so you
 get the glitches as the clock changes first, then the signal (2).  
Quoted text here. Click to load it
iven in a thermometer code.  This is very practical and would be glitchless
 since the glitches come from race conditions and a thermometer code only c
hanges one bit at a time.  A Johnson ring counter would do the job just fin
e.  So an 8 bit register chip and an inverter (a chip or a transistor) woul
d provide a thermometer code that first fills all the bits, then empties th
em in the same direction.  
Quoted text here. Click to load it
ailor the weights with larger resistors at the ends of the thermometer code
 to shape it more like a sine wave.  I'll let you do the math.  You can cas
cade more than one octal register and get a very good sine wave.  


https://www.tinaja.com/glib/rad_elec/digital_sinewaves_11_76.pdf

If you use more and more bits in creating your sine wave both the frequency
 and amplitude of your harmonics are reduced.  Filtering may or may not be  
needed, but will be much more effective by the smaller step sizes.  

I use a sigma-delta DAC in a design I build which shows staircase steps in  
the output waveforms.  The steps are small and well above the audio range,  
so not a problem.  Use enough FFs and resistors and your harmonics will be  
out of the audible range so no filter will be required unless there is some
 sensitive equipment in the path which I highly doubt.  

--  

  Rick C.

  + Get 2,000 miles of free Supercharging
We've slightly trimmed the long signature. Click to see the full one.
Re: Dirty sine wave generator
On 9/19/19 9:33 AM, Rick C wrote:
Quoted text here. Click to load it

Yep, the input to the XOR and the output of the XOR (in red) shows why  
the glitch happens:

<https://imgur.com/a/54VO6jP


Quoted text here. Click to load it

Looking at the waveforms it looks like it might be possible to "lock  
out" the glitch by using another flop and gate or two to synchronize the  
timing of the inputs to the XOR. that would also be satisfactory

Re: Dirty sine wave generator
On Thursday, September 19, 2019 at 11:23:54 AM UTC-4, bitrex wrote:
Quoted text here. Click to load it
o
F.
l (2), the slowest input to the two bit DAC.  That signal should not be gli
tchy.  The clock signal is the fastest signal, again, not glitchy.  When th
e clock signal changes it takes time for that signal to propagate through t
he XOR and the two FFs to be combined with the clock signal in the DAC so y
ou get the glitches as the clock changes first, then the signal (2).
Quoted text here. Click to load it

Yep.  


Quoted text here. Click to load it
driven in a thermometer code.  This is very practical and would be glitchle
ss since the glitches come from race conditions and a thermometer code only
 changes one bit at a time.  A Johnson ring counter would do the job just f
ine.  So an 8 bit register chip and an inverter (a chip or a transistor) wo
uld provide a thermometer code that first fills all the bits, then empties  
them in the same direction.
Quoted text here. Click to load it
 Tailor the weights with larger resistors at the ends of the thermometer co
de to shape it more like a sine wave.  I'll let you do the math.  You can c
ascade more than one octal register and get a very good sine wave.
Quoted text here. Click to load it
  
Quoted text here. Click to load it

That way lies madness.  You said you wanted a better sinewave.  Why not use
 more FFs in a single chip?  You can find lots of chips with 8 FFs and if y
ou dig a bit I think you can find 10.  Why is one 8 bit chip worse than one
 2 bit chip?  You will be amazed at the improvement in the quality of the s
ine wave.  

It will require a faster clock.  Is that the issue?  

--  

  Rick C.

  -- Get 2,000 miles of free Supercharging
We've slightly trimmed the long signature. Click to see the full one.
Re: Dirty sine wave generator
On Thursday, September 19, 2019 at 4:18:24 PM UTC-4, Rick C wrote:
Quoted text here. Click to load it
e
 to
Quoted text here. Click to load it
 FF.
Quoted text here. Click to load it
nal (2), the slowest input to the two bit DAC.  That signal should not be g
litchy.  The clock signal is the fastest signal, again, not glitchy.  When  
the clock signal changes it takes time for that signal to propagate through
 the XOR and the two FFs to be combined with the clock signal in the DAC so
 you get the glitches as the clock changes first, then the signal (2).
Quoted text here. Click to load it
  
Quoted text here. Click to load it
s driven in a thermometer code.  This is very practical and would be glitch
less since the glitches come from race conditions and a thermometer code on
ly changes one bit at a time.  A Johnson ring counter would do the job just
 fine.  So an 8 bit register chip and an inverter (a chip or a transistor)  
would provide a thermometer code that first fills all the bits, then emptie
s them in the same direction.
Quoted text here. Click to load it
.  Tailor the weights with larger resistors at the ends of the thermometer  
code to shape it more like a sine wave.  I'll let you do the math.  You can
 cascade more than one octal register and get a very good sine wave.
Quoted text here. Click to load it
e  
Quoted text here. Click to load it
se more FFs in a single chip?  You can find lots of chips with 8 FFs and if
 you dig a bit I think you can find 10.  Why is one 8 bit chip worse than o
ne 2 bit chip?  You will be amazed at the improvement in the quality of the
 sine wave.  
Quoted text here. Click to load it

And just to be clear, this design produces no glitches.  The glitches are b
ecause more than one signal is changing at a time and the timing will never
 be perfect.  So work with a design where only one signal changes at a time
.  Johnson ring counter is the way.  Use the force Luke.  

--  

  Rick C.

  -+ Get 2,000 miles of free Supercharging
We've slightly trimmed the long signature. Click to see the full one.
Re: Dirty sine wave generator
On Thursday, September 19, 2019 at 3:35:33 PM UTC+10, bitrex wrote:
Quoted text here. Click to load it

Probably not.

https://www.tinaja.com/glib/msintro1.pdf

https://www.tinaja.com/magsn01.shtml

offers a more sensible approach. You cook up a long binary number where the mark-to-space varies along it's length, and cycle it past a low-pass filter.

Carefully chosen numbers can have zero low harmonic content, but they do seem to be quite long.

Direct digital synthesis chips are a lot more practical.

--  
Bill Sloman, Sydney


Re: Dirty sine wave generator

Quoted text here. Click to load it

  Hehehe.  Run it through one of the distortion pedals guitarists  
use.  Definitely has harmonics.  ;-)

Re: Dirty sine wave generator
On 19/09/2019 06:35, bitrex wrote:
Quoted text here. Click to load it

The faster you try to clock it the worse things will get with  
propagation delays in the flip flops as drawn.

To take out most of the 5th harmonic component you will need a divide by  
5 counter in the right phase. Each extra component you try to compensate  
seriously limits the maximum output frequency that it will work at. The  
fundamental will be lowered from f/3 to f/15 by adding this factor.

The least bad fix might be to treat the output as a current source and  
integrate it so that you get a step wise linear approximation.
(or aggressively low pass filter against the fifth harmonic and above).

What are you trying to do?

--  
Regards,
Martin Brown

Re: Dirty sine wave generator
On 9/19/19 4:52 AM, Martin Brown wrote:
Quoted text here. Click to load it

I have an I/Q demodulator/detector scheme that has to run pretty fast at  
very low voltage, the 0 degree phase path goes through some op amps with  
somewhat limited bandwidth and slew rate because they're low voltage  
types. it's fed by a reference clock.

the whole system would work fine with square waves if I had the budget  
for infinite GBW and slew rate parts but the op amps I can afford on the  
budget in the path don't really have enough GBW and slew rate to support  
a square wave at the speed I need to go so, I don't want to shove a raw  
square into them like a brutal person.

this would work fine to produce a modified sine and a quadrature square  
wave and is just what I need, aside from the glitches which causes  
problems down the line. using lower value resistors I can just drive the  
input of the analog section directly from the flop outputs, the amps are  
single-supply biased at the mid-point of the same supply and just drive  
it in, nice.

<https://imgur.com/a/IahCKuJ

I want to maintain a tight phase relationship between the two signals so  
IDK if aggressive low passing is an option here. a couple flops and  
gates is within my price/power budget so I'm wishing there was a way to  
eliminate the glitch at the source without piling on parts, at that  
point I'd likely just resort to DDS. but I'd prefer to be able to  
provide a solution that works OK driven by a clock from whatever source  
in this case



Re: Dirty sine wave generator
On 19/09/2019 16:02, bitrex wrote:
Quoted text here. Click to load it

How about a 2 flip flop Johnson ring counter then?
That can be configured to generate the quadrature square waves.

Integrate them to a triangle wave and use diode shaping.
How wide a range of frequencies does this have to work at?

--  
Regards,
Martin Brown

Re: Dirty sine wave generator
On 9/20/19 5:47 AM, Martin Brown wrote:

Quoted text here. Click to load it

Just one, around 200-300kHz. Here's the drive current into my load thru  
the op amp network at about 200k (slight visible phase shift is due to  
the AD8515 being one of the few low voltage op amps I can find in the  
LTSPice library, I'll likely be using the twice-as-fast OPA4332):

<https://imgur.com/a/f3RWq8j

If not for the glitchin' it'd be near perfect, with only 3 parts. I'm on  
a pretty tight budget for per-unit cost...had to blow most of the budget  
on fast low voltage op amp....frustrating!

I don't think the glitches will affect the performance much...I may just  
try to live with it...compromise...:(


Re: Dirty sine wave generator
On Friday, September 20, 2019 at 8:50:54 AM UTC-7, bitrex wrote:
Quoted text here. Click to load it


That range allows for some options; the 'integrate' is a filter that
takes the harmonics down 3 dB/octave, but you can just
as easily use a double-tuned IF transformer, and get  12 dB/octave.
Some of 'em can be slug-tuned, too.   It's power-stingy, and in quantity, those
little wire twists are really inexpensive.

Standard off-the-shelf designs would take some external capacitors to pull
to your frequency range (from 457 kHz), but a manufacturer can build them
for any center frequency, and with your choice of input and output impedance.

Re: Dirty sine wave generator
On Friday, September 20, 2019 at 11:50:54 AM UTC-4, bitrex wrote:
Quoted text here. Click to load it

Not really.  Until you get the weights right it will be more like a triangle wave.  The wide pulse coming from the FF has to be three times the amplitude of the pulse coming from the clock.  It looks like in your circuit the ratio isn't even 2:1.  

BTW, something is wrong with the timing, but maybe that's because this is a simulation with unrealistic numbers.  The glitch should be much smaller than you are showing.  


Quoted text here. Click to load it

Why can't you use an 8 bit shift register?  It can't be that much more than the dual FF.  What parts are you using?  

--  

  Rick C.

  ++ Get 2,000 miles of free Supercharging
We've slightly trimmed the long signature. Click to see the full one.
Re: Dirty sine wave generator
On 9/20/19 11:37 PM, Rick C wrote:
Quoted text here. Click to load it

The sim is 74HC but 74LVC likely for the actual device as needs to go  
down to 1.8 volts on the supply hence the CMOS low-voltage type op amps.  
I already need at least 1 XOR elsewhere. also a square wave that's 90  
degrees advanced from the "sine."

A counter could work, too. If I could use up the extra XORs in something  
like this:

<https://www.quora.com/How-do-I-generate-a-sine-wave-with-a-microcontroller


using up the extra gates in a quad 74LVC86 would be nice. D flip flops  
let you easily make the phase-shifted square.

Re: Dirty sine wave generator
On 9/21/19 1:37 AM, bitrex wrote:
Quoted text here. Click to load it



Quoted text here. Click to load it

Quoted text here. Click to load it


Quoted text here. Click to load it

a 4 "step" sine will probably be fine. Don't really want to use more  
op-amp sections 1.8 volt CMOS amps with the bandwidth I need aren't that  
cheap relatively speaking. this is to go in a semi-disposable product I  
got a budget!!

Re: Dirty sine wave generator
On Saturday, September 21, 2019 at 1:41:55 AM UTC-4, bitrex wrote:
Quoted text here. Click to load it
ru
o

 a  

  

 like  
Quoted text here. Click to load it
  

uch  
Quoted text here. Click to load it
get
ust

 more  

Quoted text here. Click to load it
  
Quoted text here. Click to load it
.  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
g  
Quoted text here. Click to load it
ller>  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
  
Quoted text here. Click to load it
  
Quoted text here. Click to load it

Why would you need *more* op amps?  Every amplifier is also a filter... or  
can be.  

--  

  Rick C.

  -+- Get 2,000 miles of free Supercharging
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline