sigma delta experiments

creating sound with microcontrollers

sigma delta experiments

Postby chris on Sun Apr 14, 2013 8:22 am

With microcontrollers It is common to create analog voltages with PWM-signals.

Here I try to generate analog voltages with the sigmal delta principle.
To keep it simple, the proof of concept is done with an Arduino Uno.

Code: Select all
/*
  sigma delta modulator experiments
 
  generate an audio chirp signal on Arduino LED output
 
  14.4.2013 ch

*/

void setup() {               
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);   
}

int16_t integrator=0;
uint8_t sollwert=64;
uint8_t oldValue=0;
uint16_t phase=0;
uint16_t phaseDelta=200*40;
uint8_t n;

#define MAXVALUE 255

int8_t sintab[256]={
0 ,3 ,6 ,9 ,12 ,15 ,18 ,21 ,24 ,27 ,30 ,33 ,36 ,39 ,42 ,45 ,48 ,51 ,54 ,57 ,59 ,62 ,65 ,67 ,70 ,73 ,75 ,78 ,80 ,82 ,85 ,87 ,
89 ,91 ,94 ,96 ,98 ,100 ,102 ,103 ,105 ,107 ,108 ,110 ,112 ,113 ,114 ,116 ,117 ,118 ,119 ,120 ,121 ,122 ,123 ,123 ,124 ,125 ,125 ,126 ,126 ,126 ,126 ,126 ,
127 ,126 ,126 ,126 ,126 ,126 ,125 ,125 ,124 ,123 ,123 ,122 ,121 ,120 ,119 ,118 ,117 ,116 ,114 ,113 ,112 ,110 ,108 ,107 ,105 ,103 ,102 ,100 ,98 ,96 ,94 ,91 ,
89 ,87 ,85 ,82 ,80 ,78 ,75 ,73 ,70 ,67 ,65 ,62 ,59 ,57 ,54 ,51 ,48 ,45 ,42 ,39 ,36 ,33 ,30 ,27 ,24 ,21 ,18 ,15 ,12 ,9 ,6 ,3 ,
0 ,-3 ,-6 ,-9 ,-12 ,-15 ,-18 ,-21 ,-24 ,-27 ,-30 ,-33 ,-36 ,-39 ,-42 ,-45 ,-48 ,-51 ,-54 ,-57 ,-59 ,-62 ,-65 ,-67 ,-70 ,-73 ,-75 ,-78 ,-80 ,-82 ,-85 ,-87 ,
-89 ,-91 ,-94 ,-96 ,-98 ,-100 ,-102 ,-103 ,-105 ,-107 ,-108 ,-110 ,-112 ,-113 ,-114 ,-116 ,-117 ,-118 ,-119 ,-120 ,-121 ,-122 ,-123 ,-123 ,-124 ,-125 ,-125 ,-126 ,-126 ,-126 ,-126 ,-126 ,
-127 ,-126 ,-126 ,-126 ,-126 ,-126 ,-125 ,-125 ,-124 ,-123 ,-123 ,-122 ,-121 ,-120 ,-119 ,-118 ,-117 ,-116 ,-114 ,-113 ,-112 ,-110 ,-108 ,-107 ,-105 ,-103 ,-102 ,-100 ,-98 ,-96 ,-94 ,-91 ,
-89 ,-87 ,-85 ,-82 ,-80 ,-78 ,-75 ,-73 ,-70 ,-67 ,-65 ,-62 ,-59 ,-57 ,-54 ,-51 ,-48 ,-45 ,-42 ,-39 ,-36 ,-33 ,-30 ,-27 ,-24 ,-21 ,-18 ,-15 ,-12 ,-9 ,-6 ,-3
};

void loop() {

  // sin wave DDS ( direct digital synthesis )
  sollwert=128+sintab[phase>>8];
  phase+=phaseDelta;
  phaseDelta++;

  // sigma delta DAC, hold the DAC value for n-steps constant
  for(n=0;n<50;n++)
  {
    integrator+=sollwert-oldValue;
    if(integrator>0)
    {
      oldValue=MAXVALUE;
      digitalWrite(13, HIGH);   // set the LED on
    }
    else
    {
      oldValue=0;
      digitalWrite(13, LOW);    // set the LED off
    }
  }
}



To measure the sin wave with the oscilloscope at the LED output a RC low pass filter has been attached ( R=470Ohm, C=100nF )
Attachments
deltaSigmaSinWave.png
deltaSigmaSinWave.png (3.96 KiB) Viewed 7409 times
chris
 
Posts: 289
Joined: Sun May 25, 2008 7:21 am

Re: sigma delta experiments

Postby chris on Mon Apr 15, 2013 6:42 pm

Verbesserte Version. Jetzt Pin2 als Ausgang und 500kHz Abtastfrequenz mit Direktzugriff auf die Ports ohne Benutzung von digitalWrite().
Code: Select all
/*
  sigma delta modulator experiments
 
  generate an audio chirp signal on Arduino LED output
 
  14.4.2013 ch
 
*/

void setup() {               
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(2, OUTPUT);   
  //Serial.begin(9600);   
}



uint8_t n;

#define MAXVALUE 255

int8_t sintab[256]={
0 ,3 ,6 ,9 ,12 ,15 ,18 ,21 ,24 ,27 ,30 ,33 ,36 ,39 ,42 ,45 ,48 ,51 ,54 ,57 ,59 ,62 ,65 ,67 ,70 ,73 ,75 ,78 ,80 ,82 ,85 ,87 ,
89 ,91 ,94 ,96 ,98 ,100 ,102 ,103 ,105 ,107 ,108 ,110 ,112 ,113 ,114 ,116 ,117 ,118 ,119 ,120 ,121 ,122 ,123 ,123 ,124 ,125 ,125 ,126 ,126 ,126 ,126 ,126 ,
127 ,126 ,126 ,126 ,126 ,126 ,125 ,125 ,124 ,123 ,123 ,122 ,121 ,120 ,119 ,118 ,117 ,116 ,114 ,113 ,112 ,110 ,108 ,107 ,105 ,103 ,102 ,100 ,98 ,96 ,94 ,91 ,
89 ,87 ,85 ,82 ,80 ,78 ,75 ,73 ,70 ,67 ,65 ,62 ,59 ,57 ,54 ,51 ,48 ,45 ,42 ,39 ,36 ,33 ,30 ,27 ,24 ,21 ,18 ,15 ,12 ,9 ,6 ,3 ,
0 ,-3 ,-6 ,-9 ,-12 ,-15 ,-18 ,-21 ,-24 ,-27 ,-30 ,-33 ,-36 ,-39 ,-42 ,-45 ,-48 ,-51 ,-54 ,-57 ,-59 ,-62 ,-65 ,-67 ,-70 ,-73 ,-75 ,-78 ,-80 ,-82 ,-85 ,-87 ,
-89 ,-91 ,-94 ,-96 ,-98 ,-100 ,-102 ,-103 ,-105 ,-107 ,-108 ,-110 ,-112 ,-113 ,-114 ,-116 ,-117 ,-118 ,-119 ,-120 ,-121 ,-122 ,-123 ,-123 ,-124 ,-125 ,-125 ,-126 ,-126 ,-126 ,-126 ,-126 ,
-127 ,-126 ,-126 ,-126 ,-126 ,-126 ,-125 ,-125 ,-124 ,-123 ,-123 ,-122 ,-121 ,-120 ,-119 ,-118 ,-117 ,-116 ,-114 ,-113 ,-112 ,-110 ,-108 ,-107 ,-105 ,-103 ,-102 ,-100 ,-98 ,-96 ,-94 ,-91 ,
-89 ,-87 ,-85 ,-82 ,-80 ,-78 ,-75 ,-73 ,-70 ,-67 ,-65 ,-62 ,-59 ,-57 ,-54 ,-51 ,-48 ,-45 ,-42 ,-39 ,-36 ,-33 ,-30 ,-27 ,-24 ,-21 ,-18 ,-15 ,-12 ,-9 ,-6 ,-3
};

void loop() {
  uint16_t phaseDelta=1070;
  int16_t integrator=0;
  uint8_t sollwert=64;
  uint8_t oldValue=0;
  uint16_t phase=0;
  cli();
  while(1)
  {
    // sin wave DDS ( direct digital synthesis )
    sollwert=128+sintab[phase>>8];
    phase+=phaseDelta;
    //phaseDelta++;
 
    // sigma delta DAC, hold the DAC value for n-steps constant
    DDRD|=(1<<2); // set pin as output
    for(n=0;n<25;n++)
    {
      integrator+=sollwert-oldValue;
      if(integrator>0)
      {
        oldValue=MAXVALUE;
        PORTD|=(1<<2); // set pin high
      }
      else
      {
        oldValue=0;
        PORTD&=~(1<<2); // set pin low
      }
    }
    DDRD&=~(1<<2); // set pin into high impedance state
    PORTD&=~(1<<2); // turn off pull up
  }
}

Attachments
sinus440Hz.png
sinus440Hz.png (4.1 KiB) Viewed 7317 times
chris
 
Posts: 289
Joined: Sun May 25, 2008 7:21 am

Re: sigma delta experiments

Postby chris on Thu Apr 18, 2013 4:31 am

Spektrum des Ausgangssignals. Aufgenommen mit Line IN am Laptop.
Das Rauschen lässt durch einen Tiefpass höhere Ordnung verbessern. Man könnte z.B. dem RC-Tiefpass ( 470Ohm, 100nF ) einen zweiten mit 4700Ohm, 10nF nachschalten.
Attachments
sinus8Bit440HzSigmaDelta.png
sinus8Bit440HzSigmaDelta.png (51.44 KiB) Viewed 7187 times
chris
 
Posts: 289
Joined: Sun May 25, 2008 7:21 am

Re: sigma delta experiments

Postby chris on Thu Apr 18, 2013 5:00 am

Simulation of a sigma delat DAC and a RC-Model DAC.
Attachments
sigmaDelatSimualtion.png
sigmaDelatSimualtion.png (42.4 KiB) Viewed 7208 times
chris
 
Posts: 289
Joined: Sun May 25, 2008 7:21 am


Re: sigma delta experiments

Postby chris on Sat May 11, 2013 2:47 pm

- Sigma delta piano for arduino ( runs on arduino uno )
- recorded A-Song
Attachments
sigmaDeltaSinging_ArduinoUno.zip
(9.42 KiB) Downloaded 452 times
sigmaDeltaPiano.zip
(21.36 KiB) Downloaded 506 times
chris
 
Posts: 289
Joined: Sun May 25, 2008 7:21 am

Re: sigma delta experiments

Postby chris on Wed Aug 13, 2014 5:22 pm

Good explanation and code example for PDM ( Pulse Density Modulation ):
http://en.wikipedia.org/wiki/Pulse-density_modulation
chris
 
Posts: 289
Joined: Sun May 25, 2008 7:21 am

Re: sigma delta experiments

Postby chris on Thu Aug 14, 2014 7:45 am

The LPC810

http://vilaca.eu/lpc810/

seems to be very suitable for sound generation. Here is a synthesizer example:
http://www.hackster.io/janost/micro-vir ... ynthesizer

where Janost uses the sigma-delta principle like the Arduino example in this thread:
http://forum.arduino.cc/index.php?PHPSE ... msg1629872

But he uses an interrupt routine to alter the DAC-Value which looks very promissing.

Here I create an arduino compatible library for the LPC810
Last edited by chris on Thu Sep 18, 2014 5:07 pm, edited 2 times in total.
chris
 
Posts: 289
Joined: Sun May 25, 2008 7:21 am

Re: sigma delta experiments

Postby chris on Fri Aug 29, 2014 9:52 am

Here is the class-D amplifier from electrouwe:
http://electro-music.com/forum/viewtopic.php?p=402971
chris
 
Posts: 289
Joined: Sun May 25, 2008 7:21 am


Return to sound

Who is online

Users browsing this forum: No registered users and 1 guest

cron