Cov txheej txheem:

Khiav Qhov Nruab Nrab rau Koj Txoj Haujlwm Microcontroller: 6 Kauj Ruam
Khiav Qhov Nruab Nrab rau Koj Txoj Haujlwm Microcontroller: 6 Kauj Ruam

Video: Khiav Qhov Nruab Nrab rau Koj Txoj Haujlwm Microcontroller: 6 Kauj Ruam

Video: Khiav Qhov Nruab Nrab rau Koj Txoj Haujlwm Microcontroller: 6 Kauj Ruam
Video: Zoo Siab Nrog Koj - Paj Tsua Thoj [ Official MV ] Nkauj Tawm Tshiab 2022 2024, Kaum ib hlis
Anonim
Khiav Nruab Nrab rau Koj Cov Haujlwm Microcontroller
Khiav Nruab Nrab rau Koj Cov Haujlwm Microcontroller

Hauv cov lus qhia no kuv yuav piav qhia tias qhov nruab nrab khiav yog dab tsi thiab vim li cas koj yuav tsum mob siab rau nws, nrog rau qhia koj yuav ua li cas nws yuav tsum raug coj los siv rau kev ua kom tau zoo tshaj plaws (tsis txhob txhawj xeeb txog qhov nyuaj, nws yooj yim heev rau kev nkag siab thiab kuv yuav muab qhov yooj yim siv tsev qiv ntawv rau koj cov phiaj xwm arduino ib yam:)

Khiav nruab nrab, kuj tseem raug xa mus rau qhov txav mus nruab nrab, txav mus los lossis txhais tau tias yog, yog ib lo lus siv los piav qhia tus nqi nruab nrab ntawm qhov kawg N qhov kawg hauv cov ntaub ntawv. Nws tuaj yeem suav tau raws li qhov nruab nrab ib txwm lossis koj tuaj yeem siv kev dag ntxias kom nws muaj qhov cuam tshuam tsawg kawg ntawm kev ua tiav ntawm koj cov cai.

Kauj Ruam 1: Siv Cov Ntaub Ntawv: Txhim Kho Tawm ADC Kev Ntsuas

Siv Cov Ntaub Ntawv: Txhim Kho Tawm ADC Kev Ntsuas
Siv Cov Ntaub Ntawv: Txhim Kho Tawm ADC Kev Ntsuas

Arduino muaj qhov tsim nyog 10 ntsis ADC nrog lub suab nrov me me. Thaum ntsuas tus nqi ntawm lub ntsuas pa xws li lub zog ntsuas lub zog, lub tshuab ntsuas hluav taws xob lossis lwm yam khoom siv suab nrov, nws nyuaj rau ntseeg tias kev ntsuas ntsuas yog qhov tseeb.

Ib qho kev daws teeb meem yog siv ntau qhov kev ntsuas txhua lub sijhawm koj xav nyeem koj lub ntsuas thiab ntsuas qhov nruab nrab. Qee qhov no yog qhov kev daws teeb meem tab sis tsis tas li. Yog tias koj xav nyeem ADC 1000 zaug hauv ib ob, koj yuav tsum tau 10 000 yog tias koj ntsuas qhov nruab nrab ntawm 10 ntsuas. Qhov pov tseg loj ntawm kev suav sijhawm.

Kuv qhov kev daws teeb meem yog ntsuas 1000 zaus ib pliag, hloov kho qhov nruab nrab txhua lub sijhawm thiab siv nws raws li tus nqi tam sim no. Txoj hauv kev no qhia txog qee qhov latency tab sis txo qis kev ua lej ntawm koj daim ntawv thov, muab sijhawm rau koj ntau ntxiv rau kev ua tiav.

Hauv daim duab saum toj no kuv tau siv qhov nruab nrab ntawm qhov ntsuas 32 kawg. Koj yuav pom tias txoj hauv kev no tsis yog 100% ua tsis tau tab sis nws txhim kho qhov tseeb (nws tsis phem dua li qhov nruab nrab 32 qhov piv txwv txhua lub sijhawm). Yog tias koj xav suav qhov nruab nrab ntawm 32 ntsuas txhua lub sijhawm, uas yuav siv ntau dua 0.25 ms ntawm Arduino UNO rau kev ntsuas ib leeg!

Kauj Ruam 2: Siv Cov Ntaub Ntawv: Ntsuas DC Cheeb Tsam ntawm Microphone Teeb Meem

Siv Cov Ntaub Ntawv: Ntsuas DC Cheeb Tsam ntawm Microphone Teeb Meem
Siv Cov Ntaub Ntawv: Ntsuas DC Cheeb Tsam ntawm Microphone Teeb Meem
Siv Cov Ntaub Ntawv: Ntsuas DC Cheeb Tsam ntawm Microphone Teeb Meem
Siv Cov Ntaub Ntawv: Ntsuas DC Cheeb Tsam ntawm Microphone Teeb Meem
Siv Cov Ntaub Ntawv: Ntsuas DC Cheeb Tsam ntawm Microphone Teeb Meem
Siv Cov Ntaub Ntawv: Ntsuas DC Cheeb Tsam ntawm Microphone Teeb Meem

Arduino tuaj yeem ntsuas qhov ntsuas ntawm 0 thiab Vcc (ib txwm 5 V). Lub teeb liab tau ua tiav AC thiab yog tias koj xav ntsuas nws ntawm lub microcontroller, koj yuav tsum muaj kev ywj pheej nyob ib puag ncig 1/2 Vcc. Hauv qhov haujlwm Arduino UNO uas yuav txhais tau tias yog kwv yees li 2.5 V (DC) + lub teeb liab (AC). Thaum siv 10 ntsis ADC thiab 5 V fais fab mov, 2.5 V kev tsis ncaj ncees yuav tsum ntsuas sib npaug ntawm 512. Yog li kom tau txais AC tus nqi ntawm cov teeb liab, 512 yuav tsum tau muab rho tawm los ntawm kev ntsuas ADC thiab qhov ntawd yog nws, puas yog?

Hauv lub ntiaj teb zoo tshaj plaws, qhov ntawd yuav muaj tseeb. Hmoov tsis zoo lub neej yog qhov nyuaj dua thiab peb cov teeb meem kev tsis ncaj ncees yuav ploj mus. Feem ntau yog 50 Hz suab nrov (60 Hz yog tias koj nyob hauv Asmeskas) los ntawm hluav taws xob network. Feem ntau nws tsis yog txhua yam muaj teeb meem tab sis nws yog qhov zoo kom paub tias nws muaj. Teeb meem ntau dua yog cov kab tawm los ntawm cua sov ntawm cov khoom. Koj ua tib zoo teeb tsa DC offset kho thaum pib thiab nws maj mam ploj mus raws li koj daim ntawv thov ua haujlwm.

Kuv yuav piav qhia qhov teeb meem no nrog (suab paj nruag) ntaus ntes. Koj teeb tsa koj qhov kev tshem tawm kev tsis txaus siab thiab ntaus yeej pom tseeb (daim duab 2). Tom qab qee lub sijhawm, DC kev txav mus los thiab cov neeg ntaus yeej tsis pom zoo rau lub microcontroller (daim duab 3). Kev ntsuas ntsuas qhov ntsuas yuav raug tshawb pom qhov tob hauv lub neej yav tom ntej qhia vim tias nws tshaj qhov uas tau hais tseg hauv kab lus no.

Hmoov zoo, muaj ib txoj hauv kev los ua ntu zus los suav cov suab lub DC offset. Nws yuav tsis muaj qhov xav tsis thoob tias qhov nruab nrab nruab nrab, cov ncauj lus ntawm cov lus qhia no, muab kev daws teeb meem.

Peb paub tias tus nqi nruab nrab ntawm ib qho AC teeb liab yog 0. Siv qhov kev paub no peb tuaj yeem txiav tawm tus nqi nruab nrab ntawm AC+DC teeb liab nws yog DC kev tsis ncaj ncees. Txhawm rau tshem nws, peb tuaj yeem ntsuas qhov nruab nrab ntawm ob peb qhov txiaj ntsig kawg thiab rho tawm nws los ntawm kev nyeem ADC tam sim no. Nco ntsoov tias koj yuav tsum siv sijhawm ntev txaus khiav nruab nrab. Txog lub suab, ib feem kaum ntawm ob (tus lej piv txwv nyob ntawm koj tus qauv piv txwv) yuav tsum txaus tab sis paub tias qhov nruab nrab ntev ua haujlwm tau zoo dua. Hauv thawj daim duab koj tuaj yeem pom piv txwv ntawm DC qhov kev xam pom tseeb nrog kev ua haujlwm nruab nrab nrog 64 lub ntsiab lus ntawm 1 kHz tus qauv tus nqi (tsawg dua qhov kuv tau pom zoo tab sis nws tseem ua haujlwm).

Kauj Ruam 3: Xam Xaj

Muab xam los
Muab xam los

Koj tuaj yeem xav txog kev khiav nruab nrab li qhov hnyav ntawm cov neeg hauv kws kho mob chav tos. Tus kws kho mob ua tiav kev tshuaj xyuas ib tus neeg mob thiab ib txhij ib tus neeg tshiab taug kev mus rau hauv chav tos.

Txhawm rau kom paub qhov hnyav nruab nrab ntawm txhua tus neeg mob tos hauv chav tos, kws saib xyuas mob tuaj yeem nug txhua tus neeg mob txog lawv qhov hnyav, ntxiv cov lej ntawd thiab faib los ntawm cov neeg mob. Txhua lub sijhawm kws kho mob lees txais tus neeg mob tshiab, tus kws saib xyuas mob yuav rov ua tiav tag nrho cov txheej txheem.

Tej zaum koj yuav xav tias: "Qhov no tsis zoo li ua tau zoo … Yuav tsum muaj txoj hauv kev zoo dua los ua qhov no." Thiab koj yuav raug.

Txhawm rau ua kom zoo dua cov txheej txheem no, tus kws saib xyuas neeg mob tuaj yeem khaws cov ntaub ntawv hnyav tag nrho ntawm pab pawg neeg mob tam sim no. Thaum kws kho mob hu xov tooj rau tus neeg mob tshiab, tus kws saib xyuas mob yuav nug nws txog nws qhov hnyav thiab rho tawm nws los ntawm pab pawg tag nrho thiab cia nws mus. Tus kws saib xyuas neeg mob yuav nug tus neeg mob uas nyuam qhuav taug kev mus rau hauv chav tos txog nws qhov hnyav thiab ntxiv rau qhov ntawd tag nrho. Qhov hnyav nruab nrab ntawm cov neeg mob tom qab txhua qhov kev hloov pauv yuav yog qhov hnyav sib faib los ntawm cov neeg mob (yog, zoo ib yam li ua ntej tab sis tam sim no tus kws saib xyuas mob nkeeg tsuas nug ob tus neeg txog lawv qhov hnyav es tsis yog txhua tus ntawm lawv). Kuv paub cov kab lus no tej zaum yuav nkag siab me ntsis yog li thov saib cov lus saum toj no kom pom meej ntxiv (lossis nug cov lus nug hauv cov lus).

Tab sis txawm tias koj tsis pom cov kab lus kawg ua rau koj tsis txaus siab koj yuav muaj lus nug xws li dab tsi yuav tsum muaj nyob hauv qhov pib thaum pib, kuv yuav tso qhov kuv nyuam qhuav nyeem hauv C code li cas? Qhov ntawd yuav hais nyob rau hauv cov kauj ruam tom ntej, qhov twg koj tseem yuav tau txais kuv qhov chaws.

Kauj ruam 4: Txoj Cai

Txoj Cai
Txoj Cai

Txhawm rau xam qhov nruab nrab khiav, koj xub xav tau ib txoj hauv kev khaws N qhov kawg. koj tuaj yeem muaj cov kab nrog N cov ntsiab lus thiab txav tag nrho cov ntsiab lus ib qho chaw txhua lub sijhawm koj ntxiv ib lub ntsiab lus (thov tsis txhob ua qhov no), lossis koj tuaj yeem sau dua ib ntu qub thiab kho tus pointer mus rau ntu tom ntej kom raug pov tawm (thov ua qhov no:)

Tus neeg ntim khoom yuav tsum pib ua ntej rau 0, tib yam mus rau txhua lub ntsiab lus hauv kab qeeb. Hauv lwm qhov xwm txheej koj qhov nruab nrab khiav yuav ib txwm tsis raug. Koj yuav pom tias ncua sijhawmLine_init saib xyuas thawj zaug ncua txoj kab ncua, koj yuav tsum saib xyuas tus kheej accumulator koj tus kheej.

ntxiv ib lub caij kom ncua kab yog ib qho yooj yim raws li qhov txo qis qhov ntsuas ntawm cov khoom tshiab los ntawm 1, ua kom ntseeg tau tias nws tsis taw tes tawm ntawm ncua ncua kab kab. tom qab qhov ntsuas ntsuas qis dua thaum nws yog 0, nws yuav tig ncig mus rau 255 (vim tias nws yog 8 ntsis tsis tau kos npe tag nrho). Modulo (%) tus neeg teb xov tooj nrog qhov loj ntawm ncua kab kab yuav ua kom pom tseeb yuav taw qhia rau lub ntsiab lus siv tau.

Xam qhov nruab nrab khiav yuav tsum nkag siab yog tias koj ua raws kuv qhov piv txwv hauv cov kauj ruam dhau los. Rho tawm cov khoom qub tshaj plaws los ntawm cov khoom ntim khoom, ntxiv tus nqi tshiab tshaj plaws rau cov khoom ntim, thawb tus nqi tshiab tshaj plaws rau txoj kab ncua, xa rov qab cov khoom sib faib los ntawm tus lej.

Yooj yim, txoj cai?

Thov koj xav ua kev sim nrog siv cov lej txuas kom nkag siab zoo tias txhua yam ntawm no ua haujlwm li cas. Raws li nws tam sim no sawv, arduino nyeem tus nqi sib piv ntawm tus lej pin A0 thiab luam tawm "[ADC tus nqi], [khiav nruab nrab]" ntawm qhov chaw nres nkoj ntawm 115200 tus nqi baud. Yog tias koj qhib arduino cov phiaj xwm phiaj xwm ntawm qhov raug baud tus nqi, koj yuav pom ob kab: ADC tus nqi (xiav) thiab smoothed tawm tus nqi (liab).

Kauj ruam 5: Ntxiv

Ntxiv
Ntxiv

Muaj ob peb yam uas koj tsis tas yuav tsum paub txhawm rau siv qhov nruab nrab hauv koj txoj haujlwm ut yuav tsis ua mob rau paub.

ncua: Kuv yuav pib nrog tham txog kev piv txwv ntawm cov kauj ruam no. Koj yuav pom tias kev ua haujlwm nruab nrab ntawm ntau lub ntsiab lus qhia txog kev ncua sijhawm loj dua. Yog tias koj lub sijhawm teb hloov pauv tus nqi yog qhov tseem ceeb, koj yuav xav siv qhov nruab nrab khiav luv lossis nce tus nqi piv txwv (ntsuas ntau dua).

Tsiv mus.

Thaum pib: Thaum kuv tham txog qhov pib ua cov khoom sib txuam thiab ncua cov ntsiab lus, Kuv hais tias koj yuav tsum pib ua lawv txhua tus rau 0. Xwb koj tuaj yeem pib ncua txoj kab ncua rau txhua yam uas koj nyiam tab sis cov khoom sib txuam yuav tsum pib ua qhov tshiab ntawm N cov ntsiab lus hauv kab ncua (qhov twg N yog tus naj npawb ntawm cov ntsiab lus hauv koj qhov nruab nrab khiav). Yog tias cov khoom pib pib ua lwm yam txiaj ntsig, suav qhov nruab nrab yuav tsis raug - txawm tias qis heev lossis siab dhau, ib txwm los ntawm tib tus lej (piv txwv tib yam xwm txheej pib). Kuv qhia koj sim kawm vim li cas qhov no thiaj li siv qee "cwj mem thiab ntawv simulation".

qhov loj me me: Koj yuav tsum nco ntsoov tias cov khoom ntim yuav tsum loj txaus los khaws tag nrho cov ntsiab lus hauv kab ncua yog tias lawv txhua tus zoo lossis tsis zoo max. Xyaum txhais tau hais tias cov khoom ntim yuav tsum yog ib hom ntaub ntawv ntau dua li ncua kab ntu thiab kos npe, yog tias ncua sijhawm kab ntsiab lus tau kos npe.

ua kom yuam kev: Cov kab ncua ntev siv sijhawm nco ntau. Qhov ntawd tuaj yeem dhau los ua teeb meem. Yog tias koj muaj lub cim xeeb txwv ntau thiab tsis quav ntsej ntau txog qhov raug, koj tuaj yeem kwv yees qhov nruab nrab nruab nrab los ntawm kev ncua ncua tag nrho thiab ua qhov no hloov: rho tawm 1/N * cov khoom sib sau los ntawm cov khoom ntim thiab ntxiv tus nqi tshiab (piv txwv li 8 ntev khiav nruab nrab: accumulator = accumulator * 7/8 + tus nqi tshiab). Txoj hauv kev no muab cov txiaj ntsig tsis raug tab sis nws yog txoj hauv kev tsim nyog los suav qhov nruab nrab thaum koj ua haujlwm qis.

linguistics: "khiav nruab nrab/txhais tau tias" feem ntau yog siv thaum hais txog qhov nruab nrab lub sijhawm tiag tiag thaum "txav nruab nrab/txhais tau tias" feem ntau txhais tau tias cov txheej txheem ua haujlwm ntawm cov ntaub ntawv zoo li teeb tsa zoo li daim ntawv nthuav qhia.

Kauj Ruam 6: Xaus

Kuv vam tias cov lus qhia no yooj yim txaus kom nkag siab thiab nws yuav pab koj hauv koj cov phiaj xwm yav tom ntej. Thov koj xav tso tawm cov lus nug hauv cov lus hauv qab no yog tias muaj dab tsi tsis meej.

Pom zoo: