Delta-Sigma encoder, C code and test result


http://wp.me/ph3BR-21T

 

test result

Delta-sigma encoder output test

 

 

source code

 


#include < stdio.h > //wordpress 自動去除 < > 及內容, 解決辦法, 前後加空格
#include < stdlib.h >
#include < stdint.h >

//ref : https://janostman.wordpress.com/audio-hacking-with-the-esp8266/
//This function generates 32-bit samples by Delta-Sigma coding the bits.
//Pulse Density Modulated 16-bit I2S DAC

// minGW to compile
// gcc -o a.exe a.c -std=c99
// by xiaolaba, test done, 2017-JUL-10

uint32_t i2sACC; //accumulator
uint16_t DAC = 0x1234; //dummy for testing
uint16_t delta ;



void print32bitBIN (uint32_t HEX32) {
printf("output BIN=", HEX32);
for (uint8_t i=0;i<32;i++) {
if (HEX32 & 0x80000000)
printf("1");
else
printf("0");
HEX32 <<= 1;
}
printf("\n");

}

void writeDAC(uint16_t DAC) {

for (uint8_t i=0;i<32;i++) {

printf("%2d, input= 0x%4X, Flip-flop output=",i,DAC);

i2sACC=i2sACC<<1; // bit shifting, assemble PDM code, total 32 bit

if(DAC >= delta) {
i2sACC|=1; // if input > err, LSB, set flip-flop = 1
delta += 0xFFFF-DAC; // err
printf("1");
}
else {
delta -= DAC; // input < err, LSB, set flip-flop = 0
printf("0");
}

printf(" delta= 0x%4X, ", delta);
print32bitBIN (i2sACC);
}

// I2S, data bit stream, MSB first, L-CH 16bit + R-CH 16bit, total 32 bit
//bool flag=i2s_write_sample(i2sACC); // PDM signal done, output I2S module

}



int main(){

printf("xiaolaba, Delta-Sigma encoder test, 2017-JUL-09\r\n");
writeDAC(DAC);
}

REF:
https://janostman.wordpress.com/audio-hacking-with-the-esp8266/

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s