Author |
Message |
gby
Joined: Jan 23, 2020 Posts: 3 Location: Belgium
|
Posted: Thu Jan 23, 2020 11:35 am Post subject:
PIC Wave generation |
 |
|
Hey everyone,
So I'm an enginnering student and we have a project where we have to build a PIC processor based Bass Synthisizer. We are only in the brainstorming phase for now and I was thinking:
Do you think it would be smarter to create a PWM square wave signal for the wave generation from the PIC and then put it through certain analog filters to make other waves or to make the initial wave a PWM based Sine wave and then filter it for different wave shapes?
Thanks already  |
|
Back to top
|
|
 |
Grumble

Joined: Nov 23, 2015 Posts: 1310 Location: Netherlands
Audio files: 30
|
Posted: Thu Jan 23, 2020 2:33 pm Post subject:
|
 |
|
A sine wave thru a filter is only more or less attenuated, to hear the filter doing its thing you have to have a wave with a spectrum containing a lot of frequencies like a square, pulse, triangle or saw-wave. _________________ my synth |
|
Back to top
|
|
 |
blue hell
Site Admin

Joined: Apr 03, 2004 Posts: 24388 Location: The Netherlands, Enschede
Audio files: 296
G2 patch files: 320
|
Posted: Thu Jan 23, 2020 2:35 pm Post subject:
|
 |
|
Hi gby &
What PIC do you have in mind and on what frequency will/can it run?
And .. smarter than what  _________________ Jan
also .. could someone please turn down the thermostat a bit.
 |
|
Back to top
|
|
 |
Electric Druid

Joined: Mar 13, 2012 Posts: 44 Location: UK
|
Posted: Fri Jan 24, 2020 6:20 pm Post subject:
Re: PIC Wave generation |
 |
|
gby wrote: | Hey everyone,
So I'm an enginnering student and we have a project where we have to build a PIC processor based Bass Synthisizer. We are only in the brainstorming phase for now and I was thinking:
Do you think it would be smarter to create a PWM square wave signal for the wave generation from the PIC and then put it through certain analog filters to make other waves or to make the initial wave a PWM based Sine wave and then filter it for different wave shapes?
Thanks already  |
Given that this is a "bass synthesiser", I read that as "ignore aliasing"! That makes life a lot simpler. All you need to do is choose a PIC that can output audio at a reasonable quality and generate the waveforms. Beyond that, the algorithm is entirely up to you. Personally, I'd recommend something with a genuine DAC on the chip like the PIC 16F1765 (10-bit DAC). That doesn't sound like much, but for a VCO replacement where the waveform is always at maximum volume, it's not actually half bad! I did my PIC VCDO using an 8-bit PWM output (e.g. much worse quality) and that has still been a successful chip. Ok, it's not everyone's cup of tea, but it has it's own character and is not so noisy as to be unusable by any stretch. The 10-bit DAC chip will be a marked improvement over that.
When you're struggling with Flash memory for your waveforms, remember that most waveforms are symmetric from one half to the other (rotationally, often), and some (sine wave) have symmetry that means you only need to store a quarter waveform. This saves no end of program memory, and let's you get an unfeasible amount of waveforms into a very tiny chip!
This piece by Jet Holt about the development of the Frequency Central Chronograf might give you a few ideas:
https://jetholt.com/chronograf-its-about-time/
HTH,
Tom
References:
https://electricdruid.net/voltage-controlled-digital-oscillator-vcdo1/ _________________ Electric Druid Synth and Pedal DIY website |
|
Back to top
|
|
 |
gby
Joined: Jan 23, 2020 Posts: 3 Location: Belgium
|
Posted: Sat Jan 25, 2020 8:09 am Post subject:
|
 |
|
Blue Hell wrote: | Hi gby &
What PIC do you have in mind and on what frequency will/can it run?
And .. smarter than what  |
Hey, thanks
I have a PIC18F25K. We haven't decided exactly on the frequency range we want the synth to generate.
But now that you mention it, I'm starting to think maybe we won't be able to generate low frequencies as a sine wave anyways because the lowest clock speed we can choose is a 31.25kHz and even with the 1:256 prescaler we will have 122Hz minimum. So I guess we will have to go with a Square wave from the beginning.
Yeah since I'm new to this, I thought perhaps there was already a rule of thumb about the initial shape you generate because of this or that reason that I didn't know about. So that's what I meant by smarter I guess  |
|
Back to top
|
|
 |
gby
Joined: Jan 23, 2020 Posts: 3 Location: Belgium
|
Posted: Sat Jan 25, 2020 8:32 am Post subject:
Re: PIC Wave generation |
 |
|
Electric Druid wrote: | gby wrote: | Hey everyone,
So I'm an enginnering student and we have a project where we have to build a PIC processor based Bass Synthisizer. We are only in the brainstorming phase for now and I was thinking:
Do you think it would be smarter to create a PWM square wave signal for the wave generation from the PIC and then put it through certain analog filters to make other waves or to make the initial wave a PWM based Sine wave and then filter it for different wave shapes?
Thanks already  |
Given that this is a "bass synthesiser", I read that as "ignore aliasing"! That makes life a lot simpler. All you need to do is choose a PIC that can output audio at a reasonable quality and generate the waveforms. Beyond that, the algorithm is entirely up to you. Personally, I'd recommend something with a genuine DAC on the chip like the PIC 16F1765 (10-bit DAC). That doesn't sound like much, but for a VCO replacement where the waveform is always at maximum volume, it's not actually half bad! I did my PIC VCDO using an 8-bit PWM output (e.g. much worse quality) and that has still been a successful chip. Ok, it's not everyone's cup of tea, but it has it's own character and is not so noisy as to be unusable by any stretch. The 10-bit DAC chip will be a marked improvement over that.
When you're struggling with Flash memory for your waveforms, remember that most waveforms are symmetric from one half to the other (rotationally, often), and some (sine wave) have symmetry that means you only need to store a quarter waveform. This saves no end of program memory, and let's you get an unfeasible amount of waveforms into a very tiny chip!
This piece by Jet Holt about the development of the Frequency Central Chronograf might give you a few ideas:
https://jetholt.com/chronograf-its-about-time/
HTH,
Tom
References:
https://electricdruid.net/voltage-controlled-digital-oscillator-vcdo1/ |
Firstly, thanks a lot this looks really helpful.
Secondly, we already have a PIC18F25K from our other classes so we thought we would just use that. It has a DAC module but it's only 32 steps so I guess it wouldn't really be very high quality.
We are allowed to use analog filters after the digital wave generation, so i guess we could still smooth it out if it's not good enough. But what we had in mind from the beggining was to use the PWM module.
Thanks a lot for the tips as well, I think I might be updating this post when we have some more progress as well  |
|
Back to top
|
|
 |
Electric Druid

Joined: Mar 13, 2012 Posts: 44 Location: UK
|
Posted: Sat Jan 25, 2020 4:11 pm Post subject:
Re: PIC Wave generation |
 |
|
gby wrote: |
Firstly, thanks a lot this looks really helpful.
Secondly, we already have a PIC18F25K from our other classes so we thought we would just use that. It has a DAC module but it's only 32 steps so I guess it wouldn't really be very high quality.
We are allowed to use analog filters after the digital wave generation, so i guess we could still smooth it out if it's not good enough. But what we had in mind from the beggining was to use the PWM module.
Thanks a lot for the tips as well, I think I might be updating this post when we have some more progress as well  |
If you've only got a 5-bit DAC, you'd be better off using the NCO to produce a PDM output, rather than using a PWM output. You just use the NCO in "fixed pulse width" mode and then the frequency increment sets the density of output pulses. This provides a higher output frequency and smoother output than PWM usually manages. I've had 2 MHz output at 16-bit resolution instead of 10-bit at 32.5KHZ, for example. It makes a big difference.
HTH,
Tom _________________ Electric Druid Synth and Pedal DIY website |
|
Back to top
|
|
 |
gabbagabi

Joined: Nov 29, 2008 Posts: 652 Location: Berlin by n8
Audio files: 23
|
Posted: Wed Jan 29, 2020 4:49 am Post subject:
|
 |
|
NCO? PDM? WTF?
Never hears about that (new) feature,
very interesting indeed!
 |
|
Back to top
|
|
 |
ian-s

Joined: Apr 01, 2004 Posts: 2672 Location: Auckland, New Zealand
Audio files: 42
G2 patch files: 626
|
Posted: Thu Jan 30, 2020 12:24 am Post subject:
|
 |
|
NCO => PDM? very interesting.
I found this app note but it looks like you found a less complicated way of doing it.
Do you use the technique in any of your published projects Tom? |
|
Back to top
|
|
 |
Electric Druid

Joined: Mar 13, 2012 Posts: 44 Location: UK
|
Posted: Wed Jul 22, 2020 2:07 pm Post subject:
|
 |
|
ian-s wrote: | NCO => PDM? very interesting.
I found this app note but it looks like you found a less complicated way of doing it.
Do you use the technique in any of your published projects Tom? |
Sorry, haven't been back around here for while, so I've only just seen this.
Yes, the STOMPLFO uses this for its output.
The NCO module on some of the newer "enhanced" 16F PICs has a "Pulse Frequency" mode. Basically this produces a short fixed pulse every time the NCO wraps around. Since how often the NCO wraps around is directly related to how large the Frequency increment is, you've got output pulses whose density is related linearly to the frequency increment. Since the frequency increment on the chips is 16 or 20-bit, you've got a lot more resolution than you'd typically get with PWM. And the clock frequency is much higher too, since the NCO runs at the instruction rate or some fraction of it, so MHz. This makes the subsequent filtering much less demanding. You can get lovely clean LFO waveforms out of the STOMPLFO with only a RC lowpass.
It's great. I don't think it's what they had in mind for the NCO module, but it does a good job and it's much better than the PWM modules.
I think there might be some 18F chips with two NCOs too - am yet to look into that, but it sounds good if true.
Tom
PS: DSP-G1 chip used the same technique on a completely different processor (NXP LPC800 series) as far as I know. _________________ Electric Druid Synth and Pedal DIY website |
|
Back to top
|
|
 |
|