News:

SMF for DIYStompboxes.com!

Main Menu

Give me a sine

Started by Kevin Mitchell, May 12, 2020, 12:20:38 PM

Previous topic - Next topic

Kevin Mitchell

I'm looking for a template circuit for a single supply sine wave generator. I need 40kHz at 0.35Vrms to 1.5Vrms. These are typical input signal frequencies for our beloved BBD devices such as the MN3207 and MN3007.

I've been looking at wien bridge oscillators. Figured I'd dispatch the help signal before I slide down the wrong path in my quest of a simple wave generator.

Hope everyone's doin' alright!
-KM
  • SUPPORTER

Mark Hammer


Kevin Mitchell

Thanks, Mark. Trying to simulate it with a simple triangle generator (I think from the tremshifter) and not really getting anything. Of course that's an LFO circuit (only maxing out at ~70hz) and I'm assuming it would still smooth out the edges.

-KM
  • SUPPORTER

Kipper4

Have you tried a PSO ? Doesn't get much much more simple in terms of parts.
Ma throats as dry as an overcooked kipper.


Smoke me a Kipper. I'll be back for breakfast.

Grey Paper.
http://www.aronnelson.com/DIYFiles/up/

Scruffie


Kevin Mitchell

I have not tried any phase shift oscillators for this. But I'll give it a thought!

Scruffie saves the day. I had considered that one as I've breadboarded it a few times. Didn't realize it stemmed from a simple wien bridge. I'm having a hard time getting the simple design in the introduction working in simulation. Going to try it on the work bench.

-KM
  • SUPPORTER

ElectricDruid

Why do you need a 40KHz sine if you're testing a BBD that's designed to pass *audio*? If you run a 40KHz sine into a BBD, you'll get aliasing distortion and some weird result that doesn't look like the input at all, unless you get the clock frequency up over 100KHz or so.

Am I missing something important as usual?  :icon_confused:


Kevin Mitchell

Na you've got me. But I'm trying to get a visual understanding of these devices while I've got something on breadboard. I didn't consider slow clocking distortion which is important because I'm clocking them around 10kHz. But I'd certainly learn that along the way. I've been reviewing the datasheet and trying to send apropriate signals through the devices.

With the other project I've got going I've been sending high pulse signals to the input and monitoring the output while using a comparator to detect the result of the high pulse showing up as the output. While it works okay I had the thought it may be better to send an appropriate/datasheet suggested signal through the devices.

For the sake of experimenting really. I'm more inclined to believe that I'm misunderstanding something  :icon_lol:

I need a signal generator to play with anyhow.

-KM
  • SUPPORTER

Sooner Boomer

Quote from: Kevin Mitchell on May 12, 2020, 06:12:06 PM
I need a signal generator to play with anyhow.

-KM

What about using one of the Exar chips, say the XR-2206 or the XR-8038? Inexpensive, versatile, easy to implement with minimum components.
Dan of  ̶9̶  only 5 Toes
I'm not getting older, I'm getting "vintage"

imJonWain

I built the Valve wizard one and am really happy with it for a <30min veroboard build.
  • SUPPORTER
TFRelectronics

DrAlx

#10
Quote from: Kevin Mitchell on May 12, 2020, 06:12:06 PM
With the other project I've got going I've been sending high pulse signals to the input and monitoring the output while using a comparator to detect the result of the high pulse showing up as the output. While it works okay I had the thought it may be better to send an appropriate/datasheet suggested signal through the devices.

Is the other project the Arduino based BBD stage counter?
If so have you considered generating both the sine wave and bias level with the Arduino?

Don't know if this would work, but my thinking is this...


The Arduino could output a DC level for bias between 0.2V to 0.8V, that could be scaled up by factor of 10 by an external op-amp.
To hunt for the best bias level you need a reference signal added to that bias, so let the Arduino
create a sine wave of fixed period (1 ms for example) and fixed amplitude (say 0.1V pk-pk) and add it to the bias level.

So the Arduino would output a voltage that is a 1ms period sine wave of amplitude 0.1V centred on a DC bias between 0.2V and 0.8V.
An external op-amp scales all of that up by factor of 10 to give a sine wave that is 1V amplitude with bias between 2V and 8V.

For a fixed bias level, to measure how much of that signal goes through I would use homodyne detection.
i.e. Multiply (in code) the reference sine wave value centered about 0  (i.e. a value between -1 and +1)
with the measured BBD output voltage (or a scaled version of it to stop blowing up the Arduino input).
Note that you don't need to worry about the bias level at the BBD output, so a simple resistive divider to ground will suffice to scale down the voltage for measurement.
Call the result of that multiplication (i.e.  sine wave value * measurement value) "Y", and average the "Y" values over a 1ms period and call that sum "Z".
So "Z" is a running average of the "Y" values over the last 1ms of time.
"Z" is a measure of how much 1ms sine wave is contained in the BBD output signal.
So bias is optimum when "Z" is maximum. 

The nice thing about this method is that you don't need to worry about the BBD delay nor the bias level at the BBD output.
You just need to run the input signal long enough until Z has stabilised.  If the maximum possible BBD delay is 1 second then just over a second would do it.

You just repeat this procedure in the code using different bias levels and pick the best.
The number of steps it takes Z to reach its final level also gives you an estimate of the stage count.


EDIT:  Actually I got this wrong (it's been a long time since I did this stuff).  For homodyne to work the sine waves have to line up in time or else Z gives you a measurement of the phase difference.
So some other way of measuring sine wave amplitude at the output (e.g. looking at min and max levels at the BBD output within a 1ms window) would be better.  BBD delay wouldn't matter so long as you run the input signal long enough for something to appear at BBD output.
So if the maximum possible BBD delay is 1 second then just over a second would do it, and look at the min/max BBD output levels in the last ms to get a measure of sine wave amplitude.


EDIT2:  Just realised the Arduino only has PWM outputs. I wrongly assumed it had a DAC like Arduino Due.  So the above suggestion would probably not work without a lot of filtering as the BBD would give heterodyne noise with any PWM input signal passed to it.

amz-fx

The 17th fret of the high E string on a guitar is 880 Hz, so a 1k Hz signal can cover the high end of a guitar. I typically use 200 Hz as a test signal since it is in the middle of the guitar range... close to the Ab on the G string at the 1st fret.

I use 200 instead of 220 Hz since the harmonics fall directly on the frequency grid lines of my audio analyzer and are easy to see.

regards, Jack

Kevin Mitchell

#12
Thank you for your responses!

Yeah it's for the BBD tester. It's a very simple concept - send a signal to the input and start the counter (1 click per clock pulse) and stop the counter when the signal shows up at the output. Since the input bias varies between devices the output doesn't always spit out the same result. This seems to be an implication for the comparator. I thought it would be more appropriate to send a sine wave through the device and see about converting that into a logic high signal - armdnrdy did this with a half wave rectifier & switching transistor after a mixing node for his tester. Sadly his project got lost when the dropbox disabled all public folders.

DrAlx, thanks for your thought! I do believe the microcontroller (ATMEGA328P) has 8 analog pins and some of the digital pins can be enabled for analog functions such as the comparator. I also have experience using external DACs with these chips. That was for a keyboard controller (matrix scanner with CV outputs, DAC & amplifier to cover a 5 octave range). But I'm more drawn to an external signal generator. I'm mostly relying on the microcontroller to supply the clock signals, count clicks and drive a 4 digit display - it's more economical than 4 CD40110 drivers in Larry's project.

For all of this I'm not really worried about timing and have neglected giving it thought. Timing is irrelevant as long as the output signal is well enough to be detected which shouldn't be much of a problem clocking at 10kHz. Or I'm wrong that's the problem I'm facing.

Another thing - am I misinterpreting the BBD's datasheets thinking it's expecting a 1kHz to 40kHz input signal?

-KM
  • SUPPORTER

DrAlx

#13
Quote from: Kevin Mitchell on May 13, 2020, 10:34:51 AM
Another thing - am I misinterpreting the BBD's datasheets thinking it's expecting a 1kHz to 40kHz input signal?

10 kHz clock is the minimum on the datasheet for the MN3207.  I've not gone that low.

When I see 40kHz in the MN3207 datasheet its always refering to  fCP (i.e. clock frequency) rather than fI (input frequency)
One of the graphs for insertion gain in that datasheet has audio going above 40kHz too, but that's only for a curve where fCP is 100 kHz.

I would use an input signal of a few hundred Hz to 1 kHz.  Make sure its lower than 1/3 of your clock frequency.


Regarding sine wave: Looking online for Arduino code to generate a sine way only throws up a way of doing something using the digital outputs and PWM.

EDIT:  See this:
https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

So I am thinking, why use a 1kHz sine wave test signal when the Arduino can give you a 490Hz (or 980Hz) square wave test signal instead?
i.e. make use of the fact that the PWM output is a wave and has the right sort of frequency.
You don't need to have a sine wave for a test signal, just a regular waveform (sine/square/triangle).  Looking at the min/max levels coming out the BBD over a suitable period will tell you how much of that wave made it through the BBD.

ElectricDruid

+1 agree with Dr Alx.

I'd add that you shouldn't forget you've got ADC inputs on the Arduino. You could sample the output with the ADC at the same rate you clock it, and then you'd be able to see whatever bias level was coming through the chip before the signal arrived. Once you know that, it's easy enough to remove it when the actual square wave turns up.
Basically, "Have you thought about doing the comparator in firmware?" is what I'm asking. It might be easier. It'd certainly be more flexible.

Kevin Mitchell

#15
Wow thanks guys! Brilliant ideas.

Right now the micro's comparator is set with a reference voltage via an external divider.

I'll send a refined pulse and scope the in and out. From there I'll see what I can do to automate the comparator threshold.

Must keep in mind - the basic DAC & ADC functions take up a good chunk of time and will muck up the clock. Perhaps something that could be alleviated through more advanced programming if it shows to be an issue.

-KM
  • SUPPORTER

Kevin Mitchell

#16
Some thoughts...

With an input frequency of 1/10th of the clock frequency (let's say 1kHz In and 10kHz CP) we would see the high input pulse every other 10 clock cycles, 10 on and 10 off. Since I'm relying on the 1st appearance of the signal I'm wondering why the input frequency would even matter in this scenario. The reason for this post was to create an input signal that is appropriate for the BBD so I can see these devices run happily. But since we're not critiquing for audio purposes I believe the input frequency is not a major factor as only the input bias and output level are our applicable variables. I'm hoping someone can elaborate if I'm missing something here.

I totally get using the ADC input to set the comparator threshold while the input pulse is inactive and I think that's a great idea in theory. I only need to test it.

-KM
  • SUPPORTER

DrAlx

When you mentioned sine wave input i assumed you were looking to find optimum bias level.
If you don't care about bias and just want to measure delay time, then all you need to do is compare the case when the input voltage level is 0 to the case when the input voltage level is Vdd.
One will give "low" BBD output voltage and the other "high".
Make that transition from 0 to Vdd at BBD input and see how long it takes for there to be significant change in BBD output level from "low" to "high".

ElectricDruid

Quote from: DrAlx on May 14, 2020, 04:23:24 PM
When you mentioned sine wave input i assumed you were looking to find optimum bias level.
If you don't care about bias and just want to measure delay time, then all you need to do is compare the case when the input voltage level is 0 to the case when the input voltage level is Vdd.
One will give "low" BBD output voltage and the other "high".
Make that transition from 0 to Vdd at BBD input and see how long it takes for there to be significant change in BBD output level from "low" to "high".

I broadly agree with the Learned Doctor, but I'd add that the input signal levels need to be a bit more moderated than that. I found running a MN3207 on 5V that the chip clipped at 2V input, so only about 40% of the supply voltage. It's possible/probable that varies a bit with supply voltage level but it's definitely a long way off 100%. Still, perhaps the Dr is right; if you don't care about the audio quality, you could heavily clip the signal and it wouldn't matter. The problem comes if something weird happens with signals that are that far outside the normal range. Still, his point stands - you use a simple binary input of a "low" level somewhere below the typical bias level and a "high" input somewhere above it. It doesn't even need to be a square wave, really. The chip just stores *voltages*, so we can feed it DC if we want to. We just better clock it fast enough before it all fades away!

My suggestion with using the ADC to measure the output before the signal arrives was not really to tell you what level to use to set the comparator. Instead, the ADC can *replace* the comparator. You start clocking the chip, with the input held "low" (however that is defined and however low you choose to go). While this goes on, you can measure the output with the ADC. That's your base level. Then you send your "high" input and start counting clocks. For each clock, you read the ADC result and see if it's within some threshold of your base level. When it's suddenly *not*, you know the high pulse has reached the other end and whatever the count is at that point is your number of stages. No comparator needed (only a far *more* sophisticated ADC!).

anotherjim

Arduino does have a Tone function. Just tell it the pin and frequency in Hz. Square of course. If a fixed frequency will do, you could turn the output into a differentiated "saw" with a simple CR filter (which you will have anyway using the coupling cap). That might be easier to work with since only the leading edges are vertical.
https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/