Sunday, February 7, 2010

Voltage Controlled Wave Table Oscillator (v 0.1)

I was inspiried by the VC LFO and VC ADSR made using the pic16f684, so I was wondering if I could make a wavetable oscillator at Audio frequencies using the same chip. The answer is yes...

The basic idea is to use the PWM module to produce a square pulse train with a duty cycle that varies according to a lookup table. Then by filtering out the carrier signal, only the desired value for the waveform remains. This is the same method (as far as I can tell) as the above links, and definitely not anything new.

Externally, 2 pins are assigned for the crystal, 2 ADC channels for pitch and PWM (square wave only), 4 pins for waveform selection, one for trigger, and one for PWM output. This still leaves 2 open pins, which I have some ideas for below.

The software loops around reading the ADC channels, and updating the appropriate registers. A timer keeps track of when to process the next sample and update the PWM. Each waveform is contained in a 64x8Bit array. Although practically to achieve higher speeds, I can only use 7 bits (and not the full range of the 7 either). This means that the wave forms to have distortion in them, and if this were going in a function generator, it most likely would not be suitable. How ever for audio applications, distortion is not always a bad thing.

The 4 pins for wave form selection give 16 possible waves. The first 4 are the classics: Triangle, Saw, Square, and Sine. After that the next 8 are more arbitrary waveforms (exponentials, staircases, 2-slope ramps... and such). The last 4 are reserved for pseudo-random noises.

In it's current configuration, the lowest frequency is ~100Hz and the highest is ~7KHz. However this can be adjusted in software by changing one of the timers. At higher frequencies, the filter attenuates the waveform. In fact you can see that there is some ringing in the waves with sharp transitions (square, saw) caused by less then ideal filtering. By lowering the cutoff of the filter, I was able to avoid the ringing, however at the cost of more attenuation at high frequency.

The pseudo-random noise routines I use are also less than ideal. There is a definite pitch dependence of the noise, which makes it not truly random. I plan to use this for the time being, since it can create some interesting audio effects. The four different noises also each have their own character, with some being cleaner then the others.

For the next iteration of this VCO, I plan to make a few notable improvements. I want to get rid of the noise waveforms on the last 4 slots and replace them with some other arbitrary wave. To compensate, I want to use one of the free pins as VC Noise mixer, where 0V would be no noise, 5V would be all noise, and in between would be a weighted mix of noise and the currently selected waveform. I also plan to improve the filter. Moving to a 4 pole filter, and perhaps a different type. I admit that analog filters are one of my weakest EE subjects.

No comments: