Go Down

Topic: PWM to control Oscillator (Read 1 time) previous topic - next topic

diegosynth

Dear everyone,

First of all, thank you in advance for reading this, and big apologies for being so undereducated in the subject. I have an IT background and I'm trying to learn electronics by myself...somehow.


Introduction:
--------------

I have been experimenting a little bit with oscillators lately (for musical purposes). After putting together a reverse cascade oscillator and a 555 I am playing now with a CD40106 hex inverter getting similar results (positive ones).


Current Situation:
-------------------

My goal here is to digitally control the frequency of the oscillator, for which I understand I need to replace the resistor in the circuit for a variable something.

My first idea was making an arduino (PWM) controlled VACTROL. It worked. But I believe the changes in brightness lead to a bit of legato effect, and the resulting notes sound off.

I sort of decided that the VACTROL was not a very precise solution, so I thought of directly using PWM to variate the thing. Straight from arduino's PWM pin didn't work, so adding a couple resistors before the inverter's input did the trick. BUT i get a very short range of frequencies (at least I would need 2 octaves). I tried for about 2 hours plenty of combinations of resistors in series, parallel, even with capacitors somewhere there... Both between the PWM and the inverter input, and between the inverter's input and output (diagram attached).




Questions:
-----------

Do I probably need to amplify the PWM signal somehow? Do I just need to find the proper resistance value? I'm honestly shooting in the dark here, apologies for this.

(note: I have already increased arduino's PWM resolution to 10 bits, mode 7 - credit to the code's author here in the forum).

Thanks a lot,
Diego

TomGeorge

#1
Apr 01, 2020, 12:56 pm Last Edit: Apr 01, 2020, 12:57 pm by TomGeorge
Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.

What range of frequencies are you working with?

Have you looked at the tone function in the Arduino software to produce directly the frequency you require?
https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

diegosynth

Hello Tom,

thanks for the answer and the info, have just read the link you shared!

The frequency range could be between 32 and 131 for example. Or between 65 and 262. It can even be higher, but in general about these hundreds (normal piano frequencies).

I haven't tried generating the tone itself in Arduino as I would prefer a more analog and modular approach, but I don't completely discard the idea. Arduino has being super helpful so far, but I also feel that going a bit more analogue it's also good for learning.

Diego

herbschwarz

Try a Top Octave Generator IC for a musical octave output.
 

wolframore

555 can be used to build a voltage controlled oscillator(VCO)

What are you using to listen (assuming you're doing that since you mentioned audio). 32 Hz is not easy to recreate using tiny Arduino sized speakers.

I would go higher it would be easier 1320-3960 without extra equipment.

There are number of ways to create a VCO.  Arduino is pretty easy using tone()
Bad Boys Race Our Young Girls But Violet Generally Wins - Get Some Now :) - ELI ICE man

diegosynth

#5
Apr 01, 2020, 08:46 pm Last Edit: Apr 04, 2020, 03:14 pm by diegosynth
Thanks guys:

Top Octave IC would come handy later, but seems to be impossible to find / prohibitive prices.


Still, I'll try to briefly explain again:

I have a working oscillator which gives very good frequencies. I just need to control the frequencies programatically with Arduino.

PWM + VACTROL = good frequency range, bad note switching / notes off key (because of "glide")
PWM + resistors = very short range (4 notes?), notes sounding properly (switching immediately)


(I can record audio / post photos / whatever required)

Wawa

PWM + resistors = very short range (4 notes?), notes sounding properly (switching immediately)
Mod player example.
Leo..

Grumpy_Mike

Quote
I tried for about 2 hours plenty of combinations of resistors in series, parallel, even with capacitors somewhere there... Both between the PWM and the inverter input, and between the inverter's input and output (diagram attached).
Total waste of time, I am not sure what you expected but any form of filtering is just going to get zapped out of existence by the DIGITAL inverter.

What were you hoping it would achieve?

The PWM when filtered can give you an analogue voltage level, you need then to apply that to a voltage controlled oscillator.

TomGeorge

Hi,
It sounds like you are trying to make an "old" school synthesizer with digital controls.
The filters and oscillators and sweep generators are all analog but controlled by a digital controller.
This would then make your compositions save-able to say a SD card or PC?

Tom.... :)
Everything runs on smoke, let the smoke out, it stops running....

diegosynth

It sounds like you are trying to make an "old" school synthesizer with digital controls.
yes. At first I'm trying to make small independent modules that I can connect / disconnect:

- 1 module = VCO (with hex inverter I have 6 oscillators = cheap & convenient)
- another module later = filter
- another module later = envelope
- etc

All my musical stuff is mainly digital, so I don't have an analogue controller. That's why I went for Arduino to create one.


Total waste of time [...] any form of filtering is just going to get zapped out of existence by the DIGITAL inverter. [...] The PWM when filtered can give you an analogue voltage level, you need then to apply that to a voltage controlled oscillator.
I was waiting for you, took you a bit long though. I see a contradiction there in what you say. I previously tried with your filter from your website and it didn't work. Best I got is a nice fat bass sound.

My VCO is the hex inverter. It oscillates, and it can be controlled by voltage.
The time I spent is probably a waste of time in your eyes. But instead of complaining why don't you try explaining to me what is happening in the circuit and maybe how to proceed? I don't have the education  nor the knowledge you have, that's why I'm here.

What I expect is to understand why if I use a led + a LDR I get a proper signal that would give a nice range of frequencies, but if I use the signal straight from the PWM it will only give me a narrow range. I understand the signal comes in a pulse train out from the PWM and that is not the same as what an LDR outputs. That's why I went to your site and tried with the filter. But maybe I did it wrong, or maybe it just won't solve my issue, I don't know.

Thanks and apologies.
Diego

herbschwarz

Have you considered the CMOS 4046? It is a Phase-locked
loop chip that contains a voltage to frequency converter,
also known as a voltage controlled oscillator. Check it
out. It may be what you are looking for.
Herb

Grumpy_Mike

#11
Apr 08, 2020, 07:35 am Last Edit: Apr 08, 2020, 07:37 am by Grumpy_Mike
Quote
My VCO is the hex inverter
While you can make an oscillator from a Schmitt-Trigger Inverter, a feed back resistor and capacitor to ground there are two big problems.

1) You have a 12V supply which means a 12V output, but you are only changing the voltage from 0 to 5V with the Arduino. That will limit the amount of pull you can get on the frequency of the oscillator. Also it will subject the Arduino to a 12V signal on it's output pin. The reason why this has not killed the Arduino yet is probably that the resistors in the coupling and filtering are acting as a current limit to the internal ESD diodes on the processor's pin.

2) Your plan to make six oscillators from this chip will not work because the oscillators will interact with each other. That is a change in the frequency in one will cause a small change in frequency of all the others. This is because there is no supply decoupling inside the chip. Even using two such oscillators on one chip is too much to allow them to operate independently. This is a digital chip, and while you can pull analogue stunts like this, the chip was not designed for doing so. It is also highly likely that an other manufacturer's chip will behave differently.

wolframore gave you the right answer in reply#4, use a NE555 for each oscilator.

wolframore

Ahh I get it.  The old 40106 hex inverter oscillators.  They were originally used because they cost less than opamps and have a similar output with inverting input.  They will give you the classic sound.

These days opamps are so inexpensive you can build the whole thing out of TL072s or similar for the same price or less.

You should use the hex inverters if you want that old school sound.

The glide should be possible in Arduino but that's a lot of math and data for something done simply in analog.

I spent hours today getting something to act analog today in code. In the end I won.

That 4046 looks like a fascinating chip.

One of these days I would love to build a synth based on a Wien bridge oscillator for pure sine tone, it would be a lot of fun with integrators and filters...

Just do it.

It can be done.

Bad Boys Race Our Young Girls But Violet Generally Wins - Get Some Now :) - ELI ICE man

herbschwarz

A pure sine wave is the flute sound, no harmonics.
Filtering that can only decrease the signal amplitude.
You would need to add distortion (harmonics) to
be able to get other voices
Herb

wolframore

you start with a sine wave, put it through comparator to generate square wave, then integrate for triangle, those are the three basic waveforms... it's possible to add sawtooth to that list.  Clean sine wave through filters affects the amplitude as frequency changes. 

The non-sinusoidal with complex harmonics have more dramatic effect through filters.

Bad Boys Race Our Young Girls But Violet Generally Wins - Get Some Now :) - ELI ICE man

Go Up