Author Topic: Someone with a PIC and C compiler... run an envelope follower program for me?  (Read 7400 times)

ExpAnonColin

Hello,

I don't have a PIC compiler or programmer or development kit or really anything programming-wise where I am right now, but I have an idea for a program I'd really like to try out.  If anyone is willing, it would be awesome if I could write the source code up here (16f877 OK?) and have someone give it a go.

I've been playing with envelope followers for the past 3 days or so, have breadboarded maybe 10 or 12 designs.  I am using it to control the sample rate of an ADC, which is an excellent effect, but since it is controlling a frequency, ripple is ESPECIALLY apparent.  The only style I haven't tried is the insane henry bissel design (which looks awesome but is much too complex for the application), so I'm about fed up, and I don't want to give up and resort to a meatball/dr quack type (which is the best I have found so far).  So I was thinking about how to do it with a PIC, which seems pretty well suited.  Here's my idea.

First, there would be maybe a 10x or so amplifier (powered from 0 to 5V), feeding into one of the PIC's analog pins.  The pic would do the following, in pseudo-code:

var max = 0
var voltage

do forever
   do for 50 ms
      get voltage on analog input pin
      if voltage > max then
         voltage == max
   repeat
   put max on a port
repeat

So what it does is repeat a loop that finds the maximum voltage over a 50 ms (1/20hz) interval.  Then, it puts the voltage on a port (or a pin, I haven't decided...  8 bit isn't really enough so I may have it synthesize a frequency and put that through a LPF).  The port would either have to be put through a DAC of some kind (r/2r ladder probably).  Waiting for 50 ms gives us the full audio range, and I have found that I can't pick much faster than 100 ms or so so it would be sure to get every attack even at super fast picking speeds.  This would also prevent ripple of all sorts as the interval is longer than any audio frequency's period, AND there is no rectification involved which is where I find most of my ripple comes from.  The drawback being that the voltage would "step" every 50 ms but this is a low frequency so it shouldn't be noticeable... and through an LPF it wouldn't be a problem, we could easily smooth that out.

Any takers?  I am not the kind of guy who asks if something works before he tries it, rather I like to try it first, try to figure out why it doesn't work, THEN ask... but I don't have access to PIC programming right now so I need a favor.  If this works as I dream it will it will be a very simple, compact, fast, and ripple free envelope follower.

-Colin

RaceDriver205

Massive undertaking mate. You don't understand how PIC/AVR development works. You have to program it many many times trying to get it to work, it is not even remotely a case of "just typing this pseudo code up". You would probably need a DSP PIC to sample fast enough for reliable operation. If you want to experiment with PIC/AVR, you will need your own programming gear and knowledge of how it all works, thats just how it is.

ExpAnonColin

Massive undertaking mate. You don't understand how PIC/AVR development works. You have to program it many many times trying to get it to work, it is not even remotely a case of "just typing this pseudo code up". You would probably need a DSP PIC to sample fast enough for reliable operation. If you want to experiment with PIC/AVR, you will need your own programming gear and knowledge of how it all works, thats just how it is.

I'm sorry I was unclear - I've been programming PICs in C for quite a while, have made hundreds of programs, I am just on "vacation" right now and don't have access to a programmer/compiler/etc.  Yes, I absolutely agree that it takes quite a while to get the beast running, which is why I wanted to hear someone commit to working with me before I got all of the C code written up!  Though I've never written a program and had someone test it for me as such, I've definitely had people test breadboard circuits for me while I'm away from my stuff.  A useful learning experience for all involved.

-Colin

The Tone God

Does it have to be a PIC ? You really are using pseudo code which can go into and uC.

Andrew

ExpAnonColin

Does it have to be a PIC ? You really are using pseudo code which can go into and uC.

Andrew

No, any uC is fine, it is just that I'm most familiar programming on a PIC.

-Colin

The Tone God

This is pretty easy to do atleast on AVR with WinAVR. Is the delay cycle intended to simulate a cap ?

Andrew

ExpAnonColin

This is pretty easy to do atleast on AVR with WinAVR. Is the delay cycle intended to simulate a cap ?

Andrew

The delay cycle?

The Tone God

The 50ms delay you have in there.

Andrew

ExpAnonColin

The 50ms delay you have in there.

Andrew

Sort of, I was thinking of it moreso as something that simply found the highest voltage over a period of 50ms.  I haven't seen an envelope follower that utilized a cap in this way... in some ways it's like the cap in your standard sample and hold, except that this programs "samples" extremely fast, and "holds" the highest voltage.  So I guess it's sort of like a sample and hold, except instead of simply sampling every 50ms, it samples the highest voltage over the 50ms.

-Colin

The Tone God

That what I thought. And I presume you want to clear "max" every time it does the checking ?

Andrew

ExpAnonColin

That what I thought. And I presume you want to clear "max" every time it does the checking ?

Andrew

Quite right, after "put max on port" it should say "max == 0".

-Colin

The Tone God

Okay I have a good idea what you are looking for. What type of information are looking to be return ? Do you want to know if it works ?

Andrew

ExpAnonColin

Okay I have a good idea what you are looking for. What type of information are looking to be return ? Do you want to know if it works ?

Andrew

Essentially, yes.  Would you rather I write up the C code for a frequency output (for filtration) or putting it onto a port to be put into a DAC (1% R/2R ladder's probably the easiest)?

-Colin

The Tone God

Essentially, yes.  Would you rather I write up the C code for a frequency output (for filtration) or putting it onto a port to be put into a DAC (1% R/2R ladder's probably the easiest)?

I would probably throw it out on a PWM output pin and filter. I presume you want a nice smooth DC voltage and also you want the voltage on the output to be the same on the input.

I don't do PICs anymore. I'm an AVR guy so I don't know if our code would be compatible as from what I remember of PIC C compilers weren't very compliant.

Is this related to the ASM100/Pluck detection thread ?

Andrew

ExpAnonColin

Essentially, yes.  Would you rather I write up the C code for a frequency output (for filtration) or putting it onto a port to be put into a DAC (1% R/2R ladder's probably the easiest)?

I would probably throw it out on a PWM output pin and filter. I presume you want a nice smooth DC voltage and also you want the voltage on the output to be the same on the input.

I don't do PICs anymore. I'm an AVR guy so I don't know if our code would be compatible as from what I remember of PIC C compilers weren't very compliant.

Is this related to the ASM100/Pluck detection thread ?

Andrew

I could try coding generic C code and have you AVR-ify it if you're up for it.  I am getting an AVR dragon/STK500 kit (is it gone from Digi-key?) next month (probably going to try to switch to AVR myself) so that will give me experience doing that, but for now not so much. 

No, I didn't see that thread... just based on my envelope follower experimentations.

-Colin
« Last Edit: July 05, 2007, 02:59:29 PM by ExpAnonColin »

The Tone God

I could try coding generic C code and have you AVR-ify it if you're up for it.  I am getting an AVR dragon next month (probably going to try to switch to AVR myself) so that will give me experience doing that, but for now not so much. 

No, I didn't see that thread... just based on my envelope follower experimentations.

Ah it would probably take me 20 mins to write. The uC setup is the only really time consuming thing as I run through datasheets to set the control bits. If this is going to be a single input and output I can do it using a 8 pin uC like a Tiny13.

Do you want the output voltage the same as the input voltage ? Is the input voltage going to amplified ? Did you have a circuit in mind that you wanted use this in ?

Andrew

ExpAnonColin

I could try coding generic C code and have you AVR-ify it if you're up for it.  I am getting an AVR dragon next month (probably going to try to switch to AVR myself) so that will give me experience doing that, but for now not so much. 

No, I didn't see that thread... just based on my envelope follower experimentations.

Ah it would probably take me 20 mins to write. The uC setup is the only really time consuming thing as I run through datasheets to set the control bits. If this is going to be a single input and output I can do it using a 8 pin uC like a Tiny13.

Do you want the output voltage the same as the input voltage ? Is the input voltage going to amplified ? Did you have a circuit in mind that you wanted use this in ?

Andrew

I would probably amplify the input with a 10x inverting cmos op amp, to get 0-5v swing or so... it would be ideal if the output could go from 0 to 5v but any range is OK really as it can be fixed with a single op amp.  I would be using it to power an LED/H11F3 so an op amp buffer would probably be needed anyways!... so making it an amplifier/voltage offsetter is no big deal.

Seriously though, what happened to the dragon/STK500 package deal at digi-key?  I shouldn't have waited so long...

-Colin

The Tone God

I would probably amplify the input with a 10x inverting cmos op amp, to get 0-5v swing or so... it would be ideal if the output could go from 0 to 5v but any range is OK really as it can be fixed with a single op amp.  I would be using it to power an LED/H11F3 so an op amp buffer would probably be needed anyways!... so making it an amplifier/voltage offsetter is no big deal.

Well that makes life easier. I'll spit out what I get on the input that way people can figure out what they want as for signal levels. Want set the refresh time externally too ?

Seriously though, what happened to the dragon/STK500 package deal at digi-key?  I shouldn't have waited so long...

Looks like the sale is over. :(

Andrew

ExpAnonColin

I would probably amplify the input with a 10x inverting cmos op amp, to get 0-5v swing or so... it would be ideal if the output could go from 0 to 5v but any range is OK really as it can be fixed with a single op amp.  I would be using it to power an LED/H11F3 so an op amp buffer would probably be needed anyways!... so making it an amplifier/voltage offsetter is no big deal.

Well that makes life easier. I'll spit out what I get on the input that way people can figure out what they want as for signal levels. Want set the refresh time externally too ?

Seriously though, what happened to the dragon/STK500 package deal at digi-key?  I shouldn't have waited so long...

Looks like the sale is over. :(

Andrew

Man I feel stupid now, what a great deal that was.  Oh well, I will have tos ettle for just the stk500.

Setting the refresh time externally I think would be good for prototyping, but hopefully there will be a refresh time that just works.

-Colin

widdly

I've been thinking about this idea too.  I'd like to build a synth module that provide an Envelope follower, Gate and Trigger Signals and a Pitch-to-CV output.  I think it would probably need 2 PIC's, one for the follower, trigger and gate and a second for the Pitch-to-CV. 

You could take a look at Tom Scarffs Pitch-to-Midi converter for ideas on how to do the input section.  He has implemented it on PIC and his code detects peaks in the signal which is sort of similar to what you want to do.  http://tomscarff.tripod.com/pitch_midi/pitch_to_midi.htm
Looking at the Korg MS-20 pitch-to-CV, they have HPF and LPF before feeding the Pitch detector which would probably help the performance of this design.

For the output you can check out Tom Whiltshires LFO and Envelope projects.  He has implemented envelopes and lfo's using a PIC and uses a Low pass filtered PWM output to get a smooth 0v-5v. http://www.tomwiltshire.co.uk/sdiy/lfo.html