Tap Tempo LFO with PIC 16F684

Started by ElectricDruid, May 13, 2009, 05:22:13 AM

Previous topic - Next topic

ElectricDruid

Processaurus asked whether the LFO remains biased at 2.5V when you turn the depth down. Yes, it does, so your idea for inverting the waveform by inverting the PWM output would work exactly as you thought. Is it really much simpler than an inverting op-amp though?

Flo was asking about whether you could move the code to a 12Fxxx PIC. The 12F675 you mention has 4 A/D inputs, so that's good, but it doesn't have a PWM output module, so you wouldn't be able to get the output out of it without more substantial modifications and probably an external DAC or something. The killer might be program memory - the little 12F chips only have 1024 bytes, which isn't enough. It's not that the code is particularly long, but you need look-up tables for the control response and the waveforms, and those eat up some memory.

T.

flo


Processaurus

Quote from: ElectricDruid on December 17, 2009, 11:26:36 AM
Processaurus asked whether the LFO remains biased at 2.5V when you turn the depth down. Yes, it does, so your idea for inverting the waveform by inverting the PWM output would work exactly as you thought. Is it really much simpler than an inverting op-amp though?

Maybe not, I had just run into trouble in the past inverting analog LFO's with inverting opamps, from the DC bias being a little different or wandering as the depth knob was turned, so that there's a different DC value between the inverted and non inverted copies, that kind of thing, but those concerns might be out of place with this...  I was just excited because there was a bulletproof way to get the inverted copy without trimming anything, etc.


JKowalski

Just wanted to note...


Your filter design in the application notes might put off some people who want a voltage output without a large number of parts.

A simple two pole low pass filter is all you really need, IMO.

2x 1k and 0.1uF cleaned up the output perfectly, great resolution across the waveforms and speeds. Practically zero trace of the high sampling frequency.  Going higher than that, the square wave/sawtooth cliffs/random jumps became a little curved but that doesn't strike me as bad in any way.

:icon_biggrin:

flo

Quote from: JKowalski on December 29, 2009, 04:02:16 PM
A simple two pole low pass filter is all you really need, IMO. 2x 1k and 0.1uF cleaned up the output perfectly, ...
So you mean just two RC lowpass filters in series?
If not, do you have a schematic perhaps?

JKowalski

#45
Quote from: flo on December 29, 2009, 09:58:25 PM
Quote from: JKowalski on December 29, 2009, 04:02:16 PM
A simple two pole low pass filter is all you really need, IMO. 2x 1k and 0.1uF cleaned up the output perfectly, ...
So you mean just two RC lowpass filters in series?
If not, do you have a schematic perhaps?

Yeah, two passive lowpass RC filters.

Here's a scope view of the result:



The filter doesn't need to be very precise - with the sample rate at 20kHz and the LFO frequency range between <0.1Hz and 30Hz, you can get away with a pretty blunt filter. You just gotta make sure you don't start eliminating the sharper points of the wave (such as the square wave and sawtooth wave transistions) and the harmonics that lend the triangle and lump/sweep waveshapes their resolution. As you can see on the scope with 1k and 0.1uF, the sharp transistions are pretty much untouched by the filter - going any higher and you see a bit of sloping gradually start to come in to the 0-5 jumps.

The sample rate is something like.... 50dB down? Jump it to around 65 with another pole of you want... You'd have to see if it's good enough for the application... Make sure there's no bleed through but I think that it being at the total extreme of human hearing and the severe attenuation from the filter it won't be a problem.

flo


Processaurus

Nice waveforms! I bet in optical pedals, you could hook the PWM out right to the LED (if the PIC can supply the current, otherwise with a transistor driver), no filtering, because the response of LDRs is so slow it would filter out the jaggedies.

JKowalski

#48
Quote from: Processaurus on December 30, 2009, 10:21:55 AM
Nice waveforms! I bet in optical pedals, you could hook the PWM out right to the LED (if the PIC can supply the current, otherwise with a transistor driver), no filtering, because the response of LDRs is so slow it would filter out the jaggedies.

Oh definitely, I just cooked up an optical tap tremolo much like the one in the app notes Electric Druid provided. He discusses that option in the datasheet. Of course, optical kind of muddies up the waveforms a little bit (Turns the lump, sweep, sine, and triangle waves into something resembling the lump waveform, I scoped it using the LDR in a voltage divider) but it still works beautifully. In fact, since the LDR has a kind of exponential relationship, the volume sweep is probably much better for it because of how we hear exponentially anyways. If you looked at the sawtooths on my scope through the LDR/resistor voltage divider, it's a pretty good exponential curve. If you listen to the optical trem sawtooth sweep, it sounds pretty linear.

There's also the interesting effect where since the LED brightness is controlled not by the voltage/current but by the PWM, it is has a more linear brightness/LFO relationship, reducing distortion on that end. Also mentioned in the datasheet.


Finally just wanted to note that in the filter I was discussing, the bessel filter in the datasheet is a good option if you have room, I'm just saying that if you don't your not at loss. The two pole Bessel filter should provide about 100dB attenuation at the sample frequency, and it also buffers the output. There is one problem though, the first stage of the filter provides some measure of attenuation down to 30Hz... With my experience at the passive filter method, having the 6dB point at 1kHz (attenuation starting at 300Hz) is about the limit for keeping the waveforms nice and sharp. I would think the filter on your datasheet would be kind of brutal to the waveshapes coming out of the chip... It'd need to be scoped before decisions are made, though...

MoltenVoltage

#49
Those waveforms look really good, but how do they scale?

From what I can read, the rates you have pictured are between 5 and 16 hz.

I suspect that at a sweep of 2 seconds (0.5 hz), they wouldn't be as smooth, but I could be wrong.  One big factor when using lookup tables for sine waves, is the number of data points in your table.

I also wonder whether any PWM filter responds consistently across the useful LFO range (let's say 10 hz [.1 seconds] to .01 hz [10 seconds]).
MoltenVoltage.com for PedalSync audio control chips - make programmable and MIDI-controlled analog pedals!

flo

Another interesting LFO shape is the "hyper triangle" for slow phasers and flangers.
Are the "Sweep" & "Lump" meant for something that resembles a hypertriangled shape?

JKowalski

Quote from: MoltenVoltage on December 30, 2009, 02:29:22 PM
Those waveforms look really good, but how do they scale?
From what I can read, the rates you have pictured are between 5 and 16 hz.
I suspect that at a sweep of 2 seconds (0.5 hz), they wouldn't be as smooth, but I could be wrong.  One big factor when using lookup tables for sine waves, is the number of data points in your table.
I also wonder whether any PWM filter responds consistently across the useful LFO range (let's say 10 hz [.1 seconds] to .01 hz [10 seconds]).

I only did the fast waveforms (it was probably like 8Hz not 5, my scope doesn't recognize frequencies below 10Hz it just says "<10Hz" :icon_eek:) because I was testing the filter, and the most ciritcal part of the filter was to eliminate the sample frequency without messing up the LFO harmonics and resolution.

They are quite smooth, way down to 0.5Hz. Around 0.3Hz or so is where it becomes very slightly noticable on the scope, and getting even more lower than that it might get noticable audibly (in the 10 second LFO rates...?)

My optical trem pedal with the chip is not handy right now, but I will break it out when it is, slow it wayyy down and report back. I'd have to build a voltage LFO controlled effect first to see how it fares in that regard with the slow speeds...

Quote from: flo on December 30, 2009, 06:36:16 PM
Another interesting LFO shape is the "hyper triangle" for slow phasers and flangers.
Are the "Sweep" & "Lump" meant for something that resembles a hypertriangled shape?


Yeah the sweep and lump ones are the hypertriangle shape, normal and inverted. I would say it IS a hypertriangle rather than just a resemblance - the "hypertraingles" I have see look just like that, one half triangle one have sine waveish.

cloudscapes

speaking of waveshapes, say I want to create some of my own wavetables and I'm not terribly good at math. which software could I use to either import a wav or generate one on an easy-to-understand formula and convert it to a table of values?

I've already got tables for square, triangle, sine and saw, but I'm interested in making some of the funkier ones
~~~~~~~~~~~~~~~~~~~~~~
{DIY blog}
{www.dronecloud.org}

JKowalski

#53
Quote from: cloudscapes on December 30, 2009, 10:42:20 PM
speaking of waveshapes, say I want to create some of my own wavetables and I'm not terribly good at math. which software could I use to either import a wav or generate one on an easy-to-understand formula and convert it to a table of values?

I've already got tables for square, triangle, sine and saw, but I'm interested in making some of the funkier ones

Get a big sheet of graph paper and hand draw it out? It can't take tooooo long, right? Unless you have a zillion values. Besides, if the wave flips around then you only have to go through half of it  :icon_lol:

I can't think of any other way to do it without using math... I mean, for the computer to calculate the values on a curve you would need a mathematical formula for that line to give it first. To do what you want, you would need something that lets you draw out a curve and compute values on it and that sounds like a pretty specialized program with limited applications--the kind of thing your would make yourself for your own use.  :icon_neutral:

EDIT: Just an idea, if you have photoshop you could grid a square (with the PS grid overlay), draw out your waveshape with vector lines, and then use the ruler in photoshop with snap to measure all of the distances systematically on the line. Kind of the same thing as the pen and paper just on the computer instead which might make it a little easier on you.

For standard waves and whatever waves you can build with math, I would use a graphing calculator, draw it out, then hit the table function and read of all the values at each interval.


Just wondering, what kind of waves are you thinking about?

This chip has everything I would think you would ever need as far as waveforms - but the random waveform is not very useful for pedals, and maybe it could be replaced with something better. But I have been racking my brain trying to figure out what else would be worthwhile.

Triangle and sawtooth are faster calculated than looked up (as ED said on his site) so the only table you really need is the lump - because for the sweep, you just invert it, for the sine, you just double speed it and invert it on the second pass. I'm pretty sure thats how ED's chip does it but I would have to double check. That system I would think would give you nice resolution on all waves, and barely take up any space (just the hi res lump lookup table and that's it).

I suppose you could even only have HALF the lump wavetable, as you can read it forwards then backwards to give you the full waveform, and then etc.  :icon_lol:

Anyways the point of that was that if you think of any other kind of waveform that you think would be useful to have please share!


Quote from: JKowalski on December 30, 2009, 08:36:22 PM
My optical trem pedal with the chip is not handy right now, but I will break it out when it is, slow it wayyy down and report back. I'd have to build a voltage LFO controlled effect first to see how it fares in that regard with the slow speeds...

Just as a side note, I've played with the thing a ton recently and never had any scaling issues whatsoever while doing so. Couldn't hear anything in the slightest. I don't really use the super super super slow speeds, so I can't vouch for that at the moment, but I think theres a point where the speed is just not usable anymore and I think the chip doesn't become badly scaled before that point is reached.

Processaurus

Just had a thought, the pwm output could be a boon as far as interfacing with analog effects: with the pwm output, you could hook it directly (or through a logic buffer running at the effect's full supply voltage) to a 4066 for a pulse width controlled variable resistor, by putting the max resistance value you want across the switch.  For PWM'd pot, you could use a 4053 in a similar arrangement, tie identical resistors (both equal to the value of the pot) from the common to each throw.  Then filter the audio to get rid of the hi frequency artifacts at the end.

Provided the PWM'ing is fast enough to be filtered out without wrecking the audio, you could make a phaser with a jillion stages pretty easily, or replace a pot in any non LFO effect.

JKowalski

Quote from: Processaurus on December 31, 2009, 10:32:43 PM
Just had a thought, the pwm output could be a boon as far as interfacing with analog effects: with the pwm output, you could hook it directly (or through a logic buffer running at the effect's full supply voltage) to a 4066 for a pulse width controlled variable resistor, by putting the max resistance value you want across the switch.  For PWM'd pot, you could use a 4053 in a similar arrangement, tie identical resistors (both equal to the value of the pot) from the common to each throw.  Then filter the audio to get rid of the hi frequency artifacts at the end.

Provided the PWM'ing is fast enough to be filtered out without wrecking the audio, you could make a phaser with a jillion stages pretty easily, or replace a pot in any non LFO effect.

Thats a neat thought!

You need a good sharp filter, though. 19kHz is on the very very edge of human hearing.

flo

#56
Like in the MXR Envelope Filter:
http://www.tonepad.com/project.asp?id=4
http://www.generalguitargadgets.com/pdf/ggg_mxr_envelope_filter.pdf

Is the PWM frequency fixed to 19kHz because it is directly related to the clock frequency of the PIC, or can it be run even faster?

JKowalski

Quote from: flo on January 01, 2010, 04:36:37 PM
Like in the MXR Envelope Filter:
http://www.tonepad.com/project.asp?id=4
http://www.generalguitargadgets.com/pdf/ggg_mxr_envelope_filter.pdf

Is the PWM frequency fixed to 19kHz because it is directly related to the clock frequency of the PIC, or can it be run even faster?

The PWM module on the PIC16F684 is limited to a 20kHz maximum sampling frequency, I suppose that's what stopped Electric Druid from going any further  :icon_eek:

He's also running the clock at it's limit too (20MHz)

Im starting to feel like I am him now! I think he's the sensible one here and is having a nice relaxing and/or fun holiday without thinking endlessly about electronics  :icon_lol:

MoltenVoltage

Quote from: JKowalski on January 01, 2010, 09:36:03 PM
The PWM module on the PIC16F684 is limited to a 20kHz maximum sampling frequency, I suppose that's what stopped Electric Druid from going any further  :icon_eek:

He's also running the clock at it's limit too (20MHz)

At 20MHz the PWM frequency can be as high as 208.3 kHz, but the resolution drops from 10 bits to 6.6 bits (don't ask me how they calculate 6.6 bits?!?)

See page 83:
http://ww1.microchip.com/downloads/en/DeviceDoc/41202F-print.pdf

You have to decide whether the higher frequency or sample rate is more accurate with your PWM filter by doing some experiments.

Quote from: JKowalski on January 01, 2010, 09:36:03 PM
Im starting to feel like I am him now! I think he's the sensible one here and is having a nice relaxing and/or fun holiday without thinking endlessly about electronics  :icon_lol:

Thinking endlessly about electronics IS relaxing!
MoltenVoltage.com for PedalSync audio control chips - make programmable and MIDI-controlled analog pedals!

JKowalski

Quote from: MoltenVoltage on January 01, 2010, 10:47:03 PM
At 20MHz the PWM frequency can be as high as 208.3 kHz, but the resolution drops from 10 bits to 6.6 bits (don't ask me how they calculate 6.6 bits?!?)

Hahaha, that is quite interesting! They have a fancy log equation to calculate it, and for some reason they put 23 into it on that last one when complete bits can only be calculated using 2^n...? I do not know why.

Quote from: MoltenVoltage on January 01, 2010, 10:47:03 PM
Thinking endlessly about electronics IS relaxing!

I suppose it is! :icon_lol: I do catch myself daydreaming about them every day!