DIYstompboxes.com

DIY Stompboxes => Digital & DSP => Topic started by: MstrKurt on November 20, 2013, 11:35:51 PM

Title: Multi Effects Pedal
Post by: MstrKurt on November 20, 2013, 11:35:51 PM
Hey guys,

I found this forum while researching dsPIC's and Audio Processing and found that it could benefit me greatly both for my final year major project (Computer Systems & Electronics) in uni and later in life.

My project is to create a Multi Effects Guitar Pedal that is controlled by a dsPIC33F32GP302; The initial effects I plan to create are Distortion, Delay, Chorus, Phaser, Wah.

I was wondering where you guys would recommend I begin learning to create/program these effects to the dsPIC. I have a basic knowledge of PIC programming thus far, how difficult do you guys think this project will be?.

Thanks for having me.
Title: Re: Multi Effects Pedal
Post by: potul on November 22, 2013, 06:05:09 AM
dsPIC audio will not be hi-fi.... you know. Unless you use an external DAC.

But I programmed some dsPIC effects and they sounded great. You can see it in action here:

https://www.youtube.com/watch?v=Yj0t6TNvrgM (https://www.youtube.com/watch?v=Yj0t6TNvrgM)

The most complicated thing to learn is how to manage the dspic itself. Memory mapping, registers, and get the ADC DAC working properly. Once you get there and you are able to input / output sound of your dspic, things get easier.

One of the beiggest limitations of dsPIC is the amount of available memory. If you want to implement delays... you might need some kind of external memory.

Regards


Title: Re: Multi Effects Pedal
Post by: MstrKurt on November 22, 2013, 12:29:37 PM
Thanks a lot for your input Potul!.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on November 22, 2013, 12:31:01 PM
What dsPIC did you use for that btw?.
Title: Re: Multi Effects Pedal
Post by: slacker on November 22, 2013, 12:39:38 PM
Quote from: potul on November 22, 2013, 06:05:09 AM
https://www.youtube.com/watch?v=Yj0t6TNvrgM (https://www.youtube.com/watch?v=Yj0t6TNvrgM)

I saw that video a few weeks ago, didn't know it was you Potul, nice work.

Title: Re: Multi Effects Pedal
Post by: cloudscapes on November 22, 2013, 07:11:03 PM
I wouldn't use the dsPIC's internal DAC and ADC for audio. They're fine for tests, but not really that great for more. Last I heard, the DAC's 4 or 5 LSB's were so noisy that they might as well not exist, and that it's more like a 10bit DAC. Even using an external 12bit MCP3201 and equivalent DAC would be better. Proper audio ADCs and DACs have to be properly decoupled and seperated from a microcontroller, which is a huge source of digital noise. With its own star grounding and ground plane for best results. At least if you're aiming for 16 usable bits or better.

One thing the dsPIC has going for it is an I2S controller. I don't have any details or experience, but I've read that interfacing the dsPIC to a codec works pretty well, and that's it's possible to achieve a high samplerate and bit depth! I'd say go for it!

Lately I've been trying to get a PIC32 to work with a WM8731 codec. Hasn't been very easy so far.
Title: Re: Multi Effects Pedal
Post by: g_u_e_s_t on November 22, 2013, 08:02:45 PM
ive havent used PICs much, but have done a lot with the wm8731, so i can give pointers if needed.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on November 23, 2013, 09:53:31 AM
Ok, so the general consensus is to use external ADC's and DAC's?

Are there any other PICs you'd recommend that I can program with a PICkit 3?

If my best shot is the dsPIC could you recommend a specific model that would allow the highest quality of audio and is programmable using Assembly?.

Thanks a lot for your input so far guys, I appreciate it.
Title: Re: Multi Effects Pedal
Post by: cloudscapes on November 23, 2013, 02:42:28 PM
Quote from: MstrKurt on November 23, 2013, 09:53:31 AM
Ok, so the general consensus is to use external ADC's and DAC's?

Are there any other PICs you'd recommend that I can program with a PICkit 3?

If my best shot is the dsPIC could you recommend a specific model that would allow the highest quality of audio and is programmable using Assembly?.

Thanks a lot for your input so far guys, I appreciate it.

I don't know about general consensus, but basically if you're fine with lofi (or at the most midfi) audio, then you can use the dsPIC's internal converters. Just don't expect lots of precision or a low noise floor. It might be fine when you're starting out and trying to get a handly on the microcontroller, then later you can upgrade your effect with some good external converters.

Based on my extremely limited experience in dsPICs, go for the dsPIC33 line of chips, not dsPIC30. The 33's are much more powerful. As for actual "audio quality" that will depend more on your program, and how well you use internal or external ADC/DAC converters than the actual type of dsPIC.
Title: Re: Multi Effects Pedal
Post by: cloudscapes on November 23, 2013, 02:47:08 PM
Quote from: g_u_e_s_t on November 22, 2013, 08:02:45 PM
ive havent used PICs much, but have done a lot with the wm8731, so i can give pointers if needed.

I think my problems are more with the PIC32 and how it does frame mode SPI and interrupts. The wm8731 was tricky at first, but I think I got it to sort of work on its own, setting it as the master with its own clock. I can throw words at the codec and have it work like a DAC, and based on what I'm seeing on my scope it seems to be at least attempting to give me ADC sample data. The trouble is more with the PIC and its SPI buffer, sitting there and pretending it isn't receiving anything when through the scope I can see it obviously is. Probably configuration bits or the order I'm doing things. Discouraging because I've been at it for weeks.

And because datasheets aren't my strength, and configuration bits that look nothing like actual words are really really confusing.
Title: Re: Multi Effects Pedal
Post by: g_u_e_s_t on November 24, 2013, 06:43:40 AM
if you let me know which pic32 youre using, i can have a look at the datasheet at some point, and see if i see anything.  the wm8731 doesnt really do SPI, it does something really close, so i wouldnt be suprised if the pic32 was getting a bit confused.  are you using the wm8731 in I2S mode or microcontroller mode?
Title: Re: Multi Effects Pedal
Post by: cloudscapes on November 24, 2013, 08:38:26 AM
Running the codec in master DSP mode. Using a PIC32MX575F256L so there's no I2S mode, I'm told only DSP will work because the pic won't handle left-right frame shifting in I2S. MSB and LSB modes don't seem to work either. At least with my configuration.

I appreciate the offer, you don't have to though. I'll work on it a bit longer, but I think I might switch to ARM soon. There are a bunch of other things I like less about the PIC32, so that decision might've been overdue. Already ordered the STM32F4 Discovery board and will have a go as soon as I pick an IDE. I seem to have an easier time finding ARM documentation in audio projects, such as this one: http://ebrombaugh.studionebula.com/synth/stm32f4_codec/
Title: Re: Multi Effects Pedal
Post by: g_u_e_s_t on November 25, 2013, 03:16:40 AM
ive had some luck getting the wm8731 to work with the stm32's, via the maple platform.  i used the codec in slave mode, as the SS pin is only briefly toggled in DSP mode, which doesnt match what the microcontroller is expecting.  most microcontrollers want the SS line held high for the duration of the transfer, and then interrupt on the falling edge.
Title: Re: Multi Effects Pedal
Post by: cloudscapes on November 25, 2013, 12:59:46 PM
Yeah the maple platform looks pretty interesting. I've never used arduino but I admit the library and community support makes it appealing. And in the case of maple, I saw there's a wm8731 board that's compatible with it (with sources)

the 3 maple boards
http://leaflabs.com/devices/
seem to only be STM32F1's. How easy is it to use the maple IDE with your own JTAG programmer and boards, if you don't mind my asking?

I don't really have a clue, because usually everything arduino sort of advertises itself as board+bootloader, not IDE+chip.
Title: Re: Multi Effects Pedal
Post by: g_u_e_s_t on November 25, 2013, 09:28:27 PM
i am pretty sure there is a JTAG header on the maple boards.  i program them with their IDE, so i cant say for sure, though.  if you feel comfortable using your own tools, its probably better to just get started with the stm32f4 series, as they have more dsp support.  they also have native I2S, if i recall correctly.  i guess the nice thing about the maple native, is that it has built in SRAM, so you could just get up and running with it.
Title: Re: Multi Effects Pedal
Post by: cloudscapes on November 27, 2013, 08:49:37 PM
Hmm.. I meant more in the sense of using the maple IDE with chips that are not of those three/four boards. STM32 chips of my own choosing.

I did do some more research since I last posted, though, think I got my answer. The IDE apparently supports one STM32F4 chip, and they tried that with the maple II board, but it's discontinued. There is semi-support for new chips, best I can gather. Not sure if that's good enough for me. Might go with the coocox IDE instead, since it's more "general" and doesn't appear to be tied with specific boards.
Title: Re: Multi Effects Pedal
Post by: potul on November 28, 2013, 06:43:52 AM
Hi again everybody.

For some reason I dropped my initial answer and forgot about this thread... and I realize now that some interesting discussion has been going on.

I agree with Cloudscapes, ADC/DAC in dsPIC are not hifi... so it will not fit all needs.
It highly depends on what you want to achieve. In my case, I was looking for the possibility of creating crazy effects, so I didn't care much about quality, 10bits looked good enough.

Regarding the model, I agree too on using dsPIC33 models. These are by far the best ones, very powerful, they do have FFT, autocorrelation and similar functions out of the box. BTW, these are optimized for C, so better forget about Assembly.
In my test project I used a dsPIC33FJ128GP802 because it was the one that was matching my needs in terms of I/O and memory. And I got if for free as a sample from Microchip  :icon_cool:

Nowadays I have this project unfinished in a carton box, waiting... I'm playing with my new Raspberry PI   ;D
Title: Re: Multi Effects Pedal
Post by: MstrKurt on December 23, 2013, 01:01:45 PM
Can any moderators delete my other topics since I seem to be taking up the front of this forum haha. I will keep this thread as the one to continue with.

Can anyone explain to me why external memory is needed for delay?, and why a for loop cannot be used to delay the time until the next delay hits the output.

output = currentsignal;
for(x=1;x<100;x++);
{
}
output = lastsignal;
Title: Re: Multi Effects Pedal
Post by: cloudscapes on December 23, 2013, 04:24:09 PM
Quote from: MstrKurt on December 23, 2013, 01:01:45 PM
Can anyone explain to me why external memory is needed for delay?, and why a for loop cannot be used to delay the time until the next delay hits the output.

output = currentsignal;
for(x=1;x<100;x++);
{
}
output = lastsignal;


I wouldn't use for while loops to actually define your sample delay. it's not terribly accurate, and your processor can't do a whole lot while it "waits" for the next loop. it's probably better to use a timer interrupt instead. I've made several samplers/loopers/delays on pic and avr using timers. it frees up the processor to do important stuff like math, sampling pots, etc.

you can use any kind of memory for delay, internal or external. internal delay will be easier to use (just a sample word array as long as you need your delay time to be) and will be faster, but you'll have less of it. which dspic are you using? I can't find the one you mention in your original post.

external delay is a bit trickier to use, but you'll have a lot more of it
Title: Re: Multi Effects Pedal
Post by: MstrKurt on December 23, 2013, 05:18:40 PM
Quote from: cloudscapes on December 23, 2013, 04:24:09 PM
Quote from: MstrKurt on December 23, 2013, 01:01:45 PM
Can anyone explain to me why external memory is needed for delay?, and why a for loop cannot be used to delay the time until the next delay hits the output.

output = currentsignal;
for(x=1;x<100;x++);
{
}
output = lastsignal;


I wouldn't use for while loops to actually define your sample delay. it's not terribly accurate, and your processor can't do a whole lot while it "waits" for the next loop. it's probably better to use a timer interrupt instead. I've made several samplers/loopers/delays on pic and avr using timers. it frees up the processor to do important stuff like math, sampling pots, etc.

you can use any kind of memory for delay, internal or external. internal delay will be easier to use (just a sample word array as long as you need your delay time to be) and will be faster, but you'll have less of it. which dspic are you using? I can't find the one you mention in your original post.

external delay is a bit trickier to use, but you'll have a lot more of it

I'm currently using the dsPIC33FJ32GP202: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en530332 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en530332)
But I have a dsPIC33FJ128GP802 coming on the 27th: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en532298 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en532298)

I don't know much about interrupts in PIC's but what about using __delay32_(x) ?
Title: Re: Multi Effects Pedal
Post by: cloudscapes on December 23, 2013, 05:44:12 PM
Quote from: MstrKurt on December 23, 2013, 05:18:40 PM

I'm currently using the dsPIC33FJ32GP202: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en530332 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en530332)
But I have a dsPIC33FJ128GP802 coming on the 27th: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en532298 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en532298)

I don't know much about interrupts in PIC's but what about using __delay32_(x) ?

Yeah, you're not gonna get much delay time with the first chip you linked to. second one looks promising though, memory wise! good for 200-500ms delay depending on how you stretch your samplerate and bitdepth. otherwise, you can use one of these:
http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=270221&mid=&lang=en
They're very easy to use and will give you ten times the ram. Downside is that they use a serial interface, meaning they'll use up a bit of processor time each sample read/write.

I'm not familiar with __delay32_(x), but I imagine it's a delay library where x in the number of milliseconds or nanoseconds? personally I wouldn't use that for the same reason I wouldn't use loops. while your pic is "waiting" for the delay to run out, it can't do anything. it's frozen. you can't send or receive memory to external ram, can't perform calculations, can't sample pots, etc. you'll still be able to build a delay with it, but you'll be limited in how high you can set your samplerate. it can be done, it just won't be efficient or flexible. once you get your delay working using a loop or wait delay, I'd look into adapting timers and interrupts to it afterwards.

a wait delay basically puts your processor on ice for a duration you enter. while it may "work" for the end product, you aren't using the processor to its full potential because it's on ice a percentage of the time. wasted cycles means lower samplerate for the audio.

a timer interrupt is like a kitchen timer that you set to ring every fraction of a second, nanosecond, whatever. when it rings, it runs whatever function you tell it to, whether it's to push audio from the adc to memory and to the dac, perform a math calculation, etc. this may be a bit advanced for you though, so maybe try it with the loop or delay32, even if you'll be limited. but for the sake of information, I like to run a few timers for my samplers/loopers:

-one timer that "rings" repeatedly every 10 milliseconds. too slow for audio samples, but fine for sampling control pots, updating display leds, and not audio-centric calculations
-another timer that rings every 23us, or 44,000 times a second. it does very little when it rings, just move audio through memory, a bit of arithmetic, and sample the main audio ADC/DAC. you don't have to sample a control pot 44,000 times a second because the hand controlling it can't move that fast, so its wasted resources. hence using multiple timers.

but yeah, maybe look at timers and interrupts after you get a basic functioning delay/sampler using techniques you're most comfortable with. I guarantee you'll want to look into it later, though.



Title: Re: Multi Effects Pedal
Post by: MstrKurt on December 23, 2013, 05:52:28 PM
Quote from: cloudscapes on December 23, 2013, 05:44:12 PM
Quote from: MstrKurt on December 23, 2013, 05:18:40 PM

I'm currently using the dsPIC33FJ32GP202: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en530332 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en530332)
But I have a dsPIC33FJ128GP802 coming on the 27th: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en532298 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en532298)

I don't know much about interrupts in PIC's but what about using __delay32_(x) ?

Yeah, you're not gonna get much delay time with the first chip you linked to. second one looks promising though, memory wise! good for 200-500ms delay depending on how you stretch your samplerate and bitdepth. otherwise, you can use one of these:
http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=270221&mid=&lang=en
They're very easy to use and will give you ten times the ram. Downside is that they use a serial interface, meaning they'll use up a bit of processor time each sample read/write.

I'm not familiar with __delay32_(x), but I imagine it's a delay library where x in the number of milliseconds or nanoseconds? personally I wouldn't use that for the same reason I wouldn't use loops. while your pic is "waiting" for the delay to run out, it can't do anything. it's frozen. you can't send or receive memory to external ram, can't perform calculations, can't sample pots, etc. you'll still be able to build a delay with it, but you'll be limited in how high you can set your samplerate. it can be done, it just won't be efficient or flexible. once you get your delay working using a loop or wait delay, I'd look into adapting timers and interrupts to it afterwards.

a wait delay basically puts your processor on ice for a duration you enter. while it may "work" for the end product, you aren't using the processor to its full potential because it's on ice a percentage of the time. wasted cycles means lower samplerate for the audio.

a timer interrupt is like a kitchen timer that you set to ring every fraction of a second, nanosecond, whatever. when it rings, it runs whatever function you tell it to, whether it's to push audio from the adc to memory and to the dac, perform a math calculation, etc. this may be a bit advanced for you though, so maybe try it with the loop or delay32, even if you'll be limited. but for the sake of information, I like to run a few timers for my samplers/loopers:

-one timer that "rings" repeatedly every 10 milliseconds. too slow for audio samples, but fine for sampling control pots, updating display leds, and not audio-centric calculations
-another timer that rings every 23us, or 44,000 times a second. it does very little when it rings, just move audio through memory, a bit of arithmetic, and sample the main audio ADC/DAC. you don't have to sample a control pot 44,000 times a second because the hand controlling it can't move that fast, so its wasted resources. hence using multiple timers.

but yeah, maybe look at timers and interrupts after you get a basic functioning delay/sampler using techniques you're most comfortable with. I guarantee you'll want to look into it later, though.





That's the the exact memory module I had in mind if it did turn out I needed one.

Thanks a lot for taking your time to explain to me the reasoning behind needing timer interrupts! I'll do some research on how I can implement these.

I've created a form of Distortion thus far by just creating a clipping point e.g. if(input>value){ input = value;}
However there is a problem that I can't get a clean signal out, (I imagine this is because I have the output coming from a digital output and is sitting on 3.3V DC, or even because I'm not using a DAC at this stage, I will use the DAC when the new chip arrives)
Title: Re: Multi Effects Pedal
Post by: cloudscapes on December 23, 2013, 09:02:45 PM
I forgot to mention a thing in my kitchen timer metaphor. While the processor is "waiting" for the timer to "ring", it can do other stuff. it's not frozen like it would be when using loops to wait, or a wait delay.
Title: Re: Multi Effects Pedal
Post by: potul on December 28, 2013, 02:47:58 AM
Hi MstrKurt,

Based on the pseudo code you entered, I think you need to research a little about delay lines. Delaying a signal is not simply waiting for some time and then output the signal. You need to store in memory all the signal that is received so that you can output it afterwards... This is why the more delay you need, the more memory is required.
This is the reason I told you that with such a PIC, delays are limited to some ms (depending on sampling rate), because the internal memory is small. Adding external memory gives you the ability to have longer delays.

In the project I sent you there is an implemented delay line you can use (with internal memory)
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 03, 2014, 02:07:58 AM
Thanks for clearing that up Pottul :).

Would anyone know of an informative book on various types of audio effects including the background on how they are created / and how they became popular?.
Title: Re: Multi Effects Pedal
Post by: Digital Larry on January 03, 2014, 09:23:13 AM
Here's pretty good reference for a bunch of DSP FX.  Not much on the history, but pretty informative otherwise.

http://www.cs.cf.ac.uk/Dave/CM0268/PDF/10_CM0268_Audio_FX.pdf
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 03, 2014, 02:46:24 PM
Thanks Digital Larry :)

The new chip (dsPIC33FJ128GP802) has arrived, I believe I have everything set up right but Im still hearing some sort of noise when I'm trying to get a clean signal through, and also the signal decays rather quickly to a rather blippy distortion.

Anyone know what could be causing this?.
Title: Re: Multi Effects Pedal
Post by: slacker on January 04, 2014, 08:26:40 AM
How are you getting audio in and out of the chip? A schematic and a look at the code would be useful.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 04, 2014, 09:43:06 AM
(http://i.imgur.com/GOlGSO6.png)

Main Code:
/////////////////////////////////////////////////////////////////////////////////////////////////
// © 2012 Microchip Technology Inc.
//
// MICROCHIP SOFTWARE NOTICE AND DISCLAIMER:  You may use this software, and any
// derivatives created by any person or entity by or on your behalf, exclusively with
// Microchip?s products.  Microchip and its licensors retain all ownership and intellectual
// property rights in the accompanying software and in all derivatives here to.
//
// This software and any accompanying information is for suggestion only.  It does not
// modify Microchip?s standard warranty for its products.  You agree that you are solely
// responsible for testing the software and determining its suitability.  Microchip has
// no obligation to modify, test, certify, or support the software.
//
// THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF NON-INFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION
// WITH MICROCHIP?S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
//
// IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, TORT
// (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT LIABILITY, INDEMNITY,
// CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL
// OR CONSEQUENTIAL LOSS, DAMAGE, FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
// SOFTWARE, HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR
// THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT ALLOWABLE BY LAW, MICROCHIP'S TOTAL
// LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES,
// IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
//
// MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE TERMS.
//
// ****************************************************************************
// ****************************************************************************/
//
// ADDITIONAL NOTES:
// Code Tested on:
// 16-Bit 28-Pin Starter board with dsPIC33FJ128GP802 device
// **********************************************************************/

#include "p33fxxxx.h"
#include "dsp.h"
#include "adcdacDrv.h"

//Macros for Configuration Fuse Registers:
//Invoke macros to set up  device configuration fuse registers.
//The fuses will select the oscillator source, power-up timers, watch-dog
//timers etc. The macros are defined within the device
//header files. The configuration fuse registers reside in Flash memory.



// Internal FRC Oscillator
_FOSCSEL(FNOSC_FRC); // FRC Oscillator
_FOSC(FCKSM_CSECMD & OSCIOFNC_ON  & POSCMD_NONE);
  // Clock Switching is enabled and Fail Safe Clock Monitor is disabled
  // OSC2 Pin Function: OSC2 is Clock Output
  // Primary Oscillator Mode: Disabled

_FWDT(FWDTEN_OFF);                        // Watchdog Timer Enabled/disabled by user software
  // (LPRC can be disabled by clearing SWDTEN bit in RCON register


fractional input;



int main (void)
{
// Configure Oscillator to operate the device at 40MIPS
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 7.37M*43/(2*2)=79.22Mhz for ~40MIPS input clock
PLLFBD             = 41; // M=43
CLKDIVbits.PLLPOST = 0; // N1=2
CLKDIVbits.PLLPRE  = 0; // N2=2
OSCTUN             = 0; // Tune FRC oscillator, if FRC is used

// Disable Watch Dog Timer
RCONbits.SWDTEN=0;

// Clock switch to incorporate PLL
__builtin_write_OSCCONH(0x01);     // Initiate Clock Switch to
    // FRC with PLL (NOSC=0b001)
__builtin_write_OSCCONL(0x01);     // Start clock switching
while (OSCCONbits.COSC != 0b001);  // Wait for Clock switch to occur

// Wait for PLL to lock
while(OSCCONbits.LOCK!=1) {};

initAdc();    // Initialize the A/D converter to convert Channel 4
initDac();    // Initialize the D/A converter
initDma0();   // Initialize the DMA controller to buffer ADC data in conversion order
initTmr3();   // Initialize the Timer to generate sampling event for ADC

extern fractional BufferA[NUMSAMP]; // Ping pong buffer A
extern fractional BufferB[NUMSAMP]; // Ping pong buffer B
extern unsigned int DmaBuffer; // DMA flag
extern int flag; // Flag
int i;

            ;

TRISBbits.TRISB2 = 1;
TRISBbits.TRISB12 = 0;


  while (1)    // Loop Endlessly - Execution is interrupt driven
   {

      while(AD1CON1bits.DONE != 1)
      {

      }
      input = ADC1BUF0;
     
                   if(flag)
                  {
                    for(i = 0; i < NUMSAMP; i++)
                      {
                        while(DAC1STATbits.REMPTY != 1);// Wait for D/A conversion
                          if(DmaBuffer == 0)
                            DAC1RDAT = BufferA[i];     // Load the DAC buffer with data
                              else
                                DAC1RDAT = BufferB[i];  // Load the DAC buffer with data
                        }
                                    flag = 0;
                    }
               }

        DAC1RDAT = input;
           //  return 0;

     
  }


adcdacDrv.c:


/////////////////////////////////////////////////////////////////////////////////////////////////
// © 2012 Microchip Technology Inc.
//
// MICROCHIP SOFTWARE NOTICE AND DISCLAIMER:  You may use this software, and any
// derivatives created by any person or entity by or on your behalf, exclusively with
// Microchip?s products.  Microchip and its licensors retain all ownership and intellectual
// property rights in the accompanying software and in all derivatives here to.
//
// This software and any accompanying information is for suggestion only.  It does not
// modify Microchip?s standard warranty for its products.  You agree that you are solely
// responsible for testing the software and determining its suitability.  Microchip has
// no obligation to modify, test, certify, or support the software.
//
// THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF NON-INFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION
// WITH MICROCHIP?S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
//
// IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, TORT
// (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT LIABILITY, INDEMNITY,
// CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL
// OR CONSEQUENTIAL LOSS, DAMAGE, FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
// SOFTWARE, HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR
// THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT ALLOWABLE BY LAW, MICROCHIP'S TOTAL
// LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES,
// IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
//
// MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE TERMS.
//
// ****************************************************************************
// ****************************************************************************/

#include "p33fxxxx.h"
#include "dsp.h"
#include "adcdacDrv.h"

fractional BufferA[NUMSAMP] __attribute__((space(dma)));  // Ping-pong buffer A
fractional BufferB[NUMSAMP] __attribute__((space(dma)));  // Ping-pong buffer B

/*=============================================================================
initAdc() is used to configure A/D to convert channel 4 on Timer event.
It generates event to DMA on every sample/convert sequence.
=============================================================================*/
void initAdc(void)
{
AD1CON1bits.FORM  = 3; // Data Output Format: Signed Fraction (Q15 format)
AD1CON1bits.SSRC  = 2; // Sample Clock Source: GP Timer starts conversion
AD1CON1bits.ASAM  = 1; // ADC Sample Control: Sampling begins immediately after conversion
AD1CON1bits.AD12B = 1; // 12-bit ADC operation

AD1CON2bits.CHPS = 0; // Converts CH0

AD1CON3bits.ADRC = 0; // ADC Clock is derived from Systems Clock
AD1CON3bits.ADCS = 3; // ADC Conversion Clock Tad=Tcy*(ADCS+1)= (1/40M)*4 = 100ns
// ADC Conversion Time for 12-bit Tc=14*Tad = 1.4us

AD1CON1bits.ADDMABM = 1; // DMA buffers are built in conversion order mode
AD1CON2bits.SMPI    = 0; // SMPI must be 0


//AD1CHS0: A/D Input Select Register
AD1CHS0bits.CH0SA = 4; // MUXA +ve input selection (AN4) for CH0
AD1CHS0bits.CH0NA = 0; // MUXA -ve input selection (Vref-) for CH0
//AD1PCFGH/AD1PCFGL: Port Configuration Register
AD1PCFGL           = 0xFFFF;
AD1PCFGLbits.PCFG4 = 0;     // AN4 as Analog Input


IFS0bits.AD1IF   = 0; // Clear the A/D interrupt flag bit
IEC0bits.AD1IE   = 0; // Do Not Enable A/D interrupt
AD1CON1bits.ADON = 1; // Turn on the A/D converter
}

/*=============================================================================
initDac() is used to configure D/A.
=============================================================================*/
void initDac(void)
{
  /* Initiate DAC Clock */
  ACLKCONbits.SELACLK  = 0;  // FRC w/ Pll as Clock Source
  ACLKCONbits.AOSCMD   = 0;  // Auxiliary Oscillator Disabled
  ACLKCONbits.ASRCSEL  = 0;  // Auxiliary Oscillator is the Clock Source
  ACLKCONbits.APSTSCLR = 7;  // Fvco/1 = 158.2 MHz/1 = 158.2 MHz

  DAC1STATbits.ROEN = 1; // Right Channel DAC Output Enabled
  DAC1DFLT          = 0x8000; // DAC Default value is the midpoint

  // Sampling Rate Fs = DACCLK/256 = 103 kHz
  DAC1CONbits.DACFDIV = 7;   // DACCLK = ACLK/(DACFDIV - 1): 158.2 MHz/6 = 26.4 MHz

  DAC1CONbits.FORM    = 1;   // Data Format is signed integer
  DAC1CONbits.AMPON   = 0;   // Analog Output Amplifier is enabled during Sleep Mode/Stop-in Idle mode

  DAC1CONbits.DACEN   = 1;   // DAC1 Module Enabled
}

/*=======================================================================================
Timer 3 is setup to time-out every Ts secs. As a result, the module
will stop sampling and trigger a conversion on every Timer3 time-out Ts.
At that time, the conversion process starts and completes Tc=12*Tad periods later.
When the conversion completes, the module starts sampling again. However, since Timer3
is already on and counting, about (Ts-Tc)us later, Timer3 will expire again and trigger
next conversion.
=======================================================================================*/
void initTmr3()
{
TMR3          = 0x0000;   // Clear TMR3
PR3           = SAMPPRD;  // Load period value in PR3
IFS0bits.T3IF = 0;    // Clear Timer 3 Interrupt Flag
IEC0bits.T3IE = 0;    // Clear Timer 3 interrupt enable bit

T3CONbits.TON = 1;    // Enable Timer 3
}

/*=============================================================================
DMA0 configuration
Direction: Read from peripheral address 0-x300 (ADC1BUF0) and write to DMA RAM
AMODE: Register indirect with post increment
MODE: Continuous, Ping-Pong Mode
IRQ: ADC Interrupt
ADC stores results stored alternatively between BufferA[] and BufferB[]
=============================================================================*/
void initDma0(void)
{
DMA0CONbits.AMODE = 0; // Configure DMA for Register indirect with post increment
DMA0CONbits.MODE  = 2; // Configure DMA for Continuous Ping-Pong mode

DMA0PAD = (int)&ADC1BUF0;  // Peripheral Address Register: ADC buffer
DMA0CNT = (NUMSAMP-1);     // DMA Transfer Count is (NUMSAMP-1)

DMA0REQ =  13;             // ADC interrupt selected for DMA channel IRQ

DMA0STA = __builtin_dmaoffset(BufferA); // DMA RAM Start Address A
DMA0STB = __builtin_dmaoffset(BufferB); // DMA RAM Start Address B

IFS0bits.DMA0IF  = 0; // Clear the DMA interrupt flag bit
IEC0bits.DMA0IE  = 1; // Set the DMA interrupt enable bit

DMA0CONbits.CHEN = 1; // Enable DMA channel
}

/*=============================================================================
_DMA0Interrupt(): ISR name is chosen from the device linker script.
=============================================================================*/
unsigned int DmaBuffer = 0;
int flag = 0;

void __attribute__((interrupt, no_auto_psv)) _DMA0Interrupt(void)
{
DmaBuffer ^= 1;      // Ping-pong buffer select flag
flag       = 1;      // Ping-pong buffer full flag
IFS0bits.DMA0IF = 0; // Clear the DMA0 Interrupt Flag
}

/*=============================================================================
_DAC1RInterrupt(): ISR name is chosen from the device linker script.
=============================================================================*/
void __attribute__((interrupt, no_auto_psv)) _DAC1RInterrupt(void)
{
  IFS4bits.DAC1RIF = 0; // Clear Right Channel Interrupt Flag
}


addacDrv.h:

/////////////////////////////////////////////////////////////////////////////////////////////////
// © 2012 Microchip Technology Inc.
//
// MICROCHIP SOFTWARE NOTICE AND DISCLAIMER:  You may use this software, and any
// derivatives created by any person or entity by or on your behalf, exclusively with
// Microchip?s products.  Microchip and its licensors retain all ownership and intellectual
// property rights in the accompanying software and in all derivatives here to.
//
// This software and any accompanying information is for suggestion only.  It does not
// modify Microchip?s standard warranty for its products.  You agree that you are solely
// responsible for testing the software and determining its suitability.  Microchip has
// no obligation to modify, test, certify, or support the software.
//
// THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF NON-INFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION
// WITH MICROCHIP?S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
//
// IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, TORT
// (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT LIABILITY, INDEMNITY,
// CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL
// OR CONSEQUENTIAL LOSS, DAMAGE, FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
// SOFTWARE, HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR
// THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT ALLOWABLE BY LAW, MICROCHIP'S TOTAL
// LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES,
// IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
//
// MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE TERMS.
//
// ****************************************************************************
// ****************************************************************************

#ifndef __ADCDRV1_H__
#define __ADCDRV1_H__

// Sampling Control
#define Fosc 79227500     // Hz
#define Fcy (Fosc/2)     // Hz
#define Fs    103160       // Hz
#define SAMPPRD  (Fcy/Fs)-1   // Hz
#define NUMSAMP  256

// Functions
void initAdc(void);
void initDac(void);
void initTmr3(void);
void initDma0(void);

// Peripheral ISRs
void __attribute__((interrupt, no_auto_psv)) _DMA0Interrupt(void);
void __attribute__((interrupt, no_auto_psv)) _DAC1RInterrupt(void);
#endif








Title: Re: Multi Effects Pedal
Post by: cloudscapes on January 04, 2014, 10:30:04 AM
You should buffer the guitar signal before it reaches the pic, which probably can't handle the impedance very well. Just an opamp buffer with gain pot is probably enough.

Another trick I use often is just to make a clipping led. If the adc sample value is greater than a bit under the max value (so if 10bit adc, 0-1023, if it's greater than 1000) light a led. otherwise, dark. it'll help you trim your gain well and ensure you have a proper signal before you start debugging the code. only takes a few minutes to set up if you know the code to set a pin high or low.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 04, 2014, 01:05:07 PM
So create  an op amp outside of the PIC to feed the signal to before reaching the PIC? is this to amplify the signal before reaching the PIC?.

Here is an audio preview of what It sounds like: It's quite loud so be warned. Also mind the bad playing and recording.

https://www.dropbox.com/s/w52cs7s31raoz3m/Not%20so%20Clean.mp3
Any advice is appreciated :)
Title: Re: Multi Effects Pedal
Post by: cloudscapes on January 04, 2014, 02:59:12 PM
Quote from: MstrKurt on January 04, 2014, 01:05:07 PM
So create  an op amp outside of the PIC to feed the signal to before reaching the PIC? is this to amplify the signal before reaching the PIC?.

if it's straight from the guitar, yeah. just simple opamp buffer with gain pot.

the pic's ADCs are 12bit and with a default voltage reference extect voltages between 0 and 3.3v to be able to give you that full 12bit range. if it's just straight from the guitar, the ADCs are getting only a fraction of the voltage, so maybe only 2 or 3 usable bits and it'll sound pretty sputtery/crunchy. not saying that's the problem you had, but it certainly wouldn't help if it's guitar straight to pic.

careful not to overload the pic's ADC, voltage-wise. it can probably handle a bit more than 3.3v for a second, but I wouldn't push it. just make sure your buffer/gain doesn't go over that, regardless how you do it.

it might seem like a lot of work to get started  ;D but you do it once or twice and it gets easier afterwards.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 04, 2014, 07:51:57 PM
Quote from: cloudscapes on January 04, 2014, 02:59:12 PM
Quote from: MstrKurt on January 04, 2014, 01:05:07 PM
So create  an op amp outside of the PIC to feed the signal to before reaching the PIC? is this to amplify the signal before reaching the PIC?.

if it's straight from the guitar, yeah. just simple opamp buffer with gain pot.

the pic's ADCs are 12bit and with a default voltage reference extect voltages between 0 and 3.3v to be able to give you that full 12bit range. if it's just straight from the guitar, the ADCs are getting only a fraction of the voltage, so maybe only 2 or 3 usable bits and it'll sound pretty sputtery/crunchy. not saying that's the problem you had, but it certainly wouldn't help if it's guitar straight to pic.

careful not to overload the pic's ADC, voltage-wise. it can probably handle a bit more than 3.3v for a second, but I wouldn't push it. just make sure your buffer/gain doesn't go over that, regardless how you do it.

it might seem like a lot of work to get started  ;D but you do it once or twice and it gets easier afterwards.

Fantastic information.

Thank you very much for that. I will make a standard buffer for the input and diff amp for the output when I get access to the lab on Tuesday.
Did you check out the sound I recorded to give an indication of what I'm getting?. Does it sound like the problem we've been discussing?.
Title: Re: Re: Multi Effects Pedal
Post by: slacker on January 05, 2014, 01:45:09 PM
To add to what Etienne said, part of your problem is that the guitar signal swings above and below ground and the PIC can only read positive voltages, those above ground, so your current set up is only sampling half the waveform. That's where some of the distortion in your sound clip is coming from. To solve this you need to bias the input to half the PIC's supply voltage using something like shown below. So long as the total swing of the signal is less than the supply voltage you'll now sample the full wave form.

(http://img.tapatalk.com/d/14/01/06/7ajynapa.jpg)

How are you powering the PIC? If you're powering it from the USB port via the programmer then you'll get a lot of noise in the signal, you need to power it from a separate voltage regulator. In my experience just having the programmer connected even if the PIC has it's own power adds a lot of noise, I disconnect the programmer once I've finished programming.
Title: Re: Multi Effects Pedal
Post by: slacker on January 05, 2014, 02:00:19 PM
Quote from: cloudscapes on January 04, 2014, 10:30:04 AM
Another trick I use often is just to make a clipping led. If the adc sample value is greater than a bit under the max value (so if 10bit adc, 0-1023, if it's greater than 1000) light a led. otherwise, dark.

Nice idea I'll have to try that.
Title: Re: Re: Multi Effects Pedal
Post by: MstrKurt on January 05, 2014, 02:39:55 PM
Quote from: slacker on January 05, 2014, 01:45:09 PM
To add to what Etienne said, part of your problem is that the guitar signal swings above and below ground and the PIC can only read positive voltages, those above ground, so your current set up is only sampling half the waveform. That's where some of the distortion in your sound clip is coming from. To solve this you need to bias the input to half the PIC's supply voltage using something like shown below. So long as the total swing of the signal is less than the supply voltage you'll now sample the full wave form.

(http://img.tapatalk.com/d/14/01/06/7ajynapa.jpg)

How are you powering the PIC? If you're powering it from the USB port via the programmer then you'll get a lot of noise in the signal, you need to power it from a separate voltage regulator. In my experience just having the programmer connected even if the PIC has it's own power adds a lot of noise, I disconnect the programmer once I've finished programming.

Thanks for your input, Slacker.

I'm powering it via a PICkit 3, however while I'm in the lab I power it directly from a DC power supply known as a Black Box with 3.3V.
Would powering the circuit from a 3V battery still require a regulator or should it be ok?.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 06, 2014, 03:27:19 AM
Just a follow up question regarding the op amps:

I'm aware of how to design an op amp to a specific gain but only when I know the input voltage. Do guitars have a maximum output voltage(before hitting an amp), if so does it differ for each guitar?.

EDIT: Sorry, I re-read that a gain pot is needed. Apologies for not reading back beforehand.
Title: Re: Re: Multi Effects Pedal
Post by: slacker on January 06, 2014, 01:15:31 PM
Quote from: MstrKurt on January 05, 2014, 02:39:55 PM
Would powering the circuit from a 3V battery still require a regulator or should it be ok?.

Yeah you could probably use a 3 Volt battery without a regulator. You'll probably need a higher Voltage to power the opamps though, unless you find some that work at 3 Volts. The "standard" for guitar pedals is 9 Volts so I would use that to power the opamps and a 3.3 Volt regulator to power the PIC.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 07, 2014, 02:15:59 AM
The only Op Amp I could find at the lab is a 5V powered one, so I've got 2 separate supplies (3.3 and 5)
The weird thing is if I power the chip by a battery rather than my programmer I don't hear anything, and while my programmer is connected,
I still get the same original sound while the op amp is there.

Here is the Schematic:

(http://i.imgur.com/IF0MYFj.png)
Title: Re: Multi Effects Pedal
Post by: Digital Larry on January 07, 2014, 09:56:10 AM
The input impedance of your circuit is about 50k ohms which is going to load a typical passive guitar pickup quite a bit.  I recommend a non inverting stage with a fixed gain of between 1 and 2 and the volume pot after it.  This will have a much higher input impedance.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 07, 2014, 12:47:16 PM
Hey Digital Larry,
thanks for the input, I will look in to this when I'm back in the lab tomorrow :).

I managed to get a cleanish signal through the PIC today but with what sounded like slight distortion. Will see if the problem persists when I clean up the breadboard (shorten wires etc).

I also noticed the DAC has a + and - Would I need to merge the two channels so the full wave arrives at the output?.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 08, 2014, 10:12:25 AM
I'm still getting a rather distorted signal from the DAC after adding an op amp, and biasing.

The 2 DAC outputs +/- are confusing. The + pin has the positive half cycle, but no negative half and clips at around -100mv and vice verse for the -

Perhaps the DAC isn't sampling at it's maximum rate?.

EDIT: Digital Larry, what did you mean by a non inverting stage? Isn't the op amp I'm using already in Non Inverting mode?

EDIT 2: Here's an updated Circuit Diagram
(http://i.imgur.com/G3vIL4Y.png)

ALSO: I think I'm getting attenuation after the differential amplifier somehow, shouldn't the gain be 1 since all resistor values are identical = no change to the signal in terms of amplitude?
Title: Re: Multi Effects Pedal
Post by: Digital Larry on January 10, 2014, 04:07:36 PM
Ah, yes you're correct, you ARE already using a non inverting stage.  Sorry, sometimes I look at these things really quickly and pop off with some half baked response.  So in that case I'd suggest 2.2M resistors in place of the 100ks to give you the Vcc/2 bias voltage, as 2 of these in parallel would be just over 1 Meg which is usually OK for pickup loading.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 11, 2014, 05:01:00 AM
Ok, thanks for the input Digital Larry.

While browsing over this circuit, I may have stumbled on to why I'm only getting a positive half cycle of the wave out of the DAC. I've put a Capacitor before the ADC (Labelled on the circuit as C6). Wouldn't this remove the DC biasing done beforehand?.

Also can anyone explain to my why the DAC has 2 outputs a + and a -?. I'm not able to find a good explanation of why this is there.
Title: Re: Multi Effects Pedal
Post by: Digital Larry on January 11, 2014, 09:33:43 AM
You're correct that the cap removes the DC bias and since the PIC only has a single supply, it will (probably) clip any signal going below zero.

I only say "probably" because I didn't read all 88 pages of the ADC application note, and I've never used the PIC, but it seems a reasonable place to start (biasing the input).  

http://ww1.microchip.com/downloads/en/DeviceDoc/70183D.pdf

Regarding the DAC differential output, check figure 33-5 in this document:  http://ww1.microchip.com/downloads/en/DeviceDoc/70211B.pdf (http://ww1.microchip.com/downloads/en/DeviceDoc/70211B.pdf)

Normally that would be done to reduce common mode noise getting into the buffered DAC output (post op-amp).


Title: Re: Multi Effects Pedal
Post by: slacker on January 11, 2014, 09:38:33 AM
Yes the cap C6 removes the DC biasing, you can't just remove it though. Your opamp is running on 5 Volts with the signal biased to the mid point by R3 and R4, so the signal is biased around 2.5 Volts. The PIC needs the signal to be biased around half its supply which is 3.3/2 = 1.65 Volts, if you add the thing I drew earlier between the output of the opamp and the analogue input on the PIC it will bias the signal correctly.

EDIT: posted the same time as DL.

Your output stage is wrong as well, the bottom of R10 should go to half the PIC's supply Voltage not ground. See the appnote Larry posted.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 12, 2014, 01:04:46 PM
Thanks once again to both of you for your input, I will look to see if I can finally get a clean signal through on Tuesday when I get access to the lab.

Does anyone know if those pocket oscilloscopes are good enough to monitor wave forms for these type of projects?

And would anyone know for a relatively cheap variable DC PSU with a built in function generator?.

Thanks!.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 14, 2014, 12:58:40 PM
Clean signal achieved :)

I biased the input correctly and removed the Diff Amp for the time being and it sounds great so far. I also managed to get distortion working by using a clipping point which doesn't sound all that bad!.

I'm working on getting delay working now by using the delay line Pottul provided but I'm struggling.
Title: Re: Multi Effects Pedal
Post by: slacker on January 14, 2014, 01:11:40 PM
Excellent glad to see you're making progress.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 15, 2014, 12:12:09 PM
Would anyone know how I can make a simple delay line that gives the longest amount of delay possible for a dsPIC33FJ128GP802's internal RAM
Title: Re: Multi Effects Pedal
Post by: slacker on January 16, 2014, 01:39:25 PM
Try this, there's probably better ways to do it but this works. I've tried this on a dspic33FJ64GP202 which is similar to what you're using and this is the longest delay I can make using this method, you've got twice as much RAM so you might be able to increase the length. How much delay this gives you depends on your sample rate, I'm running at 32KHz so it gives me about 90ms. This is a  circular buffer (https://en.wikipedia.org/wiki/Circular_buffer) with a counter that steps through the stages writing a new sample in and reading one out, hopefully the code is pretty self explanatory.

Stick all this in your ISR or whatever you're using to run the ADC or DAC. You may need to make a few changes to make it fit what you're doing.


#define length 3000 //length of delay in samples
static unsigned int writeaddress = 0; //address to write sample to
static unsigned int readaddress; //address to read sample from
static signed int delayline[length]; //set up an array of signed ints of "length" number of samples

writeaddress++;
if(writeaddress == length)
writeaddress = 0;

readaddress = writeaddress + 1;
if(readaddress == length)
readaddress = 0;

delayline[writeaddress] = sample_in; //sample could be the output from the ADC
sample_out = delayline[readaddress]; //sampleout could go to the DAC
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 17, 2014, 07:11:39 AM
Thank you very much, Slacker!.

Based on initial code, I think it's working however it's difficult to hear the short delay. I have tried increasing the length from 3000 to 6000 but I get this error:

build/default/production/Main.o: Link Error: Could not allocate section .nbss, size = 12008 bytes, attributes = bss near
Link Error: Could not allocate data memory

But isn't that saying 12008 bytes are required, when I have 16384 bytes of RAM?.

EDIT: Nevermind, I fixed it by changing the memory model to "Large data".
Title: Re: Re: Re: Multi Effects Pedal
Post by: slacker on January 17, 2014, 07:37:07 PM
Quote from: MstrKurt on January 17, 2014, 07:11:39 AM
EDIT: Nevermind, I fixed it by changing the memory model to "Large data".

Interesting, how do you do that?
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 18, 2014, 03:18:21 PM
Sorry I'm late replying,

Right click the project name>properties>C30 (Global Options)>pic30-gcc>set option categories to Memory Model>Change Data model to Large data model.
Title: Re: Multi Effects Pedal
Post by: slacker on January 19, 2014, 01:25:44 PM
Thanks for that, how much extra memory did it allow you to use?
Title: Re: Multi Effects Pedal
Post by: MstrKurt on January 19, 2014, 03:39:12 PM
All 16k of my chips RAM.
Title: Re: Multi Effects Pedal
Post by: ElectricDruid on January 20, 2014, 04:08:08 PM
You should check out Seb Francis 4xD stuff if you're doing FX on a dsPIC. It's great work. A bit more sophisticated, but it shows what can be done with these chips. He used an external codec like you discussed initially.

http://burnit.co.uk/sdiy/index.php?page=4xd (http://burnit.co.uk/sdiy/index.php?page=4xd)

I've used the dsPIC '802 a lot myself, but pretty much always in assembler. There's some nice DSP features (DMA, hardware circular buffers) available which really save a lot of processor time, but I'm afraid I'd have no idea how you'd implement them from C.

Good luck anyway, it looks like a cool project.

Tom
Title: Re: Multi Effects Pedal
Post by: MstrKurt on February 02, 2014, 02:25:21 PM
Hi again guys, I've recently bought a 23LC1024 1Mbit RAM chip that interfaces with the dsPIC through SPI.

Have any of you any experience on getting these things to work together?.
Title: Re:
Post by: slacker on February 02, 2014, 03:11:18 PM
I'm playing with the same thing at the minute and the smaller 23k256.
Pretty easy to get working, the datasheet gives good explanations of what to do.
Let me know if you need any pointers, happy to share my code if needed.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on February 04, 2014, 04:40:21 PM
Thanks Slacker, I will give it a try according to the datasheets soon and see if I hit a wall.

I was told today that the sample time that is able to be achieved by 16k of RAM can be increased by lowering the resolution of my ADC or lowering the sample rate?. Is there any truth to this?.
Title: Re: Multi Effects Pedal
Post by: ElectricDruid on February 04, 2014, 04:57:07 PM
Quote from: MstrKurt on February 04, 2014, 04:40:21 PM
Thanks Slacker, I will give it a try according to the datasheets soon and see if I hit a wall.

I was told today that the sample time that is able to be achieved by 16k of RAM can be increased by lowering the resolution of my ADC or lowering the sample rate?. Is there any truth to this?.

Yes. At least in theory.

For a given amount of memory (like 16K) if you reduce the ADC resolution, then the input samples you're storing take up less bits, and you'll get more samples in, which will give you longer delays. In practice, reducing the samples to (say) 11-bits with a 16-bit RAM would cause enough difficulties that I seriously doubt it would be worth the extra effort. 12-bit is a borderline case, since at least you'd be handling whole nibbles, but it's still not easy and is going to eat up processor cycles that would be better used for something else.

Alternatively, if you reduce the sampling rate, then a delay of X samples gets longer by the same amount. If you're sampling at (say) 44KHz and you've got 1 second total delay, then reducing the sample rate to 22KHz will give you 2 seconds delay. You can trade off bandwidth against delay time. This has no other consequences like changing the ADC resolution. Usually it's far more straightforward to do and would involve changing the setup of whatever sets the sample rate - a timer or perhaps the master clock rate.

HTH,
Tom
Title: Re: Multi Effects Pedal
Post by: MstrKurt on February 04, 2014, 08:49:36 PM
Thanks for that information, Tom.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on March 01, 2014, 10:16:42 PM
Hey guys, I've had slow progress over the last month from dealing with some personal trauma's.

I've just got back in to the swing of things and realised that the distortion has seem to stop working :S.

The circuit is unchanged and the only additions I've made is switchable effects. The code for distortion I have is:



  if (Input>threshold)
  {
Input = ADC1BUF0;     
Input = threshold;  //  Clip the input
     
  }

    Output = Input;     // Sets output = clipped input


  DAC1RDAT = Output;       // Send output to the DAC


Threshold is some nominal value that in this example is 2000, but will be set by a potentiometer eventually.
Where
Title: Re: Multi Effects Pedal
Post by: slacker on March 03, 2014, 04:45:56 PM
Hope the personal trauma's were nothing serious.

I think your code is wrong or there's some bits missing. It looks to me like the "input = ADC1BUF0;" should be before the if statement not inside it, that would set input = ADC1BUF0 then if it's above threshold it sets input to threshold instead, that would clip the positive side of the input.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on March 03, 2014, 08:56:30 PM
Thanks for the help Slacker, I think that's worked however, I've found a problem that's further going to hinder my progress.. 2 of the pickups screw holes on my guitar have snapped from being squashed in the travel bag. Is there any way I can buy new pickups for relatively cheap? or is it better to take it to a guitar shop.

Thanks!.


EDIT:
https://www.dropbox.com/s/va7n1xtz9bn6fzx/Guitar%20Pickups.jpg - Here is an image to show what I mean. Notice that 2 of the pickups plastic holes have snapped off.

EDIT 2:
Would anyone know how I can generate a clean guitar signal from my PC maybe route it through the Line Out port to the input of my pedal to see the effects without a guitar?.
Title: Re: Multi Effects Pedal
Post by: slacker on March 04, 2014, 01:31:24 PM
Ouch. If it was mine I'd take one of the screws down to the local hardware store and see if I could find some nuts that would fit, fit the pickup then screw the nut on to hold it at the correct height, maybe use two nuts to lock it in place. If you can't find nuts to fit the existing screws you'll probably find a suitable replacement screw or bolt.
Title: Re: Multi Effects Pedal
Post by: Ice-9 on March 04, 2014, 04:44:20 PM
Re- pickups, I would get some screws and nuts, not the self tapper screws that are in but something like a 2mm thread (or what is the best size to match diameter). I would then put it together and glue the nut with some epoxy glue to the underside of the pickup, that way the pick up height would still be adjustable.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on March 05, 2014, 01:31:29 PM
Thanks for the help, both. I will look to purchase some nuts tomorrow :)
Title: Re: Multi Effects Pedal
Post by: MstrKurt on March 14, 2014, 01:16:55 AM
Hey again guys,

Would anyone know how I'd implement a Phaser effect?.

Am I right to assume that I get the ADC value, and store that in a fractional variable. Then take that variable through a chain of all pass filters and save the output of them to another variable and then multiply the original signal with the APF'd variable?.
Title: Re: Multi Effects Pedal
Post by: slacker on March 14, 2014, 05:31:19 PM
Yeah that's pretty much it, that will give you fixed phase shifted effect. To get the sweeping phaser effect you need to modulate the allpass filters so that the phase shift moves about.

I don't think you need to use fractional numbers you can just use signed integers.

There's a pretty good explanation of how to do phasing and other effect here http://www.spinsemi.com/knowledge_base/effects.html#Phase_shifting (http://www.spinsemi.com/knowledge_base/effects.html#Phase_shifting)
Title: Re: Multi Effects Pedal
Post by: Digital Larry on March 14, 2014, 05:36:35 PM
Though you don't multiply the direct signal with the phase shifted one - just add them together.  Invert one or the other and you'll get a different sound.  Add some feedback and yet more colors will emerge.
Title: Re: Multi Effects Pedal
Post by: slacker on March 14, 2014, 05:47:27 PM
Oh yeah I missed that, might be interesting if you did multiply them, some sort of weird ringmoddy octavy mess of a thing.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on March 16, 2014, 10:22:42 AM
Thanks a lot for the info guys. I may actually try multiplying them and see what comes of it!
Title: Re: Multi Effects Pedal
Post by: MstrKurt on March 16, 2014, 12:09:15 PM
Since trying Distortion out on a new guitar, the distortion seems to decay very quickly.

I've used an Overdrive type of path where I multiply the input by some random value which pushes the wave to the clipping points of the dsPIC. Any idea why it gives a harsh decaying sound?.
Title: Re: Multi Effects Pedal
Post by: Digital Larry on March 16, 2014, 12:42:06 PM
If all you are doing to get harmonics is to slam the signal to the clipping point, you can expect a harsh result.  The gain is constant up to that point and then it immediately becomes zero.  This puts a real sharp edge on the signal, making high order harmonics come out.

Soft clipping like you naturally get from vacuum tubes or well designed distortion pedals has a more gradual transition.  In order to implement this in your DSPic, you'd need to implement some math function (I've read that hyperbolic tangent (tanh) is good for this).  Or you could try piecewise linear, like:

Input = 0 to 0.5, gain = 1.5
Input = 0.5 to 0.75, gain = 1.2 (then you have to add 0.15, so that you don't get a jump at the point where the gain changes)

I.e. since 0.5 x 1.2 = 0.6, to get the level to 0.75 (0.5 x 1.5 in the first gain range) you need to add 0.15 to the level in the second gain range.

etc.

These are just ideas... many ways to do it.  If you try to do math functions in real time you may be limited by the speed of your microcontroller and the efficiency of the supplied math library.  Piecewise linear should be less load on the CPU but may not give you the sound you want.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on March 16, 2014, 02:07:01 PM
Ok that sounds a good plan DL.

One thing I don't understand however is the adding the 0.15 part.

Does this mean that if the input is 0 to 0.5 the gain is 1.5, if the gain is 0.5 to 0.75 the gain is 1.2 but with the added 0.15 it's 1.35?

EDIT:


    if ((Input > 0)&&(Input<0.5))
    {
        Input = Input*2;
    }
    else if((Input>=0.5)&&(Input<1))
    {
        Input = Input*1.5;
    }
    else if((Input>=1)&&(Input<1.5))
    {
        Input = Input*1.2;
    }
   else if((Input>=1.5)&&(Input<1.8))
   {
     Input = Input*1.1;
   }
   else if((Input>=1.8)&&(Input<1.98))
   {
       Input = Input * 1;
   }

Is this correct?
Title: Re: Multi Effects Pedal
Post by: Digital Larry on March 17, 2014, 09:42:46 AM
What you want to do is make sure that at the transition point, the calculation is the same for that point using the equation on either side.  Clearly you are only going to calculate that point using one of the equations.  This is like slope - intercept y = mx + b stuff from algebra.  The idea is to make sure that as you go through the gain transition point there's not a jump in the waveform.  Even this is not truly soft clipping as it still creates sharp corners (but not 90 degree type) on the waveform at the gain transition points.  Soft clipping approach changes gain continuously as input amplitude increases.  Nevertheless, it should be less harsh than simply clipping abruptly at some signal level, and you can fairly quickly try out different approaches to see if any of them are acceptable.  I've never actually done what I am describing!

E.g.

0 to <= 0.5:

Output = input * 1.5

at 0.5, output = 0.75.

For the next vertical slice, reduce the gain to 1.2.  But to get the result to be 0.75 at 0.5, you need to ADD 0.15 in this section.

> 0.5 to <= 0.8

Output = input * 1.2 + 0.15 (if input is negative, subtract 0.15 instead)

If your next gain transition is at 0.9:

0.9 * 1.2 + 0.15 = 1.23

If the gain reduced to 1.1, then

0.9 * 1.1 + x = 1.23 ... so x = 0.24

Hope this makes sense!

Title: Re: Multi Effects Pedal
Post by: MstrKurt on March 19, 2014, 12:15:36 AM
Still not catching on I don't think.


    if ((Input > 0)&&(Input<0.5))
    {
        Input = Input*1.5;
    }
    else if((Input>=0.5)&&(Input<0.8))
    {
        Input = ((Input*1.2)+0.15);
    }
    else if((Input>=0.8)&&(Input<0.9))
    {
        Input = ((Input*1.2)+0.15);
    }
   else if((Input>=1)&&(Input<1.2))
   {
     Input = ((Input*1.2)+0.15);
   }
   else if((Input>=1.2)&&(Input<1.3))
   {
     Input = ((Input*1.2)+0.15);
   }
   else if((Input>=1.3)&&(Input<2))
   {
     Input = ((Input*1.2)+0.15);
   }

Is that what you mean?.

Using that code, I'm getting a constant whining tone out of the amplifier when nothing is being input, however the distortion transition is a lot smoother.

---------------------------------
DELAY: This is not my code, but is available on DSP Related's website.

Code in main:

    Input = dc_removal(Input);
    Delay_set_fb(0.8);                                                 
    Delay_set_delay(8000);

    Output=Delay_task(Input);
    DAC1RDAT = Output;


Code called Delay:


#include "p33fxxxx.h"
#include "dsp.h"
#include "libq.h"

#define smul(a,b) ( (long)(a)*(b) )
#define sround( x )  (short)( ( (x) + (1<<14) ) >>15 )

#define S_MUL(a,b) sround( smul(a,b) )


/****************DELAY.C*******************************/
#include "delay.h"
#include "math.h"

#define MAX_BUF_SIZE 8000  //8000

/*****************************************************************************
*       Fractional delay line implementation in C:
*
*                    ---------[d_mix]--------------------------
*                    |                                         |
*                    |                                         |
*                    |x1                                       v
*     input ------>[+]----->[z^-M]--[interp.]----[d_fw]-------->[+]-----> output
*                 ^                         |
*                 |                         |
*                 |----------[d_fb]<--------|
*******************************************************************************/

fractional d_buffer[MAX_BUF_SIZE] __attribute__((far));
fractional prev_x;
fractional prev_y;

#define DC_REMOVAL_POLE Q15(0.999)

/*
This interface defines the delay object
*/
static struct fract_delay {
    fractional d_mix;       /*delay blend parameter*/
    int d_samples;    /*delay duration in samples*/
    fractional d_fb;            /*feedback volume*/
    fractional d_fw;            /*delay tap mix volume*/
    int n_fract;     /*fractional part of the delay*/
    fractional *rdPtr;      /*delay read pointer*/
    fractional *wrtPtr;     /*delay write pointer*/
char reverse_buffer;
};

static struct fract_delay del;

/*
This function is used to initialize the delay object
*/
void Delay_Init(short delay_samples,fractional dfb,fractional dfw, fractional dmix) {
        Delay_set_delay(delay_samples);
        Delay_set_fb(dfb);
        Delay_set_fw(dfw);
        Delay_set_mix(dmix);
        del.wrtPtr = &d_buffer[MAX_BUF_SIZE-1];
        del.rdPtr = del.wrtPtr - (short)del.d_samples;
        /*Wraps read pointer*/
        if (del.rdPtr < d_buffer) {
                del.rdPtr += MAX_BUF_SIZE-1;
        }
del.reverse_buffer=0;
}

/*
These functions are used as interface to the delay object,
so there's not direct access to the delay object from
external modules
*/
void Delay_set_fb(fractional val) {
    del.d_fb = val;

}

void Delay_set_fw(fractional val) {
    del.d_fw = val;
}

void Delay_set_mix(fractional val) {
    del.d_mix = val;
}

void Delay_set_delay(short n_delay) {
    //short dif;
    if (n_delay==0) n_delay=1;
    /*Get the integer part of the delay*/
    del.d_samples = n_delay;

    /*gets the fractional part of the delay*/
    //dif = (n_delay - del.d_samples);
//del.n_fract= dif;
}

fractional Delay_get_fb(void) {
    return del.d_fb;
}

fractional Delay_get_fw(void) {
    return del.d_fw;
}

fractional Delay_get_mix(void) {
    return del.d_mix;
}

void Delay_put_fifo_value(fractional val){

// writes value in fifo
*(del.wrtPtr) = val;

    /*Increment delay write pointer*/
        del.wrtPtr++;

    /*Wraps delay write pointer*/
        if ((del.wrtPtr-&d_buffer[0]) > MAX_BUF_SIZE-1) {
                del.wrtPtr = &d_buffer[0];
        }
}

fractional Delay_get_fifo_value(void) {

        fractional x_est;

//get buffer next value
        x_est = *(del.rdPtr);

    /*Increment delay read pointer*/
        del.rdPtr++;

    /*Wraps delay read pointer*/
        if ((del.rdPtr-&d_buffer[0]) > MAX_BUF_SIZE-1) {
                del.rdPtr = &d_buffer[0];
        }
return x_est;
}

fractional Delay_get_fifo_ping_pong(void) {

        fractional x_est;
fractional x_est2;
int offset;

// if (del.rdPtr < del.wrtPtr) {
offset = (abs(del.wrtPtr - del.rdPtr));
if (offset > MAX_BUF_SIZE/2){
offset = MAX_BUF_SIZE - offset;
}
// }
// else {
// offset = del.rdPtr - del.wrtPtr;
// }

if (del.rdPtr==del.wrtPtr) {
del.reverse_buffer =1;
}
if (del.rdPtr==del.wrtPtr+1) {
del.reverse_buffer =0;
}
// pending to add check for when wrtPtr is just the last buffer byte
//get buffer next value
        x_est = *(del.rdPtr);


//find the point at a max distance
if (del.rdPtr < &d_buffer[0]+(MAX_BUF_SIZE/2)){
x_est2= *(del.rdPtr+MAX_BUF_SIZE/2);
}
else{
x_est2= *(del.rdPtr-MAX_BUF_SIZE/2);
}

    /*Increment delay read pointer*/
        if (del.reverse_buffer) del.rdPtr--;
else del.rdPtr++;

    /*Wraps delay read pointer*/
        if ((del.rdPtr-&d_buffer[0]) > MAX_BUF_SIZE-1) {
            del.rdPtr = &d_buffer[0];
        }
        /*Wraps read pointer*/
        if (del.rdPtr < d_buffer) {
                del.rdPtr += MAX_BUF_SIZE-1;
        }
offset = ((long)offset * 0x8000) / (MAX_BUF_SIZE/2);
// x_est = S_MUL(x_est , offset) ;
// x_est += S_MUL(x_est2, 0x8000-offset);

return x_est;
}

/*
This is the main delay task,
*/
fractional Delay_task(fractional xin) {
        fractional yout;
        fractional * y0;
        fractional * y1;
        fractional x1;
        fractional x_est;

    /*Calculates current read pointer position*/
        if (del.wrtPtr > d_buffer+ (short)del.d_samples)
del.rdPtr = del.wrtPtr - (short)del.d_samples;
        else
del.rdPtr = del.wrtPtr + MAX_BUF_SIZE - (short)del.d_samples;


        /*Wraps read pointer*/
//        if (del.rdPtr < d_buffer) {
//                del.rdPtr += MAX_BUF_SIZE-1;
//        }

        /*Linear interpolation to estimate the delay + the fractional part*/
        //y0 = del.rdPtr-1;
        y1 = del.rdPtr;

        //if (y0 < d_buffer) {
        //    y0 += MAX_BUF_SIZE-1;
        //}

        //x_est = (*(y0) - *(y1))*del.n_fract + *(y1);  // to be validated
x_est= *(y1);

    /*Calculate next value to store in buffer*/
    x1 = xin + S_MUL(x_est,del.d_fb);  //should it be S_MUL?
    //x1= xin;
        /*Store value in buffer*/
        *(del.wrtPtr) = x1;

    /*Output value calculation*/
    //    yout = S_MUL(x1,del.d_mix) + S_MUL(x_est,del.d_fw);  // should it be S_MUL?
yout = S_MUL(x1,del.d_mix) + S_MUL(x_est,del.d_fw);  // should it be S_MUL?

    /*Increment delay write pointer*/
        del.wrtPtr++;

    /*Wraps delay write pointer*/
        if ((del.wrtPtr-&d_buffer[0]) > MAX_BUF_SIZE-1) {
                del.wrtPtr = &d_buffer[0];
        }
        return yout;
}
/***********DELAY.h*************************************/
#ifndef __DELAY_H__
#define __DELAY_H__

void Delay_Init(short delay_samples,fractional dfb,fractional dfw, fractional dmix);
void Delay_set_fb(fractional val);
void Delay_set_fw(fractional val);
void Delay_set_mix(fractional val);
void Delay_set_delay(short n_delay);
fractional Delay_get_fb(void);
fractional Delay_get_fw(void);
fractional Delay_get_mix(void);
fractional Delay_get_fifo_value(void);
fractional Delay_get_fifo_ping_pong(void);
void Delay_put_fifo_value(fractional val);
fractional Delay_task(fractional xin);

#endif


fractional ga= Q15(0.95);  //0.95
fractional gr= Q15(0.9998);  //0.999

fractional calc_envelope(fractional input, fractional envelope){
input = _Q15abs(input);
if (envelope<input){
envelope= S_MUL(envelope, ga);
envelope+= S_MUL((Q15(1)-ga),input);
}
else {
envelope= S_MUL(envelope, gr);
envelope+= S_MUL((Q15(1)-gr),input);
}
return envelope;
}

fractional dc_removal(fractional input)
{
// y[n] =  x[n] - x[n-1] + p*y[n-1]       (where p = pole, 0 < 1-p << 1)
prev_y= S_MUL(prev_y , DC_REMOVAL_POLE);
prev_y= prev_y + input - prev_x;
prev_x= input;


return prev_y;
}



/*****USAGE EXAMPLE****************************************/

void test_func(void) {
    fractional xin;
    fractional yout;
Delay_Init(50,Q15(0.7),Q15(0.7),Q15(1));
fractional i=Q15(-0.8);
    while(1) {

            /*When there's new sample at your ADC or CODEC input*/
            /*Read the sample*/
xin =  i;
i = i >> 1;
            /*Apply the Delay_task function to the sample*/
            yout = Delay_task(xin);

            /*Send the output value to your ADC or codec output*/
//          tracevalue = yout; //write_output(yout);
// tracevalue2 = xin;
// traceout();

    }
}



I'm not 100% I'm getting a delayed result. If I increase the Delay_set_fb(0.8); to a higher value I can hear some form of very short reverb type effect, but nothing to prove delay is evident.  (Unfortunately I know very little about this code, and even less of how it works, I don't quite understand the Q15 stuff, S_MUL etc).




Title: Re: Multi Effects Pedal
Post by: Digital Larry on March 19, 2014, 09:32:53 AM
What is the actual range of the input signal that the DAC sees?  Is it about 0 when there's no input or is it offset?  Does it go + and - or only +?

I'll take a closer look at the code some time!
Title: Re: Multi Effects Pedal
Post by: MstrKurt on March 19, 2014, 12:19:33 PM
The average swing of the input from the pickups of the guitar is around 100-200mV (that's going in to the ADC) with a bias voltage of 1.6V. So it has a maximum level of -1.6V on the negative half cycle?
Title: Re: Multi Effects Pedal
Post by: Digital Larry on March 19, 2014, 04:48:03 PM
So the ADC code for "0" input is actually your bias point, correct?  You'll have to adjust everything for that then.
Title: Re: Multi Effects Pedal
Post by: MstrKurt on April 02, 2014, 04:44:06 PM
Ok managed to get Distortion working to a standard that I'll settle for.

Is there a program that must be used to generate C code for DSP filters?.