DIYstompboxes.com

DIY Stompboxes => Digital & DSP => Topic started by: midwayfair on October 24, 2014, 02:50:08 PM

Title: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on October 24, 2014, 02:50:08 PM
Something without the tap tempo, clock input, step etc., and without as many pins?

I realize I can just not use most of the TAPLFO pins, but I'm looking for something in 8 pins preferably to save PCB space. I know there's a tap tempo chip in 8 pins, so it doesn't seem absurd to think that something could be done with an LFO.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: cloudscapes on October 24, 2014, 03:29:57 PM
What features would you be after?

Only 4 pins would be available for an 8 pin device. 2 for power, and 2 for the crystal, not always needed, but for time sensitive stuff it kind of is.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on October 24, 2014, 03:39:57 PM
Quote from: cloudscapes on October 24, 2014, 03:29:57 PM
What features would you be after?

Only 4 pins would be available for an 8 pin device. 2 for power, and 2 for the crystal, not always needed, but for time sensitive stuff it kind of is.

I can't see any way the crystal wouldn't be required.

Rate, depth, and sine/triangle/square wave forms, or if possible potentiometer control over the hardness of the wave that pans from sine CCW to square CW. The last pin is of course the PWM output (I have no hope of getting an analog output 8 pins, I suppose ...).

I'm willing to hire someone for this if the chip can be offered as part of a project. :)
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on October 24, 2014, 03:56:41 PM
Doing it with a PIC you'd probably be limited to two pots if it needed a crystal, as one of the pins (MCLR) is generally a digital input only, so you've only got two free analogue inputs to use for the pots. That's not too bad though because depth could be implemented outside of the chip.

A hardness control should be doable or even a pan from tri through sine to square.  
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on October 24, 2014, 04:26:12 PM
Quote from: slacker on October 24, 2014, 03:56:41 PMThat's not too bad though because depth could be implemented outside of the chip.

I'm not so sure. I need to be able to invert it with a PNP (and an NPN buffer for the in-phase), and I don't think there's a reasonable way to do that without adding so many devices that it's not better to just use the TAPFLO again.

In which case ... rats. I'm not totally sure it's really worth doing if it's just rate and depth.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: loylo on October 25, 2014, 04:31:44 AM
You may start working from this:
http://www.sabrotone.com/?p=3992
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on October 25, 2014, 09:01:45 AM
Quote from: loylo on October 25, 2014, 04:31:44 AM
You may start working from this:
http://www.sabrotone.com/?p=3992

If I'm reading the datasheet right, it has three analog-to-digital pins, but two of them would normally be used for the crystal?

http://www.atmel.com/images/atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet.pdf
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on October 25, 2014, 10:05:52 AM
Yeah that's what it looks like, for a lot of applications you don't need a crystal though so it's not as daft as it first looks.
A crystal is only needed when you need accurate and stable timing or if you need to run the chip faster than its internal clock will allow or you need to run it at some specific frequency you can't generate internally.
In the TAPLFO for example Tom is probably using a crystal to get the maximum possible speed from the chip and maybe to get accurate enough timing for the tap tempo. For a non taptempo LFO the inbuilt clock is accurate enough, it might drift a bit with temperate or voltage changes but no worse than an analogue LFO would.  

I've got a few 8 pin PICs around, I'll have a crack at making something.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on October 25, 2014, 01:04:27 PM
Quote from: slacker on October 25, 2014, 10:05:52 AM
Yeah that's what it looks like, for a lot of applications you don't need a crystal though so it's not as daft as it first looks.
A crystal is only needed when you need accurate and stable timing or if you need to run the chip faster than its internal clock will allow or you need to run it at some specific frequency you can't generate internally.
In the TAPLFO for example Tom is probably using a crystal to get the maximum possible speed from the chip and maybe to get accurate enough timing for the tap tempo. For a non taptempo LFO the inbuilt clock is accurate enough, it might drift a bit with temperate or voltage changes but no worse than an analogue LFO would.  

I've got a few 8 pin PICs around, I'll have a crack at making something.

That's very kind of you! Thanks :)
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on October 29, 2014, 05:08:41 PM
I've made a start, using a PIC 12F683 running at the highest internal clock speed of 8Mhz you can get an 8 bit PWM output at 20Khz, this compares to 10 bit in the TapLFO at about the same frequency due to it running at 20Mhz. The question is whether 8 bits is enough to get a usable waveform or will it be too obviously stepped.
If it's no good that might scupper the project because to get more bits either means lowering the PWM frequency and you can't go much lower without getting into audio frequencies or adding a crystal and then you've only got two pots as discussed earlier.

I don't know if there's any small AVR chips that might do better, no experience with them.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on October 30, 2014, 01:13:04 PM
Slacker, I think you've already gone way above and beyond. Thanks very much for your time. :)
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: electrosonic on October 30, 2014, 05:13:11 PM
Quoteyou can get an 8 bit PWM output at 20Khz

I think the 20kHz might be overkill = not that that's a bad thing. A reasonably fast LFO  has a period of say 1/10 of a second. A single period of that LFO would have 2000 samples at 20kHz.

Put another way - you are updating the LFO every 50 microseconds. Do you think if the LFO was updated instead every say 1mS you would hear the difference -especially if you are driving a relatively sluggish LDR.

I am the process designing a tap tempo tremolo of my own so I have been considering these issues lately.

Andrew
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on October 31, 2014, 02:43:41 AM
An 8 pin uC LFO sounds like a nice project.

Quote from: slacker on October 29, 2014, 05:08:41 PM
The question is whether 8 bits is enough to get a usable waveform or will it be too obviously stepped.

If it's a problem, you might be able to get around it using dithering.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on October 31, 2014, 08:45:51 AM
Quote from: electrosonic on October 30, 2014, 05:13:11 PMPut another way - you are updating the LFO every 50 microseconds

Jeez, I read this quickly last night and thought it said "milliseconds." I know we can't detect latency below 500uS, and I'm 100% certain that even the fastest LDRs can't react faster than some number of milliseconds, so 50uS seems more than fast enough.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on October 31, 2014, 01:05:15 PM
Quote from: midwayfair on October 30, 2014, 01:13:04 PM
Thanks very much for your time. :)

No problem Jon, I haven't got any projects on the go at the minute, so I'm quite happy playing with this.

Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on October 31, 2014, 01:26:00 PM
Quote from: electrosonic on October 30, 2014, 05:13:11 PM
Do you think if the LFO was updated instead every say 1mS you would hear the difference -especially if you are driving a relatively sluggish LDR.

Yeah you're right there's no need to update the waveform at 20Khz, this would be done at a much slower rate. The reason for running the PWM as fast as possible is that it generates a tone at whatever frequency it's running at, so it's a good idea to get it above audio frequencies. If you ran the PWM at 1Khz (1ms period) then you risk this bleeding into the audio path.

Quote
Quote from: slacker on October 29, 2014, 05:08:41 PM
The question is whether 8 bits is enough to get a usable waveform or will it be too obviously stepped.

If it's a problem, you might be able to get around it using dithering.

Thanks. I'll look into that. I've since had a look and there are more powerful 8 pin PICs available, never looked at them before because I've not needed to. They could easily do 10 bits so I'll probably go down that route. As is often the way with these things they're actually cheaper than the one I'm using now.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: g_u_e_s_t on October 31, 2014, 08:40:19 PM
the attiny85 has an internall pll that can clock the internal 8MHz oscillator up to 64MHz.  unfortunately it only has an 8b counter for the PWM.  if you need more depth, and you might not, there are 2 options.  1. use dual pwm - this takes up a second pin, but that still leaves 4 ADC inputs free.  2. average over time - this would take up a fair bit more computation, but you could effectively get 10b or 11b this way.  the attiny13 also isnt bad, but doesnt have the pll.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on November 17, 2014, 04:07:48 PM
I've come up with a first attempt at this. I started off trying to do it with a PIC 12F683 running a 8Mhz, which limited me to an 8 bit PWM, I soon found that, probably due in part to my mediocre programming skills, this was really too slow for the job so I had a look for some faster chips.
I settled on the PIC 12F1822 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en544839) which can run at 32Mhz and has all the peripherals I needed. It's a pretty cool beast for a an 8 pin chip and as a bonus it's cheaper than the 12F683, or it is round here anyway.

The current version has a 10 bit PWM output and produces a sine wave of between 0.03Hz and 20Hz. It also has depth and shape controls, the shape clips the sine giving trapezoid and square waves. I might add a second mode that changes the shape control's function to switch between different wave forms, triangle, saw etc.
Thanks go to Tom Wiltshire for his excellent TAPLFO project, studying his code to see how he did it was a great help. The speed pot scaling and the hysteresis for the shape pot were copied from him.

The code is here if anyone wants to see it https://github.com/slackDSP/slackLFO/blob/master/slack_lfo_main.c (https://github.com/slackDSP/slackLFO/blob/master/slack_lfo_main.c) it still needs tidying up and commenting properly.

I've tested it using the tap tempo trem audio circuit and it seems to do the job.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on November 17, 2014, 04:13:30 PM
Quote from: slacker on November 17, 2014, 04:07:48 PM
I've come up with a first attempt at this. I started off trying to do it with a PIC 12F683 running a 8Mhz, which limited me to an 8 bit PWM, I soon found that, probably due in part to my mediocre programming skills, this was really too slow for the job so I had a look for some faster chips.
I settled on the PIC 12F1822 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en544839) which can run at 32Mhz and has all the peripherals I needed. It's a pretty cool beast for a an 8 pin chip and as a bonus it's cheaper than the 12F683, or it is round here anyway.

The current version has a 10 bit PWM output and produces a sine wave of between 0.03Hz and 20Hz. It also has depth and shape controls, the shape clips the sine giving trapezoid and square waves. I might add a second mode that changes the shape control's function to switch between different wave forms, triangle, saw etc.
Thanks go to Tom Wiltshire for his excellent TAPLFO project, studying his code to see how he did it was a great help. The speed pot scaling and the hysteresis for the shape pot were copied from him.

The code is here if anyone wants to see it https://github.com/slackDSP/slackLFO/blob/master/slack_lfo_main.c (https://github.com/slackDSP/slackLFO/blob/master/slack_lfo_main.c) it still needs tidying up and more comments adding.

I've tested it using the tap tempo trem audio circuit and it seems to do the job.

This is awesome! Thanks so much!

p.s. What are the unused pins? Or what CAN they be?
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: jubal81 on November 17, 2014, 05:36:48 PM
Above & beyond, Slacker!  :o

Can't wait to put this to use. Would it be possible to do one with a second LFO output, 180 degrees out of phase?
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on November 18, 2014, 12:49:18 PM
Quote from: midwayfair on November 17, 2014, 04:13:30 PM
This is awesome! Thanks so much!

p.s. What are the unused pins? Or what CAN they be?

Cheers Jon, hopefully a few folks will find it useful.

One of the unused pins is a digital in/out and the other is a digital in only, so both could have a switch to select something. I was thinking one of them could be used to select between how it works now and a second mode with different wave shapes. Or could do a half/double speed switch or freeze or reset the waveform. If anyone's got any other ideas let me know.

Quote from: jubal81 on November 17, 2014, 05:36:48 PM
Can't wait to put this to use. Would it be possible to do one with a second LFO output, 180 degrees out of phase?

I don't think so but I'll have a look, if you want to use it to drive LEDs you can invert the phase using a transistor.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on November 18, 2014, 01:33:40 PM
Quote from: slacker on November 18, 2014, 12:49:18 PM
if you want to use it to drive LEDs you can invert the phase using a transistor.

This is what I'd do. You'd still want an NPN to buffer the PWM, so it doesn't save a part over just using a PNP to invert it.

I'm having a hard time understanding the shape control, mostly because I'm not sure what a trapezoidal wave sounds like ... is that like the duty cycle? When you say that it clips the size to make the square, does that mean that the PWM amplitude is limited, or is it more like it's pushing the wave up until it squares off?

I do kind of like the idea of using one of the pins to set what that control does for the wave shape control (like one mode would be pre-set waveforms like the TAPLFO and the other would be your more analog control over the wave); that adds some versatility for builders without clutter.

By the way, are the Brownout functions what set whether it defaults to the knob positions on power-up, or is that something beyond the capabilities of this chip? I know there's two TAPLFOs, one of which defaults to the knobs and the other doesn't.

I really know too little of this stuff to be helpful with suggestions for the last pin, and I'm really just happy as long as a true sine and square are available, but there are some things I can imagine an LFO control doing:

1. Half speed, as you suggested. People seem to like this in stuff like the Fulltone Supatrem, but it doesn't work perfectly in an analog design. Definitely one case where the digital chip would have a big advantage, and it's also really easy to leave it off.

2. Not sure about this, but speaking of waveforms, would it free up an analog pin (if you have cooler ideas for that) if you have one of the digital pins set the waveform? Like just center = sine, left connects to G = square, right connects to +5V = triangle?

3. LFO brake ... I really doubt this is possible, though. I'm thinking of something that gradually reduces the speed as long as it's held and winds back up when it's not, like in a Leslie. Someone could probably figure out a way to implement the chip in the ROG Tri-Vibe as a Leslie simulator if that existed. Again, though, I don't see this one being plausible in such a simple chip. Maybe at absolute best it would switch what the shape control does, so instead of someone having a wave shape pot, it would default to a sine wave and then that pin is controlled by a switch.

Not sure what anyone else would find useful.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on November 18, 2014, 03:49:31 PM
Quote from: midwayfair on November 18, 2014, 01:33:40 PM
I'm having a hard time understanding the shape control, mostly because I'm not sure what a trapezoidal wave sounds like

The shape control works basically the same as hard diode clipping, think of the shape control as increasing the gain. At minimum you get a sine with the peak at the clipping level, as you increase the shape the top and bottom of the wave get clipped off, the amplitude stays the same but the peaks flatten off.             _     _
This gives a trapezoid shape, sloping sides and a flat top _/  \_/   \_ the more you clip it the straighter the sides become until you get a square wave. This actually needs a bit of work, the square isn't quite square enough, it sounds square at higher speeds but at slower ones the sides still have a noticeable slope.

Quote
I do kind of like the idea of using one of the pins to set what that control does for the wave shape control (like one mode would be pre-set waveforms like the TAPLFO and the other would be your more analog control over the wave); that adds some versatility for builders without clutter.

Yeah that's what I thought, two for the price of one, assuming I can fit it all in :)

Quote
By the way, are the Brownout functions what set whether it defaults to the knob positions on power-up, or is that something beyond the capabilities of this chip? I know there's two TAPLFOs, one of which defaults to the knobs and the other doesn't.

Short answer, it defaults to the knob positions at power up.
Long answer, at power up all the settings are at zero. It reads a pot every 20ms, cycling through each one in turn, so after 60ms it will have read all 3 pots and be using their settings.

Quote
2. Not sure about this, but speaking of waveforms, would it free up an analog pin (if you have cooler ideas for that) if you have one of the digital pins set the waveform? Like just center = sine, left connects to G = square, right connects to +5V = triangle?

Nice idea. Digital inputs can only be high or low though, so only two options per pin, could use both to get four wave forms.

Quote
3. LFO brake ... I really doubt this is possible, though. I'm thinking of something that gradually reduces the speed as long as it's held and winds back up when it's not, like in a Leslie.

Unfortunately probably not possible. You might be able to add it externally though, little circuit that ramps the voltage from the speed pot up and down.  
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on November 18, 2014, 04:37:22 PM
Quote from: slacker on November 18, 2014, 03:49:31 PM

Unfortunately probably not possible. You might be able to add it externally though, little circuit that ramps the voltage from the speed pot up and down.  

Good idea. Fortunately, Josh McClaren at 1776 already has a circuit that does that in the Multiplex I can nick!

Just an idea on the wave shape idea:

What if it changes the slope of the wave instead of clipping the top of the wave? At one side, the rise and fall is uniform (sine). As the pot is turned, the rise becomes more and more immediate, resulting in a square wave at the far end. I can't figure out how to get a triangle out of that, but maybe that's what the function switch idea is for.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on November 24, 2014, 04:49:31 AM
Nice job slacker, and the 12F1822 looks like a very cool little chip.

I guess you would be stepping on the TAPFLO's toes, a little, but do you have enough resources to use one of the unused pins as an optional tap tempo input?
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on November 26, 2014, 12:46:21 PM
Cheers Sam. Yeah the 12F1882 is a nice bit of kit, only issue with it as far as I'm concerned is that MPLABX doesn't support programming it with a PICkit2 programmer, they want you to buy a PICkit3 or an ICD3. Luckily there's some unofficial updates to the standalone PICkit2 software that support it.

I'd have to have a think about how to implement it but I think the chip has enough resources left to do a tap tempo, it's not something I'm planning on doing for now but I might have a look in the future.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on November 27, 2014, 12:02:27 PM
^it's not something I'm planning on doing for now but I might have a look in the futureFair enough.

Fair enough.

Thanks for the posting the code - and very nice to see you wrote it in c rather than assembly. If/when I next get the need for a digital LFO, I might take a closer look.
In the mean time, I must add a few of these chips to my next Farnell order.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: ElectricDruid on November 27, 2014, 02:39:46 PM
Quote from: slacker on November 17, 2014, 04:07:48 PM
I've come up with a first attempt at this. I started off trying to do it with a PIC 12F683 running a 8Mhz, which limited me to an 8 bit PWM, I soon found that, probably due in part to my mediocre programming skills, this was really too slow for the job so I had a look for some faster chips.
I settled on the PIC 12F1822 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en544839) which can run at 32Mhz and has all the peripherals I needed. It's a pretty cool beast for a an 8 pin chip and as a bonus it's cheaper than the 12F683, or it is round here anyway.

The current version has a 10 bit PWM output and produces a sine wave of between 0.03Hz and 20Hz. It also has depth and shape controls, the shape clips the sine giving trapezoid and square waves. I might add a second mode that changes the shape control's function to switch between different wave forms, triangle, saw etc.
Thanks go to Tom Wiltshire for his excellent TAPLFO project, studying his code to see how he did it was a great help. The speed pot scaling and the hysteresis for the shape pot were copied from him.

The code is here if anyone wants to see it https://github.com/slackDSP/slackLFO/blob/master/slack_lfo_main.c (https://github.com/slackDSP/slackLFO/blob/master/slack_lfo_main.c) it still needs tidying up and commenting properly.

I've tested it using the tap tempo trem audio circuit and it seems to do the job.

I was going to suggest using one of the newer 12F1xxx or 16F1xxx "enhanced" chips, but it sounds like Slacker's right there already. They remove the need for the crystal which is a major help, and the higher clock rate is the icing on the cake. Plus the new instructions should lead to some more efficient code. There's also no need to run the sample update at the same rate as the PWM output if time gets tight. I've done some projects using the Timer postscaler to divide-down the interrupt rate. Like this, you can have a PWM frequency of 31.25KHz and a sample interrupt of half that. Essentially, it automates just outputting each sample twice.

So, having stepped in to tell you what you all already know, I'll just say "Good work! Carry On!".

Tom
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: rustypinto on December 06, 2014, 11:30:28 AM
Quote from: jubal81 on November 17, 2014, 05:36:48 PM
Can't wait to put this to use. Would it be possible to do one with a second LFO output, 180 degrees out of phase?
Quote
I don't think so but I'll have a look, if you want to use it to drive LEDs you can invert the phase using a transistor.

Assuming you use the ECCP for PWM: using the half-bridge mode with P1B inverted can generate a complimentary LFO (or P1A inverted, P1B normal, doesn't matter). I've done this with 12F1822. This chip also offers two pin-muxing options if P1B gets in the way of an ADC or something else.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on August 18, 2015, 11:34:01 AM
Figured it was best to bring this post back from the dead than start another.
I find myself in the need (well want) of a PIC that can do 2 LFOs.

Quote from: rustypinto on December 06, 2014, 11:30:28 AM
Assuming you use the ECCP for PWM: using the half-bridge mode with P1B inverted can generate a complimentary LFO (or P1A inverted, P1B normal, doesn't matter). I've done this with 12F1822. This chip also offers two pin-muxing options if P1B gets in the way of an ADC or something else.

I got quite excited about this for a while, but realised that I don't understand how this would work if the depth was also determined by the duty cycle?

So, any suggestions for a small(ish) PIC that can run at 32MHz(ish) and has 2 CCP modules?
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on August 18, 2015, 02:18:59 PM
I've not used any of them but look at the bigger enhanced midrange 8 bit jobbies, 16F1824 to 16F1829 have two PWM modules. Some of the through hole dsPICs have 4 PWMs and there's a couple with 16bit DACs, might be overkill for what you want.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on August 18, 2015, 03:26:27 PM
Have spent some time the the microchip MAPS and found the 16F1824/5. These should work, but are 14 pin. Nice features (including DIP) and price, so will add a couple to the basket.

As I don't need ECCP, just 2xCCP, the 12F1622 might just do the trick with 3 10bit ADC to spare (don't need wave shape, but could have 2 switchable options via the last digital IO pin

http://www.microchip.com/wwwproducts/Devices.aspx?product=PIC12F1612
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on September 05, 2015, 03:15:18 AM
After a few teething problems with the 8 pin pic12F1612 - new chip and a few errors in the datasheet and some mostly undocumented new features in the CCP modules - I have it running and generating a dual LFO. Currently have 3 pots - depth, speed and phase between LFOs (0-359 degrees). I currently have the last pin disabling the LFO when grounded, but may alternatively use this to switch between 2 waveforms.

I will tidy up the code and post it along with a hex file. If there is any interest, I could easily also do a second version where the second LFO is fixed 180 out of phase (could be switchable e.g. between 0 or 90 vs 180o) and have the 3rd pot do something else - probably different waveforms, but open to suggestions...

slacker - your slackLFO code was very helpful in getting started. Thanks.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on September 16, 2015, 11:51:26 AM
Before I get distracted again, I figured I should post the code for the dual LFO I mentioned in the last post.
It works quite nicely, but at some stage I will tweak the speed range/spread and to make the way the depth pot scales the LFO a little more elegant.

At the moment, pin 4 switches between a sine and square wave LFO.
I see that the code is censored too. The 'c0cked wah' mode kicks in when the speed pot is fully ccw. In this case, the LFO stops osciallating and the 2 outputs are controlled separatedly by the depth and phase pots.



/*
* File:   DUAL_LFO_main.c
* Author: Sam Hay
* Created on August 15, 2015, 2:12 PM
*
* based in part on slackLFO:
* https://github.com/slackDSP/slackLFO/blob/master/slack_lfo_main.c
* which is based in part on TAPLFO:
* http://www.electricdruid.net/index.php?page=projects.taplfo
*
*
*                              __________
*                VDD (+5V) ---|         |--- VSS
*           CPP1, PWM out1 ---| 12F1612 |--- CPP2, PWM out2 (ICSPDAT)
*           AN3, phase pot ---|         |--- AN1, speed pot (ICSPCLK)
*  (MCLR off) RA3, wave_sw ---|_________|--- AN2, depth pot
*
*/

#include <xc.h>                 // pic12F1612 is new and needs xc8 v1.35(ish)
#include <stdint.h>

// CONFIG1
#pragma config BOREN = ON       // Brown-out Reset Enable->Brown-out Reset enabled
#pragma config PWRTE = OFF      // Power-up Timer Enable->PWRT disabled
#pragma config FOSC = INTOSC    // Oscillator Selection Bits->INTOSC oscillator: I/O function on CLKIN pin
#pragma config MCLRE = OFF      // Disable MCLR so pin 4 (RA3) can be used as input
#pragma config CP = OFF         // Flash Program Memory Code Protection->Program memory code protection is disabled
#pragma config CLKOUTEN = OFF   // Clock Out Enable->CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection->Write protection off
#pragma config LPBOR = OFF      // Low-Power Brown Out Reset->Low-Power BOR is disabled
#pragma config LVP = OFF        // Low-Voltage Programming Enable->High-voltage on MCLR/VPP must be used for programming
#pragma config ZCD = OFF        // Zero Cross Detect Disable Bit->ZCD disable.  ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable->Stack Overflow or Underflow will cause a Reset
#pragma config PLLEN = ON       // PLL Enable Bit->4x PLL is always enabled
#pragma config BORV = LO        // Brown-out Reset Voltage Selection->Brown-out Reset Voltage (Vbor), low trip point selected.

// CONFIG3
#pragma config WDTCWS = WDTCWSSW // WDT Window Select->Software WDT window size control (WDTWS bits)
#pragma config WDTCCS = SWC      // WDT Input Clock Selector->Software control, controlled by WDTCS bits
#pragma config WDTE = OFF        // Watchdog Timer Enable->WDT disabled
#pragma config WDTCPS = WDTCPS1F // WDT Period Select->Software Control (WDTPS)

// GLOBAL DEFINITIONS
#define _XTAL_FREQ 32000000     // processor speed for delay macro
#define speed_pot pots[0]       // these are 8bit values populated from ADRESH (8 MSB) in main
#define depth_pot pots[1]
#define phase_pot pots[2]
#define wave_sw PORTAbits.RA3   // select between sine (RA3 = 1) and alternative (RA£ = 0) waveforms in interrupt routine

// GLOBAL ARRAYS
// 256 8bit values that cover 2pi rad of a sine wave, starting from 0
volatile const unsigned int sine[256] = {
0,0,0,0,1,1,1,2,2,3,4,5,5,6,7,9,10,11,12,14,15,17,18,20,21,23,25,27,29,31,33,35,37,40,42,44,47,49,52,54,57,59,62,65,67,70,73,76,79,82,85,88,90,93,97,100,103,106,109,112,115,118,121,124,128,131,134,137,140,143,146,149,152,155,158,162,165,167,170,173,176,179,182,185,188,190,193,196,198,201,203,206,208,211,213,215,218,220,222,224,226,228,230,232,234,235,237,238,240,241,243,244,245,246,248,249,250,250,251,252,253,253,254,254,254,255,255,255,255,255,255,255,254,254,254,253,253,252,251,250,250,249,248,246,245,244,243,241,240,238,237,235,234,232,230,228,226,224,222,220,218,215,213,211,208,206,203,201,198,196,193,190,188,185,182,179,176,173,170,167,165,162,158,155,152,149,146,143,140,137,134,131,128,124,121,118,115,112,109,106,103,100,97,93,90,88,85,82,79,76,73,70,67,65,62,59,57,54,52,49,47,44,42,40,37,35,33,31,29,27,25,23,21,20,18,17,15,14,12,11,10,9,7,6,5,5,4,3,2,2,1,1,1,0,0,0
};
// '0' + 255 speed values log spaced from 54-13366 with speed_pot = 0 for '%^&*ed wah' mode;
// LFO freq calculation given below in interrupt routine
volatile const unsigned int speed[256] = {
0,54,56,57,59,60,61,62,64,65,67,68,70,71,73,74,76,78,79,81,83,85,86,88,90,92,94,96,98,101,103,105,107,110,112,115,117,120,122,125,128,130,133,136,139,142,145,148,152,155,158,162,165,169,173,177,180,184,188,192,197,201,205,210,214,219,224,229,234,239,244,250,255,261,266,272,278,284,290,297,303,310,317,324,331,338,345,353,360,368,376,385,393,402,410,419,429,438,448,457,467,478,488,499,510,521,532,544,556,568,580,593,606,619,633,646,661,675,690,705,720,736,752,769,785,803,820,838,856,875,894,914,934,954,975,996,1018,1041,1063,1087,1110,1135,1159,1185,1211,1237,1264,1292,1320,1349,1379,1409,1439,1471,1503,1536,1570,1604,1639,1675,1711,1749,1787,1826,1866,1907,1949,1991,2035,2079,2125,2171,2219,2267,2317,2368,2419,2472,2526,2582,2638,2696,2755,2815,2877,2940,3004,3069,3137,3205,3275,3347,3420,3495,3571,3650,3729,3811,3894,3979,4066,4155,4246,4339,4434,4531,4630,4731,4835,4941,5049,5159,5272,5387,5505,5625,5748,5874,6003,6134,6268,6405,6545,6688,6835,6984,7137,7293,7453,7616,7782,7952,8126,8304,8486,8671,8861,9055,9253,9455,9662,9873,10089,10310,10535,10766,11001,11242,11488,11739,11996,12258,12526,12800,13080,13366
};
// used in main to update _pots values
volatile unsigned char pots[3] = {0,0,0};

// INITIATION GUBBINS
void OSCILLATOR_Init(void) { 
    OSCCONbits.IRCF = 14;       // 8Mhz clock + 4 x PLL from PLLEN   
    OSCSTAT = 0x00;             // HFIOFR disabled; HFIOFS not 0.5percent_acc; PLLR disabled; MFIOFR disabled; HFIOFL not2percent_acc; LFIOFR disabled;
    OSCTUNE = 0x00;             // TUN 0x0;
}

void TIMERS_Init(void) {
    INTCONbits.GIE = 1;         // set the Global Interrupt Enable
    INTCONbits.PEIE = 1;        // set the Peripheral Interrupt Enable
    INTCONbits.T0IF = 0;        // Timer0 overflow interrupt flag bit
    INTCONbits.T0IE = 1;        // Timer0 overflow interrupt enable
    OPTION_REGbits.T0CS = 0;    // Timer0 Clock Source Select - Internal instruction cycle clock (FOSC/4)
    OPTION_REGbits.T0SE = 0;    // Timer0 Source Edge Select bit - Increment on low-to-high transition on T0CKI pin
    OPTION_REGbits.PSA = 0;     // Prescaler is assigned to the Timer0 module
    OPTION_REGbits.PS = 0;      // Prescaler Rate Select = 1 : 2
    TMR0 = 0;                   // load a value of 0 into the timer
    T2CONbits.TMR2ON = 1;       // Timer 2 on
    T2CONbits.T2CKPS = 0;       // Timer 2 prescaler 1
    PR2 = 255;                  // Timer 2 period ~31Khz PWM freq   
}

void PIN_Init(void) {
    LATA = 0x00;                // clear all pins to 0 
    TRISAbits.TRISA0 = 0;       // RA0 (pin 7) CCP1 PWM out - output 1
    TRISAbits.TRISA5 = 0;       // RA5 (pin 2) CCP2 PWM out - output 2
    TRISAbits.TRISA1 = 1;       // RA1 (pin 6) input
    TRISAbits.TRISA2 = 1;       // RA2 (pin 5) input
    TRISAbits.TRISA3 = 1;       // RA3 (pin 4) input - wave_sw
    TRISAbits.TRISA4 = 1;       // RA4 (pin 3) input
    ANSELAbits.ANSA1 = 1;       // AN1 (pin 6) analogue input - speed pot
    ANSELAbits.ANSA2 = 1;       // AN2 (pin 5) analogue input - depth pot
    ANSELAbits.ANSA4 = 1;       // AN3 (pin 3) analogue input - phase pot
    OPTION_REGbits.nWPUEN = 0x01; // All weak pull-ups are disabled (except MCLR, if it is enabled)
    WPUAbits.WPUA3 = 1;         // enable weak pullup on RA3/MCLR - wave_sw should default to sine with no connection to pin 4
}

void PWM_Init(void) {           // initialise both PWM modules: CCP1 on RA5/pin 2 and CCP2 on RA1/pin 7
    APFCONbits.CCP1SEL = 1;     // CCP1 functions on RA5 / pin 2     
    CCP1CON = 0xCC;             // EN=1, module enabled; OE=1, output enabled; FMT=0, duty right-aligned; MODE PWM
    CCP2CON = 0xCC;             // (0b11001100)
    CCPR1H = 0x00;              // to start, lets set duty cycle to 0
    CCPR2H = 0x00;
    CCPR1L = 0x00;              //
    CCPR2L = 0x00;
    CCPTMRSbits.CCP1TSEL = 0x0; // Select Timer2
    CCPTMRSbits.CCP2TSEL = 0x0; 
}

void ADC_Init(void) {
    ADCON1bits.ADCS = 3;        // DFRC - ADC clock supplied from an internal RC oscillator
    ADCON1bits.ADFM = 0;        // ADC register pair left justified, ADRESH contains 8 MSB, ADRESL <7:8> contains 2 LSB
    ADCON0bits.ADON = 1;        // ADC on
}

// SET PWN DUTY CYCLE ROUTINE
void PWM1_DutyValueSet(unsigned int duty1) {
    duty1 &= 1023;              // duty cycle value is 10bit
    CCPR1H = duty1 >> 8;        // FMT=0 so CCPRxH <1:0> contains 2 MSB,
    CCPR1L = duty1;
}

void PWM2_DutyValueSet(unsigned int duty2) {
    duty2 &= 1023;
    CCPR2H = duty2 >> 8;
    CCPR2L = duty2;
}

// MAIN - INITIALISE EVERYTHING AND THEN POLL ADC AND UPDATE _pots VALUES
void main() {
   
    // local variables
    const unsigned char adc_channel[3] = {1, 2, 3};
    unsigned char count = 0;
   
    // initialise everything using above gubbins
    OSCILLATOR_Init();          //
    TIMERS_Init();              //
    PIN_Init();                 //
    PWM_Init();                 //
    ADC_Init();                 //

    // taken straight from slackLFO with ADC channels updated
    for (;;) {                                 
        count++;                                // read 1 pot per cycle, runs every ~20 ms
        if (count == 3)                         // count = 0,1,2,0...;
            count = 0;                          // could alter this to sample some pots more than others

        ADCON0bits.CHS = adc_channel[count];    // select analog input - AN1, AN2, AN3 in turn
        __delay_ms(20);                         // could make this shorter

        GO_nDONE = 1;                           // make ADC read
        while (GO_nDONE);                       // wait while reading takes place
        pots[count] = ADRESH;                   // ADC Result High Register = 8 MSB
    }  // end for
}  // end main


// INTERRUPT - CALCULATE & WRITE PWM DUTY CYCLE
void interrupt isr(void) {                      // ISR runs every 64us

    INTCONbits.T0IF = 0;                        // clear Timer0

    // local variables
    static unsigned int step = 0;
    static unsigned int pos1 = 0; 
    unsigned int pos2 = 0; 
    unsigned int output1 = 0;
    unsigned int output2 = 0;
    unsigned int output1_duty = 0;
    unsigned int output2_duty = 0;
   
    // '%^&*ED WAH' mode - also useful for calibration/trimming the LED current to set e.g. min LDR resistance

    if (speed_pot == 0) {                       // speed pot at minimum = manual mode with no LFO

        PWM1_DutyValueSet(depth_pot << 2);      // PWM output1 is determined only by depth pot
        PWM2_DutyValueSet(phase_pot << 2);      // PWM output2 is determined only by phase pot
       
    } else {                                    // LFO frequency is determined by interrupt rate (64 us) and speed[]   
        step = step + speed[speed_pot];
        if (step > 32767) {
            step = step & 32767;
            pos1 = (pos1 + 1) & 255;
            pos2 = (pos1 + phase_pot) & 255;
           
            // 1/freq = (32767/speed_pot) * 64eE-6 * 255
            // LFO freq = 0.1 - 25 Hz if min/max speed_pot = 54/13366
           
            if (wave_sw == 1) {                         // pin 4 is high, LFO has sine waveform
            output1 = sine[pos1];                       // 8 bit unsigned
            output2 = sine[pos2];                       // 8 bit unsigned
            } else {                                    // pin 4 is low
                output1 = (pos1 < 128)? 255 : 0;        // alternatively pin 4 is low, LFO has square waveform
                output2 = (pos2 < 128)? 255 : 0;
            }  // end wave_sw else
           
            output1_duty = (output1 * depth_pot) >> 6;  // 8bit unsigned * 8bit unsigned >> 6 = 10 bit unsigned
            output2_duty = (output2 * depth_pot) >> 6;

            PWM1_DutyValueSet(output1_duty);            // set PWM duty cycle
            PWM2_DutyValueSet(output2_duty);

        }  // end step if
    }  // end speed else
   
}  // end interrupt

Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: idiot savant on September 17, 2015, 08:47:37 AM
GREAT job. Thanks for sharing!

I did something similar recently using an AVR to do a simple LFO for a project.

http://www.diystompboxes.com/smfforum/index.php?topic=110823.0

I only posted code for sine wave, but I have a setup for triangle, ramp up and down and square as well. 2 outputs at 180deg.

The variable phasing you implemented is a neat idea, What kind of applications were you thinking of using it for?

--At some point, representing the full 360deg cycle (in complementary form)seems a little weird to me, are you really going to need multiple outputs a few degrees apart, in practice you'd never even notice phase shifts of less than a certain difference...

Speed wise, you have a HUGE range of 0.1-25Hz. How does it feel on pot travel?

When I dealt with mine, I decided to limit the range, and provide code functions for doubling or halving speed ranges eternally...


I'm not a PIC guy, so some hardware config stuff looks kinda funny to me. Like why bother running the chip at 32MHz when the fastest thing happening is your 31kHz PWM. You'd save a ton of power running at the slowest possible speed that maintains your fastest desired peripheral. Also, hard coded _delay_ms calls like in the ADC read function are sloppy and may cause timing errors on the important stuff like the phase accumulator and PWM, why not round-robin and discard the extra samples(you can only turn a pot so fast).

Again this all might just be differences in PIC's vs. the AVR's that I'm used to.


Anyways, not griping, just interested as I'm a novice programmer.

Thanks for posting!!

-Morgan
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on September 17, 2015, 09:24:43 AM
Thanks Morgan, I hadn't seen your project but I like it - there is something wonderful about combining a valve and a uC.

I figured I would play with arbitary phase shifting as, AFAIK, it is essentially impossible to do (reasonably) in the analogue domain.
The first thing I will use the code for is this: http://www.diystompboxes.com/smfforum/index.php?topic=111802.5
I just have a couple of tweaks to make and should post the V2 with the pic quite soon.

I haven't quite figured whether having 180 or 360 degrees of phase variation is better, so I figured I would keep it like this for a while and do some real world experiments to see if I ever turn it past noon/180 degrees.
In any case, it is trivial to change the code to give only 180 degrees:
pos2 = pos1 + (phase_pot >> 2) & 255;

The other reason for doing this is that I have a 'kitchen sink' version in the works using a pic16F1825 with a second LFO that modulates the phase and in this case, it makes sense (I think) to be able to swing the full 360 degrees.

I took the approximate speed range from the TAPLFO. It is mostly quite workable, but I might change the taper a little to give more play around the sweet spot, once I work out where that is. I did think about a range switch, but there isn't enough pins with this chip.

^I'm not a PIC guy...
I do not have a huge ammount of experience with PICs, so some of the design choices may be suboptimal. That said, most operations take 4 clock cycles, so you can think of it as running at 8MHz. In any case, I will have to check, but I'm fairly sure that the clock has to be running this fast to get the 10bit PWM output at ~31kHz
Actually, that must be right as 31.25kHz * 1024 = 32 MHz.
Also, remember this is 8bit architecture, so you need to spend a fair few cycles doing most of the math.

The ADC read code came straight from slacker's code and as it works well enough, I haven't bothered changing it. I am guessing that the 20ms delay is essentially debouncing, but perhaps he can elaborate.

Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: idiot savant on September 17, 2015, 10:00:38 AM
Lol, yeah 10-bit makes more sense now... I saw the 8-bit wave table and ass-umed 8-bit. :icon_redface:
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on September 17, 2015, 10:58:58 AM
Your confusion is quite understandable.
I wanted to keep the ADC 8bit, so made the wave table entries 8bit so that ADC*wave table is 16bit. As this is then divided down to 10bit, there are other ways to get there, and I have been thinking about getting better resolution by using a 10bit wave table and then a more elaborate duty cycle calculation that doesn't require operations on >16bit integers.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: slacker on September 17, 2015, 01:27:19 PM
Quote from: samhay on September 17, 2015, 09:24:43 AM
The ADC read code came straight from slacker's code and as it works well enough, I haven't bothered changing it. I am guessing that the 20ms delay is essentially debouncing, but perhaps he can elaborate.

The delay is there for two reasons, first when you change ADC channels you need to wait a certain amount of time for the ADC to settle and you start getting valid readings from it, can't remember the exact value it's in the datasheet somewhere, it's a few u seconds. Second there's no point reading the pots faster than you can turn them so I slowed it down, can't remember why I chose 20ms you could probably slow it down even more and the pots would still feel nice and responsive.
Morgan, not sure what you meant by "sloppy" if you meant the timing is sloppy, then yeah it is but it doesn't matter if the pots aren't read exactly every 20ms so not an issue. If you meant it's sloppy coding then yeah it can be, the delay makes the program sit there doing nothing and often it's better to poll things periodically use an interrupt to trigger something or do something useful to cause a delay instead. In this case though all the main loop does is read the pots so it doesn't matter if it sits there doing nothing useful most of the time. It doesn't affect the timing of the phase accumulator because this is running in an interrupt triggered every 64us by a timer, you actually have the opposite problem, the interrupt messes with the timing of the main loop. The longer the interrupt takes doing its thing the longer the main loop is interrupted for.
The PWM is a hardware peripheral running off the min clock its speed isn't influenced by what the processor is doing.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: idiot savant on September 17, 2015, 07:25:06 PM
Quote from: slacker on September 17, 2015, 01:27:19 PM
Quote from: samhay on September 17, 2015, 09:24:43 AM
The ADC read code came straight from slacker's code and as it works well enough, I haven't bothered changing it. I am guessing that the 20ms delay is essentially debouncing, but perhaps he can elaborate.

If you meant it's sloppy coding then yeah it can be, the delay makes the program sit there doing nothing and often it's better to poll things periodically use an interrupt to trigger something or do something useful to cause a delay instead.

This is what I was getting at. Though as you said it doesn't really matter. I've been chewed out for using busy wait delays too much, so now I try to avoid them.

Sorry for making it sound confrontational in my other post, I didn't understand the program flow fully before I opened my mouth. :icon_redface:
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on September 18, 2015, 05:26:55 AM
Thanks for the clarification Ian.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: garcho on November 24, 2015, 10:12:34 PM
zombie thread alert...

what happened with this, and CAN I BUY SOME?! cheers
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on November 25, 2015, 03:18:23 AM
The code that both Ian (slacker) and myself have posted works. I have tweaked mine a little more and am currently building it as part of a tremolo / vibe*

I don't know about Ian, but while I would be happy to put a few chips in the post to UK members to get some feedback, I have no desire to sell programmed chips. This is especially the case seeing as the 8 pin PICs give limited control options, so it makes sense to customise the code for each application - waveshape selection OR phase difference between 2 LFOS OR tap tempo OR etc.
If you have a pickit 3 or equivalent then you can burn your own chip and I am happy to provide hex code if that helps. The PIC12F1612 is pretty cheap too**.

I appreciate that most people don't have the kit/know-how/desire to program chips, so I guess it would be good to find an alternative option.  I would be happy for Aron to sell programmed chips in the store (assuming he can burn them himeself), as he does with the Taptation. However, much of my code is borrowed from Ian, which in turn is borrowed in part from Tom (ElectricDruid), so I would want their blessing first.

*see here: http://www.diystompboxes.com/smfforum/index.php?topic=111802.0

**e.g. http://eu.mouser.com/Semiconductors/Embedded-Processors-Controllers/Microcontrollers-MCU/8-bit-Microcontrollers-MCU/_/N-a85ik?P=1z0z7v3&Keyword=pic12f1612&FS=True
http://uk.farnell.com/microchip/pic12f1612-i-p/mcu-8bit-pic12f-32mhz-dip-8/dp/2406552
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: ElectricDruid on November 27, 2015, 04:51:15 PM
Quote from: samhay on November 25, 2015, 03:18:23 AM
The code that both Ian (slacker) and myself have posted works. I have tweaked mine a little more and am currently building it as part of a tremolo / vibe*

I don't know about Ian, but while I would be happy to put a few chips in the post to UK members to get some feedback, I have no desire to sell programmed chips. This is especially the case seeing as the 8 pin PICs give limited control options, so it makes sense to customise the code for each application - waveshape selection OR phase difference between 2 LFOS OR tap tempo OR etc.
If you have a pickit 3 or equivalent then you can burn your own chip and I am happy to provide hex code if that helps. The PIC12F1612 is pretty cheap too**.

I appreciate that most people don't have the kit/know-how/desire to program chips, so I guess it would be good to find an alternative option.  I would be happy for Aron to sell programmed chips in the store (assuming he can burn them himeself), as he does with the Taptation. However, much of my code is borrowed from Ian, which in turn is borrowed in part from Tom (ElectricDruid), so I would want their blessing first.

*see here: http://www.diystompboxes.com/smfforum/index.php?topic=111802.0

**e.g. http://eu.mouser.com/Semiconductors/Embedded-Processors-Controllers/Microcontrollers-MCU/8-bit-Microcontrollers-MCU/_/N-a85ik?P=1z0z7v3&Keyword=pic12f1612&FS=True
http://uk.farnell.com/microchip/pic12f1612-i-p/mcu-8bit-pic12f-32mhz-dip-8/dp/2406552

If there's a desire to see 8-pin PIC LFOs out there in world, I'd be happy to have some in the Druid shop, now I've got it set up properly (took a while...). What's the favourite set of features? Or what's the top applications?

Dual LFOs with a phase difference seems to be one - what waveshapes? Other options?
Tap tempo in a small chip seems to be another? How many of the bells and whistles from the TAPLFO does it need? Multipliers? Many waveshapes? Wave distortion?

I'm open to ideas or suggestions about how best to do this, if it's worth it - do you guys have code that's good already? Do I need to program some Druid chips that do something similar? How should we make sure that no-one ever builds a boring op-amp LFO ever again?!?

Thanks,
Tom

Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: dbp512 on November 27, 2015, 09:51:27 PM
Tom, I'm new to building effects in general, and I still haven't gotten around to using any digital chips. That being said, I do plan on changing that once I have some more experience. I have some ideas, but I'm not sure how useful they'd be, or if they'd even be possible to implement. But hey, it doesn't hurt to brainstorm, does it? Well, maybe a bit of embarrassment as you realize how little I know, but I'll live.

Having each waveform is nice, but it seems like some people want a more analog waveform manipulator. I like samhay's method of morphing from a sine to square. Chase bliss uses a pair of toggle switches to select each side of the wave from sine, ramp, and square, so you end up with some cool nonstandard shapes. Similar to this, what about starts with a triangle, but slowly puffing out the sides to shift into sine, then eventually square. Maybe one waveform is enough, and just use a symmetry adjustment like your taplfo chip. A triangle has two sawtooth patterns, and maybe a sine could be manipulated to make sweep/lump at the extremes.
 
Another option, as you touched upon, would be generating multiple waves. I see samhay working with 180°, although I thought an inverting buffer could do the same thing. What about 3 waveforms, 120° out of phase with each other? Again my lack of knowledge is showing clearly here, but I don't recall seeing any easy way to make 3 waveforms like this. I saw one method, but it used RC filters so it was calibrated to a single frequency. I'm basing this idea off your BBD clock chips, in which you could synchronize multiple of them and offset their phases. Unless there's already a way to do something similar, I feel like that might be more useful than 180°, but then again what would I know? It might not be possible to even squeeze 3 lfo's in a chip (wouldn't that leave a single pin free for any and all controls?).
 
As was pointed out earlier, since 8 pin chips have fewer controls, it makes sense to make them specialized for each application. While that certainly won't make things easier for the majority of us who can't flash our own chips, maybe you could boil things down to a small number of chips with different applications in mind. Such as a single waveform with controls for wave shape and symmetry, or dual waveforms with a single control to morph between 2-3 preset waveforms. 
 
I remember reading something (I believe by Mark Hammer about the hypertriangle chorus flanger) that the lfo in a chorus doesn't require much depth, so you can get away using a triangle, while flangers' wider depths really benefit from a sweep shape. If thats the case, then perhaps a morph control would be enough for a chorus/flanger based lfo chip. I think that would work well with multiple waveforms, as you'd have fewer pins available for controls. 
 
I'd be happy to help you however I could, but I don't have much experience programming pic chips (I did take a robotics course where I programmed an arduino-like robot in pbasic). That being said, I'm a quick study and good at programming. I'm not sure how much help I could be, but if you could benefit from your own whipping boy (tayda does have nate after all) I'm around. I'd benefit by learning to implement these chips in effects, instead of just building whatever other people determined works.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: garcho on November 28, 2015, 03:15:21 PM
wow, y'all are amazing! some thoughts...

what i would like to see in a 8 pin dual LFO IC

1- A waveform
2- A rate
3- B waveform
4- B rate multiplier, synced to 'A rate' (could this be programmed so that turning a pot counterclockwise from noon would move through sync stages for B rate to be synced to A rate? like 1:1, 1:2, 1:3 etc? and then turning the pot clockwise from noon would move through non-synced rate times?)
5- B phase (in 15° segments? that way key phase like 180° or 90° would be easy to dial in exactly)

what i would like to see in a 8 pin single LFO IC
1- waveform
2- rate
3- distort a la TAPLFO
4- tap tempo/ext. sync
5- multiplier (for sync)

what i would like to see in a 14 pin dual LFO IC
1- waveform A
2- rate A
3- distort A
4- waveform B
5- rate B
6- distort B
7- sync/rate (sync 'B rate' to 'A rate' by set ratios, all the way counterclockwise being 'no sync')
8- B phase (in 15° segments)
9- tap tempo/ext. sync for 'A rate'
10- multiplier for 'A rate'
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on November 28, 2015, 03:45:39 PM
Thanks Tom.

The code I posted earlier works ok, but needs a little refinement - mainly the speed control is too wide/twitchy, so could do with a new table and it might be nice to use a log wavetable for the depth control to make it less twitchy at lower settings (there isn't much program memory left though).
Other than that, it might benefit from some polishing by somebody that does this sort of work in a slightly more professional context than I do.
From my brief play with Ian's code, it seemed to work ok, but again might benefit from a few tweaks to the control tables.

Gary -
The only 8 pin PIC I could find to do a decent job of a dual LFO has room for 3 control pots. If you get rid of one LFO, you can get 4 pots. The other pins are Vdd (e.g. +5V), Vss (ground), 2 LFO outputs (or 1 + 4th pot) and the MCLR pin, which you can't use as an analog input (a pot), but can be a on/off switch.

However, you can do some neat stuff that isn't feasible in the analogue realm. With the dual LFO code I have settled on for the stereo vibe, I originally used the MCLR switch to select between a sine and square wave. However, I freed up the switch by setting up the depth pot differently - from CCW the depth increases and you have a sine wave (actually a hypersine). At noon, you get max depth and then at 12:01 you get max depth of a square(ish) wave. Turning the pot further gives you less depth (square wave) until you get to no depth at CW. You could also do this the other way round with no depth at noon and increasing depth of 2 waveforms turning up or down from there.

dbp512 -

>I like samhay's method of morphing from a sine to square.
That's a good idea, but it's Ian's (slacker) idea/code.

Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: garcho on November 28, 2015, 07:04:57 PM
duh! i guess you need both PWM outs  :icon_redface:

in that case:

what i would like to see in a 8 pin dual LFO IC
1- A/B waveform
2- A rate
3- B rate multiplier, synced to 'A rate' (could this be programmed so that turning a pot counterclockwise from noon would move through sync stages for B rate to be synced to A rate? like 1:1, 1:2, 1:3 etc? and then turning the pot clockwise from noon would move through non-synced rate times?)
4- switch for whether or not B is 180° out of sync from A or not.

what i would like to see in a 8 pin single LFO IC
1- waveform
2- rate
3- distort a la TAPLFO
4- tap tempo/ext. sync
5- switch for whether to not output is 180° out of phase with sync signal

what i would like to see in a 14 pin dual LFO IC
1- waveform A
2- rate A
3- distort A
4- waveform B
5- rate B
6- distort B
7- sync/rate (sync 'B rate' to 'A rate' by set ratios, all the way counterclockwise being 'no sync')
8- B phase (in 15° segments)
9- tap tempo/ext. sync for 'A rate'
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on November 30, 2015, 05:09:18 PM
You don't have depth in any of these options.
This is probably ok for some/ a few designs, but not for others, and certainly wouldn't be a drop-in replacement for other designs that use the TAPLFO.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: garcho on December 01, 2015, 01:00:00 AM
i was thinking there would be a way to add depth control later, say, after the filter (or LED/LDR)? like a CV in?
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: ElectricDruid on December 02, 2015, 08:42:45 AM
Quote from: garcho on December 01, 2015, 01:00:00 AM
i was thinking there would be a way to add depth control later, say, after the filter (or LED/LDR)? like a CV in?

I agree, I think. I'd thought how to reduce the pin count, and reckon the Depth pot is the obvious one to drop. In many situations, adding a depth control after the LFO isn't too difficult. Still, it's a pity...but you can't have everything, I guess. Or not on an 8-pin chip, anyway.

It's really excellent to see these ideas. Helps no end.

Thanks,
Tom
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: midwayfair on December 02, 2015, 09:00:04 AM
Quote from: ElectricDruid on December 02, 2015, 08:42:45 AM
Quote from: garcho on December 01, 2015, 01:00:00 AM
i was thinking there would be a way to add depth control later, say, after the filter (or LED/LDR)? like a CV in?

I agree, I think. I'd thought how to reduce the pin count, and reckon the Depth pot is the obvious one to drop. In many situations, adding a depth control after the LFO isn't too difficult. Still, it's a pity...but you can't have everything, I guess. Or not on an 8-pin chip, anyway.

It's really excellent to see these ideas. Helps no end.

Thanks,
Tom

It's also "easy" to invert the phase of the signal so you have two out-of-phase PWMs as long as you're willing to add more parts. Leaving off the depth means that you have to add at least one more active component, a transistor at the very minimum (which will result in a kind of lousy depth control) and better two transistors or an op amp. Even if you add a transistor, between the three pins on the transistor itself and the couple of resistors to make it work, you're back up to as much space and PCB connections as the TAPLFO's 14-pin chip.

Not that this is "my" project or thread, but my whole reason for asking in the first place was to see if there was something that could do better waveform outputs in a package as small as a regular dual op amp so the chip would be more useful for small projects, and suddenly we're talking about adding tap tempo and multiplier steps and dropping the depth control for them! That's silly from a design standpoint. If you have space for a second footswitch, you certainly have space to use a 14-pin DIL.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: free electron on December 02, 2015, 09:19:06 AM
Another advantage of external Depth control is it doesn't reduce the bit depth of the PWM generated waveform, which is happening if the waveform is scaled down in the software.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: garcho on December 02, 2015, 01:15:54 PM
Quote...and suddenly we're talking about adding tap tempo and multiplier steps and dropping the depth control for them! That's silly from a design standpoint. If you have space for a second footswitch, you certainly have space to use a 14-pin DIL.

Suddenly? The title of your post, from over a year ago, says "smaller LFO chip". Sorry if I didn't respect that the thread was about the smaller chip that specifically you want.

For me, the point of having tap tempo and multiplier is to have an easy way to sync the LFO with another control source via 1/4" jack, not to add a tap tempo foot switch, which personally, I don't use, for a number of reasons. Without that, how would you control the rate externally? Certainly not "silly".

QuoteLeaving off the depth means that you have to add at least one more active component, a transistor at the very minimum (which will result in a kind of lousy depth control) and better two transistors or an op amp.
That's certainly not always true. Do you use CV? Or only LED/LDR opto stuff? Either way, good l' passive potentiometers work as depth controls all the time, easy. The textbook "tremulus lune" LFO is made from an 8 pin IC that does a lot (minus real sine and random, which is maybe exactly what you want, i get it), and has a passive potentiometer for depth control and is the opto style that I've seen you use frequently. What it doesn't do is sync.

QuoteIf there's a desire to see 8-pin PIC LFOs out there in world, I'd be happy to have some in the Druid shop, now I've got it set up properly (took a while...). What's the favourite set of features? Or what's the top applications?

why wouldn't i respond to the man that brought us the TAPLFO? i've used that chip, and other LFOs many times before, and that's what came to mind. Tom and Slacker both mentioned external depth as well, so maybe it's not "silly"?

QuoteIt's really excellent to see these ideas. Helps no end.

glad my points weren't just aggravating and OT, even if they're bad ideas.  ;)

EDIT:
I didn't want this to come off defensive or snarky, but it probably did. sorry y'all
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on December 02, 2015, 04:35:08 PM
>It's also "easy" to invert the phase of the signal...

I never managed to get this to work very well using a PNP transistor. It worked, but the response was not completely inverse to the LED driven with a PNP.

Also, I haven't been buffering the LEDs with these newer chips and with modest LED resistors it seems to work fine - keeps the parts count down further.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on December 02, 2015, 04:40:44 PM
>Another advantage of external Depth control is it doesn't reduce the bit depth of the PWM generated waveform, which is happening if the waveform is scaled down in the software.

True, but I have been using an 8 bit unsigned wave table and the sweep has sounded pretty smooth. It's also a trade off against how much resolution you need out of the depth pot and there is not much program memory on the 12F1612, so something may have to go if you want a much higher resolution wavetable(s).
If it's a real concern then I can revisit this.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on December 02, 2015, 04:53:50 PM
>my whole reason for asking in the first place was to see if there was something that could do better waveform outputs in a package as small as a regular dual op amp so the chip would be more useful for small projects

This is definitely one thing that would be worth implementing properly.
I would keep depth, speed and waveform controls. We could have 2 outputs that are 2 different degree out of phase (or not, selected via a switch). Alternatively, if you only want 1 output, we have room for another pot and some form of switch. Any thoughts?

>and suddenly we're talking about adding tap tempo and multiplier steps and dropping the depth control for them! That's silly from a design standpoint. If you have space for a second footswitch, you certainly have space to use a 14-pin DIL.

Mission creep. There are good 14 pin chips that could be used to do most/all of the requests, so I don't see there being much point compromising on e.g. a depth control to fit everything into an 8 pin package for a 'product' that is intended to be a 1-size-fits-all chip.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: ElectricDruid on December 02, 2015, 04:58:44 PM
Quote from: samhay on December 02, 2015, 04:40:44 PM
>Another advantage of external Depth control is it doesn't reduce the bit depth of the PWM generated waveform, which is happening if the waveform is scaled down in the software.

True, but I have been using an 8 bit unsigned wave table and the sweep has sounded pretty smooth. It's also a trade off against how much resolution you need out of the depth pot and there is not much program memory on the 12F1612, so something may have to go if you want a much higher resolution wavetable(s).
If it's a real concern then I can revisit this.

The reduction in bit depth when you use a software depth control is a concern, certainly. It's a trade-off, as ever - in this case, simplicity against resolution. For some designs, I've wondered about using MCP4922 DACs, which (a) are 12-bit, which is an improvement over the PIC's PWM*, (b) are proper DACS, so don't need such extreme filters, and (c) are multiplying DACs, so you can feed a "Depth CV" into the Vref input on the DAC and you get full resolution at any level. It's certainly appealing, but it makes it into two chips, etc etc.

If the program memory is a concern on the 12F1612, could you not interpolate between the table points a bit? I've sometimes saved memory by (say) reducing a 256 entry table to 128 or 64 entries, and then using a (very simple) two bit interpolation to put the missing entries back again. For many things, no-one notices. It's a useful trick to know.

Finally - Mission Creep. Hohoho! Yep, we know that one! Most of my missions have got more creep than Radiohead!

HTH,
Tom

*Some of the recent PICs have a 16-bit PWM module, but I haven't looked into it yet, and I seriously doubt it would give 16-bit resolution at a frequency useful to act as a DAC. I may be wrong. In fact, I'd *love* to be wrong.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on December 02, 2015, 05:15:13 PM
I figured I would reduce the size of the array if I had to - haven't quite got stuck yet, but some of the arrays now use Char instead of Int, which helps with the crap optimisation in the free xc8 compiler.
Linear interpolation is certainly easy (and cheap) enough to do.

I haven't seen any PICs that can do a 16-bit PWM with a frequency above the audio range. I don't look too closely at those that are not available through hole though.

This doesn't directly help those that can't program chips, but perhaps it would be good to start a microcontroller code library.

If Mr X wants a chip with X features that doesn't exist, they post a request.
Mr Y writes then writes some code and posts it.
So far this is pretty familiar, as it is how the popular vero layout sites work. I would imagine there are enough Mr (or Mrs, or Dr or whatever) Y's that will do this with no expectation of enumeration.

Now, this only works for Mr X if Mr Y or Mr Z (who preferably is in Mr X's neighbourhood) then program a chip for Mr X and pop it in the post.
Someone is going to have to pay for the chips and postage, so this part gets more tricky and there isn't much in it for Mr Z unless this is runs as a business.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: ElectricDruid on December 03, 2015, 07:10:19 AM
Quote from: samhay on December 02, 2015, 05:15:13 PM
If Mr X wants a chip with X features that doesn't exist, they post a request.
Mr Y writes then writes some code and posts it.
So far this is pretty familiar, as it is how the popular vero layout sites work. I would imagine there are enough Mr (or Mrs, or Dr or whatever) Y's that will do this with no expectation of enumeration.

Now, this only works for Mr X if Mr Y or Mr Z (who preferably is in Mr X's neighbourhood) then program a chip for Mr X and pop it in the post.
Someone is going to have to pay for the chips and postage, so this part gets more tricky and there isn't much in it for Mr Z unless this is runs as a business.

It might be possible to offer the required code blocks for people to download and program onto a chip themselves. It might even be possible to offer a webpage that could *generate* your own semi-custom code by selecting different prewritten routines and waveform tables, and then once you'd selected what you want, you download it and program it. I like the idea, and I might give it a try. But I'm not offering to do the programming for you - too tedious and time-consuming, especially for lots of one-offs. As you say, this gets tricky. I can sell chips as a business (and I do, as of recently), but I need designs that I can order in quantities of several hundred, otherwise it isn't really worthwhile.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on December 04, 2015, 09:33:09 AM
>But I'm not offering to do the programming for you - too tedious and time-consuming, especially for lots of one-offs. As you say, this gets tricky. I can sell chips as a business (and I do, as of recently), but I need designs that I can order in quantities of several hundred, otherwise it isn't really worthwhile.

I wasn't suggesting that you be Mr Y. In fact, I was a little weary of suggesting it at all, as I don't want it to cut into your business.
At the end of the day, maybe more people will just have to make the £20-odd investment in a programmer and become self sufficient.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: garcho on December 04, 2015, 10:17:00 AM
QuoteAt the end of the day, maybe more people will just have to make the £20-odd investment in a programmer and become self sufficient.

"DIY" stompboxes  ;)
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: samhay on December 04, 2015, 11:04:08 AM
Gary - if you fancy going down this route, look into PICkit clones, which are typically quite a bit cheaper than the microchip offering.
However, do a little homework though as some of the real cheap ones may not work very well. I have an Olimex PICkit 3 clone, which seems to do everything it should.
Title: Re: Is there a SMALLER digital LFO chip than the TAPLFO?
Post by: ElectricDruid on December 05, 2015, 05:41:41 AM
Quote from: garcho on December 04, 2015, 10:17:00 AM
QuoteAt the end of the day, maybe more people will just have to make the £20-odd investment in a programmer and become self sufficient.

"DIY" stompboxes  ;)

Exactly! :)