Cov txheej txheem:

Yuav Ua Li Cas thiab Xeem Qhov Zoo DAC Nrog ESP32: 5 Cov Kauj Ruam
Yuav Ua Li Cas thiab Xeem Qhov Zoo DAC Nrog ESP32: 5 Cov Kauj Ruam

Video: Yuav Ua Li Cas thiab Xeem Qhov Zoo DAC Nrog ESP32: 5 Cov Kauj Ruam

Video: Yuav Ua Li Cas thiab Xeem Qhov Zoo DAC Nrog ESP32: 5 Cov Kauj Ruam
Video: QHIA QHOV TSEEB - KUB VAJ LOOG TSUA NEW MUSIC VIDEO 2022 2024, Hlis ntuj nqeg
Anonim
Yuav Ua Li Cas thiab Xeem Qhov Zoo DAC Nrog ESP32
Yuav Ua Li Cas thiab Xeem Qhov Zoo DAC Nrog ESP32
Yuav Ua Li Cas thiab Xeem Qhov Zoo DAC Nrog ESP32
Yuav Ua Li Cas thiab Xeem Qhov Zoo DAC Nrog ESP32

ESP32 muaj 2 8-ntsis Digital rau Analogue Converters (DACs). Cov DACs no tso cai rau peb los tsim cov khoom siv hluav taws xob nyob hauv ib thaj tsam (0-3.3V) nrog 8 qhov kev daws teeb meem. Hauv Cov Lus Qhia no, Kuv yuav qhia koj yuav tsim DAC li cas thiab qhia nws qhov kev ua tau zoo nrog rau sib piv nws rau ESP32 DAC. Cov cim ntsuas kev ua haujlwm Kuv yuav saib nrog rau

  • Qib Siab
  • Bandwidth
  • Ib qho kev tsis sib haum xeeb
  • Qhov sib txawv tsis sib xws

Txhawm rau ntsuas cov ntsuas no kuv yuav siv ADS1115.

Nws yog ib qho tseem ceeb kom nco ntsoov tias koj qhov kev ntsuas ntawm txhua qhov ntsuas no tsuas yog raug raws li koj lub cuab yeej siv (qhov no yog ADS115). Piv txwv li, ADS115 tsis muaj 16-ntsis qhov tseeb thaum nws los txog rau nws qhov hluav taws xob poob qis thiab nce. Cov yuam kev no yuav loj li 0.1%. Rau ntau lub kaw lus, cov kev ua yuam kev no tuaj yeem tsis quav ntsej thaum qhov tseeb raug txwv tsis pub muaj kev txhawj xeeb.

Khoom siv

  • TIAB SA 1115
  • Pawg ESP32
  • daim ntawv qhia zaub mov
  • jumper cov xov hlau
  • 5 kOhm Resistor
  • 1 micro-Farad ceramic capacitor

Kauj Ruam 1: Teem Tawm Breadboard

Teem Tawm Breadboard
Teem Tawm Breadboard

Txuas cov kab hauv qab no

Nruab nrab ntawm ESP32 thiab ADS1115

3v3vd wb

GND GND

GPIO 22 SCL

PIB 21 SDA

Ntawm ADS1115

ADDR GND (ADS115)

Ua DAC

Muaj ntau txoj hauv kev los ua DAC. Qhov yooj yim tshaj yog kom qis dhau lim PWM teeb liab nrog tus tiv thaiv thiab lub peev xwm. Kuv tuaj yeem tau ntxiv op-amp nyob ntawm no ua qhov tsis zoo tab sis xav kom ua tej yam yooj yim. Kev tsim qauv no yog qhov yooj yim thiab pheej yig los siv nrog txhua lub microcontroller uas txhawb PWM. Kuv yuav tsis mus hla txoj kev xav ntawm kev tsim ntawm no (google PWM DAC).

Tsuas yog txuas GPIO255 KOhm resistor 1 microFarad Capacitor gnd

Tam sim no txuas lub xov hlau jumper los ntawm qhov chaw uas tus tiv thaiv ua tau raws lub capacitor rau A0 ntawm ADS115.

Kauj Ruam 2: Ntsuas Teeb Meem rau Qib Siab

Ntsuas Teeb Meem rau Qib Siab
Ntsuas Teeb Meem rau Qib Siab

Txhawm rau ntsuas qib suab nrov tsuas yog sau tsab ntawv hauv qab no. Txhawm rau ntsuas qhov no peb tsuas yog tso DAC ntawm tus nqi ruaj khov thiab ntsuas seb qhov hluav taws xob oscillates dhau lub sijhawm.

Vim yog tsim los ntawm DAC, lub suab nrov yuav zoo tshaj thaum PWM teeb liab nyob ntawm 50% kev ua haujlwm. Yog li qhov no yog qhov uas peb yuav tshuaj xyuas nws. Peb tseem yuav ntsuas ESP32 ntawm tib lub teeb liab no. Peb tseem yuav lim lub ESP32 DAC nrog tib lub lim qis dhau los txhawm rau txhawm rau ntsuas ntsuas sib piv.

Rau kuv cov zis tau meej. PWM tsim muaj> 6dB SNR zoo dua (uas yog 2 zaug zoo dua). Kev yeej meej rau DAC tshiab. Ib qhov tsis meej pem yog tias muaj cov ntxaij lim dej ua rau hauv ADC uas yog qhov tseeb tshaj plaws txhim kho SNR. Yog li qhov tseem ceeb yuav nyuaj rau txhais. Yog tias kuv tau siv lub lim xaj thib ob qhov no yuav tsis yog qhov no.

Xijpeem chaws yog hauv qab no

#suav nrog

#suav nrog Adafruit_ADS1115 tshaj tawm; // adafruit tsev qiv ntawv rau adc int16_t adc0; // qhov tsis muaj teeb tsa (tsis muaj dab tsi) {Serial.begin (115200); // Pib serial ads.setGain (GAIN_TWO); // 2x nce +/- 2.048V 1 ntsis = 0.0625mV ads.begin (); // pib adc ntab M = 0; // thawj lub ntsiab lus ntab Mp = 0; // previouos txhais tau tias ntab S = 0; // pib Variance ntab Sp = 0; // qhov sib txawv yav dhau los const int reps = 500; // tus naj npawb ntawm kev rov ua dua int n = 256; // naj npawb ntawm cov qauv coj ledcSetup (0, 25000, 8); // set pwm frequecny = 25000 Hz at 8 bits resolution ledcAttachPin (25, 0); // set pwm on pin 25 ledcWrite (0, 128); // teeb tsa nws mus rau ib nrab kev ua haujlwm (suab nrov tshaj) ncua (3000); // tos rau lub sijhawm daws teeb meem ntab snrPWM [reps]; // array ntawm snrs rau PWM ntab snrDAC [reps]; // array ntawm snrs rau DAC rau (int i = 0; i <reps; i ++) {// loope over repititions for (int k = 1; k <(n+1); k ++) {// loope over sample adc0 = ads.readADC_SingleEnded (0); // tau nyeem M = Mp + (adc0 - Mp) / k; // suav dov txhais Mp = M; // teeb tsa yav dhau los S = Sp + (adc0 - Mp) * (adc0 - M); // xam qhov sib txawv ntawm qhov sib txawv Sp = S; // teeb tsa qhov sib txawv yav dhau los} // snr hauv dB snrPWM = 20 * log10 (3.3 / (sqrt (S / n) *.0625 *.001)); // pib qhov tseem ceeb M = 0; Mp = 0; S = 0; Sp = 0; } ledcDetachPin (25); // tshem PWM los ntawm tus pin 25 dacWrite (25, 128); // sau rau DAC ncua (3000); // tos kom khom rau (int i = 0; i <reps; i ++) {// tib yam li PWM lub voj rau (int k = 1; k <(n+1); k ++) {adc0 = ads.readADC_SingleEnded (0); M = Mp + (adc0 - Mp) / k; Mp = M; S = Sp + (adc0 - Mp) * (adc0 - M); Sp = S; } snrDAC = 20 * log10 (3.3 / (sqrt (S / n) *.0625 *.001))); M = 0; Mp = 0; S = 0; Sp = 0; } // phiaj SNRs ntawm ib kab rau (int i = 1; i <reps; i ++) {Serial.print ("PWM_SNR (dB):"); Serial.print (snrPWM ); Serial.print (","); Serial.print ("ESP32_SNR (dB):"); Serial.println (snrDAC [kuv]); }} void loop (tsis muaj dab tsi) {}

Kauj Ruam 3: Kev Sib Koom Tsis Ncaj Ncees thiab Kev Sib Txawv Tsis Txaus Siab

Kev sib xyaw tsis sib xws thiab sib txawv tsis sib xws
Kev sib xyaw tsis sib xws thiab sib txawv tsis sib xws

Qhov tsis sib xws tseem ceeb yog ntsuas ntawm qhov sib txawv ntau npaum li cas nyob nruab nrab ntawm koj DAC tso zis hluav taws xob thiab kab ncaj. Qhov loj dua qhov no yog qhov phem tshaj nws yog …

Qhov sib txawv ntawm qhov tsis sib xws yog ntsuas ntawm kwv yees ntau npaum li cas pom qhov hloov pauv ntawm qhov hluav taws xob (los ntawm ib txoj cai mus rau lwm qhov) sib txawv ntawm qhov uas yuav xav tau los ntawm kab ncaj.

Cov txiaj ntsig ntawm no tau nthuav tiag tiag. Ua ntej tshaj plaws, ob qho tib si muaj tsawg dua 0.5lsb yuam kev (ntawm 8-ntsis kev daws teeb meem) uas yog qhov zoo tab sis PWM muaj qhov ua tau zoo dua qhov ua tau zoo. Ob qho tib si muaj qhov sib txawv sib txawv tsis sib xws tab sis ESP32 DAC muaj qee qhov txawv txawv heev. Dab tsi ntxiv, PWM txoj kev muaj qee tus qauv rau qhov ua yuam kev. Qhov tseem ceeb nws tau hla dhau thiab ua rau pom qhov tseeb qhov hluav taws xob hauv kev hloov pauv.

Kuv qhov kev tsis txaus ntseeg yog qhov no yog qee qhov txawv txav hauv qhov ua li cas 8-ntsis PWM teeb liab tau tsim ntawm ESP32.

Ib txoj hauv kev los kho qhov no yog ua kom nrawm nrawm ntawm ob tus lej nyob ib sab (piv txwv 128, 129) nrog PWM. Nrog cov lim lim analog qis, qhov ua yuam kev yuav nruab nrab rau xoom. Kuv sim qhov no hauv software thiab qhov tseeb txhua qhov ua yuam kev ploj. Tam sim no tus txheej txheem PWM muaj kab sib chaws uas raug rau 16-ntsis!

Anywho cov cai los tsim cov ntaub ntawv yog hauv qab no. Cov zis yuav nyob ntawm tus saib xyuas hauv.csv hom ntawv. Tsuas yog luam nws mus rau cov ntawv sau rau kev ua haujlwm ntxiv.

#suav nrog

#suav nrog Adafruit_ADS1115 tshaj tawm; / * Siv qhov no rau 16-ntsis version */ int16_t adc0; teeb tsa tsis muaj dab tsi (tsis muaj dab tsi) {Serial.begin (115200); ads.setGain (GAIN_ONE); // 2x nce +/- 2.048V 1 ntsis = 1mV 0.0625mV ads.begin (); ledcSetup (0, 25000, 8); ledcAttachPin (25, 0); Serial.println ("Cia Siab, Soj Ntsuam"); ledcWrite (0, 2); ncua (3000); rau (int i = 2; i <255; i ++) {ledcWrite (0, i); ncua (100); adc0 = ads.readADC_SingleEnded (0); ntab yuav tsum = (i / 256.0 * 3.3) / 4.096 * 32767; Serial.print (xav tau); Serial.print (","); Serial.println (adc0); }} void loop (tsis muaj dab tsi) {}

Kauj ruam 4: Bandwidth

Bandwidth
Bandwidth

Kuv yuav txiav txim siab bandwidth li ntawm no raws li qhov zaus uas qhov tso tawm ntawm DAC poob los ntawm 3dB. Qhov no yog kev pom zoo thiab, rau ib qib, kev xav. Piv txwv li, ntawm 6dB taw tes, DAC tseem yuav tso tawm lub teeb liab nws tsuas yog ~ 50% qhov dav.

Txhawm rau ntsuas qhov no peb tsuas yog hla sine nthwv dej ntawm qhov nce zuj zus los ntawm DAC mus rau ADC thiab ntsuas lawv cov qauv sib txawv. Qhov tsis txaus ntseeg, 3dB point yog nyob ntawm 30Hz (1/(2*pi*5000*1e-6)).

ESP32 tuaj yeem ua 1 Mega qauv ib pliag. Nov yog kev nqis tes ua yeej rau ESP32. Nws qhov dav tsis ploj mus nyob rau hauv 100Hz bandwidth cheeb tsam xeem.

Cov cai hauv qab no tuaj yeem ntsuas PWM DAC bandwidth.

#suav nrog

#suav nrog Adafruit_ADS1115 tshaj tawm; / * Siv qhov no rau 16-ntsis version */ int16_t adc0; int16_t adc1; teeb tsa tsis muaj dab tsi (tsis muaj dab tsi) {ntab M; ntab Mp = 0; ntab S = 0; ntab Sp = 0; Serial.begin (115200); ads.setGain (GAIN_ONE); // 1x nce +/- 4.096V 1 ntsis = 2mV 0.125mV ads.begin (); ledcSetup (0, 25000, 8); ledcAttachPin (25, 0); ncua (5000); Serial.println ("Zaus, Tshaj Tawm"); rau (int i = 1; i <100; i ++) {unsigned ntev pib = millis (); unsigned ntev T = millis (); Sp = 0; S = 0; M = 0; Mp = 0; int tau = 1; tus qauv ntab; thaum ((T - pib) <1000) {int tawm = 24 * sin (2 * PI * i * (T - pib) / 1000.0) + 128; ledcWrite (0, tawm); adc0 = ads.readADC_SingleEnded (0); M = Mp + (adc0 - Mp) / k; Mp = M; S = Sp + (adc0 - Mp) * (adc0 - M); Sp = S; T = millis (); k ++; } yog (i == 1) {norm = sqrt (S / k); } Serial.print (kuv); Serial.print (","); Serial.println (sqrt (S / k) / norm, 3); k = 0; }} void loop (tsis muaj dab tsi) {}

Thiab tus lej no yuav ntsuas ESP32 bandwidth. Nco ntsoov tshem lub capacitor lossis cov txiaj ntsig yuav zoo ib yam rau ob txoj hauv kev.

#suav nrog

#suav nrog Adafruit_ADS1115 tshaj tawm; / * Siv qhov no rau 16-ntsis version */ int16_t adc0; int16_t adc1; teeb tsa tsis muaj dab tsi (tsis muaj dab tsi) {ntab M; ntab Mp = 0; ntab S = 0; ntab Sp = 0; Serial.begin (115200); ads.setGain (GAIN_ONE); // 1x nce +/- 4.096V 1 ntsis = 2mV 0.125mV ads.begin (); ncua (5000); Serial.println ("Zaus, Tshaj Tawm"); rau (int i = 1; i <100; i ++) {unsigned ntev pib = millis (); unsigned ntev T = millis (); Sp = 0; S = 0; M = 0; Mp = 0; int tau = 1; tus qauv ntab; thaum ((T - pib) <1000) {int tawm = 24 * sin (2 * PI * i * (T - pib) / 1000.0) + 128; dacWrite (25, tawm); adc0 = ads.readADC_SingleEnded (0); M = Mp + (adc0 - Mp) / k; Mp = M; S = Sp + (adc0 - Mp) * (adc0 - M); Sp = S; T = millis (); k ++; } yog (i == 1) {norm = sqrt (S / k); } Serial.print (kuv); Serial.print (","); Serial.println (sqrt (S / k) / norm, 3); k = 0; }} void loop (tsis muaj dab tsi) {}

Kauj Ruam 5: Kaw Kev Xav

Tus tsim DAC tshiab yeej ntawm kab thiab suab nrov tab sis poob ntawm kev siv bandwidth. Nyob ntawm koj daim ntawv thov ib qho ntawm cov ntsuas no yuav yog qhov tseem ceeb dua lwm qhov. Nrog rau cov txheej txheem ntsuas no, koj yuav tsum muaj peev xwm txiav txim siab qhov kev txiav txim siab ntawd!

Tsis tas li, kuv xav tias nws tsim nyog taw qhia ntawm no tias vim tias PWM tso zis muaj suab nrov qis, nrog qhov tshwj xeeb kab nws yuav tsum muaj peev xwm tsim kom muaj kev daws teeb meem ntau dua DAC nrog PWM tso zis (tej zaum txawm tias 16-ntsis qhov tseeb). Qhov ntawd yuav siv qee txoj haujlwm. Txog thaum ntawd, Kuv twv koj adieu!

Pom zoo: