electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software
Turning triangle into a square signal using a comparator
Post new topic   Reply to topic Moderators: jksuperstar, Scott Stites, Uncle Krunkus
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
nschagen



Joined: Dec 11, 2021
Posts: 3
Location: Netherlands

PostPosted: Sat Dec 11, 2021 5:12 pm    Post subject:  Turning triangle into a square signal using a comparator Reply with quote  Mark this post and the followings unread

Hello Synth Enthousiasts,

I am building a VCO that should have a square wave output with PWM. I already have a circuit that creates a triangle wave (based on AS3340) and I would like to turn it into a square.

Before you tell me that the AS3340 can also output a pulse wave, I know this, but I am running into known issues with pitch stability when I change pulse width, so I rather build this myself.

So instead, I am using an opamp as a comparator. In my design one of the terminals connects to the triangle out and the other will see the PWM reference voltage controlled with a pot + CV.

However, the result I'm getting doesn't sound like a sharp square wave but instead it is a bit muffled. I have narrowed down the problem to the comparator, which is a TL074 bought in a German online-shop so hopefully its good quality.

In the video below, I will first send a square wave from a signal generator, through my comparator, which results in a nice looking and sounding square signal. When I change the signal to be triangle, the sound changes a lot and looses its high-end. You can also see a slow rising edge on the scope.

https://www.youtube.com/watch?v=mWvt0zL0xIo&t=2s

Does anyone know why there is a difference? I would expect the opamp to give a perfect square in both cases. The only reason they might sound different is because the input signals might cross the threshold voltage (other opamp terminal) at a different point in time, resulting in a slightly different pulse-width.

Thanks a lot in advance!
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24432
Location: The Netherlands, Enschede
Audio files: 297
G2 patch files: 320

PostPosted: Sat Dec 11, 2021 5:35 pm    Post subject: Reply with quote  Mark this post and the followings unread

hi nschagen and welcome

on the scope it looks like the comparator amplifies by some limited amount .. so it follows the tri wave for a bit ... does it have positive feedback?

Or better even, post the schematic for the comparator circuit.

Still it is pretty steep - amazed you can hear the difference Cool

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
nschagen



Joined: Dec 11, 2021
Posts: 3
Location: Netherlands

PostPosted: Sun Dec 12, 2021 4:17 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks for your reply!

I've added the circuit and a circuitlab output graph in the attachment.

In Circuitlab, I can also confirm the slow rising & falling edge. It takes ~0.025 miliseconds for the edge to rise to 12V and for it to go back to -12V later. This is much better performance than what I'm getting in my test circuit (an edge takes 0.25ms which gives distortion around 4Khz, clearly audible! Check my video) but still worse than what the datasheet suggests.

I just had a look at the datasheet, which says the TL074 has a slew rate of 13V per microsecond, meaning that the output can change by at most 13V per microsecond when input changes. It confuses me that it seems to take ~25 microseconds instead.

I have confirmed that I can fix the problem by adding another comparator in series with this one. However, I would like to know what is going on first and learn something Cool

Can someone shed some light on this?


comparator_circuit.png
 Description:
 Filesize:  10.63 KB
 Viewed:  124 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

comparator_circuit.png



slow_edge.png
 Description:
 Filesize:  82.41 KB
 Viewed:  115 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

slow_edge.png


Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24432
Location: The Netherlands, Enschede
Audio files: 297
G2 patch files: 320

PostPosted: Sun Dec 12, 2021 9:45 am    Post subject: Reply with quote  Mark this post and the followings unread

You run into non ideal behaviour of the opamp - applying positive feedback may better things up ... can't tell exactly what non idealities though - maybe someone else can.

https://www.electronics-tutorials.ws/opamp/op-amp-comparator.html

or use a real comparator device.

Some things that come up ...

The TL07x DC open loop amplification may be 125 dB, at 4 kHz it is just 62 dB (or about 1200) - so things at around 2 mV at the input result in full swings at the output.

The noise in the saw around the zero crossing may result in a muddy sound, as the "switch" point will shift in time by it.

Not sue what saturation of the output of the opamp really does - they are not really designed for that situation .. looked a bit at the TI specs, this seems to not fully explain things.

https://www.ti.com/product/TL071

It may be the add-upp of several effects.

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
nschagen



Joined: Dec 11, 2021
Posts: 3
Location: Netherlands

PostPosted: Tue Dec 14, 2021 2:19 am    Post subject: Reply with quote  Mark this post and the followings unread

I managed to solve my problem.

First, I had the incoming triangle signal connected to the non-inverting input and the PWM reference voltage to the inverting input. When I switched these around, the rising-edge-time went from ~200 microseconds to about 30 microseconds, giving a much richer sound.

I don't know why this asymmetry exists, but this is what worked for me. I could not replicate this with circuitlab so this might very well be a quirk of the particular opamp I have (TL074CN).

Thanks for your help Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: jksuperstar, Scott Stites, Uncle Krunkus
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use