Cov txheej txheem:

Microcontroller Npuag Tone Generator hauv C-code: 8 Cov Kauj Ruam (nrog Duab)
Microcontroller Npuag Tone Generator hauv C-code: 8 Cov Kauj Ruam (nrog Duab)

Video: Microcontroller Npuag Tone Generator hauv C-code: 8 Cov Kauj Ruam (nrog Duab)

Video: Microcontroller Npuag Tone Generator hauv C-code: 8 Cov Kauj Ruam (nrog Duab)
Video: 🫣😱See what high voltage does #shorts 2024, Hlis ntuj nqeg
Anonim
Microcontroller Npuag Tone Generator hauv C-code
Microcontroller Npuag Tone Generator hauv C-code

Qhov kawg ntawm Lub Kaum Hli xyoo tas los qhia cov neeg siv carmitsu xa lus rau kuv tom qab pom kuv lub thawv ntim khoom noj synth. Los ntawm nws cov lus: Kuv qhia suab paj nruag hauv tsev kawm ntawv theem qis. Peb ua si ntau lub suab kaw suab. piv txwv li cov menyuam yaus ua si flutes me …… Cov tub ntxhais kawm no thawb rau hauv lub voj voos nrog sau cov npe nyob rau tib lub sijhawm cov tub ntxhais kawm tau ua si ib zaj nkauj….. Feem ntau ntawm cov menyuam xav tau tshwj xeeb tuaj yeem ua qhov no zoo thiab nyob rau lub sijhawm nrog cov nkauj. Qhov kuv tab tom nrhiav yog tsim lub tshuab hluav taws xob yooj yim heev kom cov menyuam no tuaj yeem ua suab zoo ib yam li cov uas tau ua los ntawm cov tub ntxhais kawm ntawm lawv lub kaw suab. Kuv yuav tsuas yog ob peb lub suab. Kuv xav tias kuv tuaj yeem txuas qee yam khawm me me rau hauv qab ntawm lawv cov kab puag ncig kom thaum lawv thawb rau lawv lub suab yuav tawm los ntawm tus hais lus me, nrov txaus kom lawv hnov. Muaj ib leej niam uas yog tus kws qhia ntawv thiab nyiam tsev kawm ntawv, kuv yuav tiv thaiv tau li cas? Qhov tseeb yuav qhia kuv ua tsis tau. Qhov no zoo nkauj npaum li keeb kwm ntawm qhov project thiab cov lus qhia yuav tsim koj li cas.

Kauj Ruam 1: Pib lossis Vim Li Cas Kuv Ua Tsis Tau Rau Analog

Pib lossis Vim Li Cas Kuv Ua Tsis Tau Rau Analog
Pib lossis Vim Li Cas Kuv Ua Tsis Tau Rau Analog

Cov khoom zoo pib ntawm nplooj ntawv tom ntej. Yog tias koj xav paub yuav ua li cas kuv thiaj li siv cov khoom kuv tau ua, nyeem ntawm. Qhov tseeb timer: Tom qab muab txoj haujlwm qee qhov xav kuv tam sim xav txog lub tshuab hluav taws xob piezo los ntawm kuv phau ntawv op-amps Forest Mims III. Zoo li txoj hauv kev zoo mus, nws tsuas yog piezo, 741 IC thiab ob peb yam tsis sib haum. Tsis muaj teeb meem loj? Zoo nws muaj 2 teeb meem, 1) thaum koj nyuaj siab hloov, nws muaj peev xwm hloov lub suab 2) nws yog damn nyob ze ua tsis tau. Thawj qhov yuav tuaj yeem kov yeej nrog qee qhov kev siv thev naus laus zis, txawm hais tias kuv tsis paub yuav ua li cas yam tsis ntxiv lwm lub txee. Nws kuj tseem tuaj yeem yog qhov teeb meem nrog kev siv piezo. Qhov teeb meem thib ob tsuas yog tsis tau txais txiaj ntsig thaum koj pib sim tsoo qee lub suab. Dab tsi txog 555? Cov ntawv qhia pom lub sijhawm ua haujlwm raws li cov neeg tawm tsam thiab cov khoom siv hluav taws xob. Uas yog qhov zoo kom txog thaum koj pib ntaus nqi qhov tseem ceeb ntawm lub ntiaj teb tiag, qhov ntawd yog thaum koj yuav pom ntaus 440Hz suab pib kom nyuaj me ntsis. Koj tuaj yeem siv cov lauj kaub txiav kom tau txais nws nyob hauv, tab sis dhau sijhawm lawv zoo li txav mus. Kev ntsuas qhov ntsuas tas li, suav sau nyob rau sab saum toj ntawm qhov nce nrawm ntawm tus nqi thiab ntau qhov ntawm qhov, thiab kuv tus poj niam ua lub suab hloov thaum nws thawb lub khawm tua 555 rau qhov haujlwm no. Op-amp: Tsis muaj teeb meem, tib neeg tau ua synths nrog op-amps txij li ua ntej kuv yug los. Nws nyuaj npaum li cas los ua qhov yooj yim tiag tiag, nrog ob peb ntu thiab cov ntawv tshwj xeeb? Nyuaj tshaj qhov kuv xav. Feem ntau ntawm cov qauv tsim tawm muaj qhov nyuaj dhau rau txoj haujlwm no. Synth cov neeg tsim qauv tau tawm rau lub suab zoo/suab nrov. Qhov no cuam tshuam ncaj qha nrog txoj haujlwm uas xav tias yuav pheej yig txaus rau tsev kawm lossis kws qhia ntawv pob nyiaj siv. Kev tsim cov keyboard yog yooj yim txaus, nws tsuas yog pawg ntawm cov neeg tawm tsam thiab lub zog lossis ib pawg ntawm diodes thiab lub zog. Nws yog qhov seem ntawm kev tsim hluav taws xob, thiab tus nqi ntawm pcbs kev cai uas pib tawm ntawm tes rau ib tus neeg thaum pib qib hluav taws xob. Kev txiav txim siab qhov project: Yog li txoj haujlwm tau rov txhais dua ua ntej kuv txawm tias yuav mus tiag tiag. Kuv xav tau qee yam uas tuaj yeem hloov tus pin tus hais lus, lub sijhawm, nrog nias lub pob. Kuv tsis xav kom tsim thiab yuav PCB. Qhov no yuav tsum siv ob peb yam khoom tuaj yeem ua tau, thiab sib sau ua cov khoom siv pib. Nws tau ntsia kuv ntawm lub ntsej muag tag nrho lub sijhawm. Duh !! Microcontroller! Microcontroller: Yog li tom qab yuav ob qho khoom siv niaj hnub no Bare Bone Bones Arduino cov khoom siv thiab Cov Neeg Txom Nyem Tsis Txawj Ntse Tus Kws Tshawb Fawb Lub Hom Phiaj Yooj Yim thiab cia lawv zaum ntawm kuv lub rooj rau ntau lub hlis tsis tau siv, Kuv tau ua tiav txoj haujlwm zoo. Kuv pib saib lub sijhawm nws yuav siv ob qho los ua ke, txoj kev kawm nkhaus rau tus lej, tus nqi, qhov xav tau ntxiv thiab ua rau nws ua qhov kuv xav tau thiab teeb tsa ntawm pawg phiaj. Tus nqi zoo nkauj heev, $ 15 ntxiv rau $ 20 FTDI cable rau Arduino, $ 12 ntxiv rau $ 22 USBtinyISP programmer. Kuv twb paub C ++ los ntawm tsev kawm qib siab me kuv tuaj yeem sawv thiab xam C rau microcontrollers yuav tsis yog qhov phem, thaum lwm yam tshaj li ntsais lub teeb kom paub tseeb tias kuv tso kuv cov khoom ua ke kom raug, Kuv tsis muaj kev paub txog Arduino. Ob leeg tuaj yeem ntsia tau. Nws yog qhov zoo nkauj heev pov tseg, yog li kuv txiav txim siab qhov tsawg dua ntawm ob, lub phiaj xwm phiaj xwm.

Kauj Ruam 2: Yam Koj Xav Tau Rev 1

Yam Koj Xav Tau Rev 1
Yam Koj Xav Tau Rev 1

Cov Nqi Tus NqiUSBtinyISP AVR Programmer Kit (USB SpokePOV Dongle) v2.0 $ 22.00https://www.adafruit.com/index.php? Main_page = product_info & cPath = 16 & products_id = 46Evil Mad Scientist labs ATmegaXX8 Mini Dev Kits $ 12 5-pk $ 2.75https://evilmadscience.com/tinykitlist/74-atmegaxx8Speaker (8-ohm Mini) $ 2.79https://www.radioshack.com/product/index.jsp? ProductId = 2062406SPST Feem ntau Qhib Momentary Hloov (peb siv 5) $ 3.49 (4pack) https://www.radioshack.com/product/index.jsp?productId=2062539"AAA "Tus tuav roj teeb $ 1.79https://www.radioshack.com/product/index.jsp? ProductId = 2102735SPST Submini Swb Hloov (xaiv tau rau lub zog hloov) $ 2.69 (2 pob) https://www.radioshack.com/product/index.jsp?productId=2062490LED thiab resistor (yeem, yog tias koj xav tau lub teeb pom kev zoo) $ yuav tsum tau dawb Yog tias lawv nyob ib puag ncigWire $ kuj yuav tsum tau dag ib puag ncigSilver solder (yog tias qhov no mus nyob qhov twg ze cov menyuam koj yuav tsum tsis txhob siv txhuas, cov niam txiv tau coj txawv txawv zoo nkauj txog qhov ntawd;)) Ntxuav cawv (kom rov Yog tias koj xav tau qee qhov chaw kom txuag tau nyiaj, koj tsis tas yuav tau cov khoom los ntawm RadioShack. Kuv tau ua vim tias lawv nyob ze thiab tuaj yeem kwv yees tau.

Kauj Ruam 3: Sib dhos Rev 1

Sib dhos Rev 1
Sib dhos Rev 1
Sib dhos Rev 1
Sib dhos Rev 1

Muab koj qhov chaw ua ke raws li qhia. Nco ntsoov siv tshuaj txhuam cawv thiab txhuam txhuam thaum koj ua tiav kom tshem tawm cov dej ntws los ntawm cov tshuaj txhuam hniav. Qhia hauv qab no rau cov uas nyiam nws. D1 thiab R1 tuaj yeem yog txhua yam koj xav tau, nws tsuas yog lub teeb pom kev zoo. C1 tsuas yog pab ua kom lub zog muaj zog me ntsis ntxiv. Kuv siv 10uF. Cov txheej txheem no zoo ib yam rau cov qauv tom qab, tsuas yog sib pauv tawm cov nyees khawm rau cov ntaub npuag. hauv qhov kev tshuaj xyuas zaum kawg kuv ntxiv cov hloov pauv rau PC4 thiab PC5 lossis tus pin 27 thiab 28.

Kauj Ruam 4: Yam Koj Xav Tau Rev 2

Yam Koj Xav Tau Rev 2
Yam Koj Xav Tau Rev 2

Yog li ntawd, koj tab tom pauv xov tooj cua Shack nyees khawm rau tes ua cov ntaub. Koj xav tau: Ntau yam xim ntawm cov ntaub, lossis ib qho xim yog tias koj xav tau txhua tus cim tib xim. Tshooj quilting ntawm koj lub khw muag ntaub ze tshaj plaws yog qhov chaw zoo tshaj plaws kom tau txais qhov pheej yig no. Quilting quarters yog $ 1.50 thiab koj tuaj yeem tau txais ib tuj ntawm qhov hloov pauv ntawm ib qho. Cov ntaub npuag, Kuv hais qhia Flectron npuag los ntawm LessEMF nws yog $ 20 rau 12 "x54" pieceEyelets rau txuas cov hlau rau ntaub. Koj tuaj yeem tau txais lawv ntawm cov khw muag ntaub feem ntau pheej yig. JoAnn muaj cov cuab yeej thiab 25 rau $ 2 Koj yuav xav tau rauj rau qhov no. Wire, Kuv siv 22AWG, Kuv hais kom me dua yog tias koj muaj nws. Nug ntawm lub khw thiab tej zaum koj tuaj yeem yuav los ntawm lub vaj. Qhov no tej zaum yuav ua haujlwm tau zoo, txawm hais tias kuv qhia koj kom nug ib tus neeg, tab sis kuv tau siv cov khoom xoob heev thaum xub thawj, tom qab ntawd hloov mus rau ib yam dab tsi nruj dua. Kuv qhia koj tsuas yog sim ob peb yam sib txawv kom txog thaum koj pom qhov ua haujlwm tau zoo tshaj plaws. Nws cua sov ntsws, qhov no ua rau txhua yam tswj tau ntau dua. cua sov ua kom cov xov hlau sib koom ua ke thaum lawv dhau ib leeg thiab lawv yuav nyob zoo dua.

Kauj Ruam 5: Sib dhos Rev 2

Sib dhos Rev 2
Sib dhos Rev 2
Sib dhos Rev 2
Sib dhos Rev 2
Sib dhos Rev 2
Sib dhos Rev 2

Muab cov ntaub npuag ntau xim sib ib leeg thiab txiav tawm ib lub xwmfab, nws tsis tas yuav zoo tag nrho. Hlau cov ntaub kom tau txais ib qho quav tawm, txheej lawv nyob rau ib sab dua thiab ua kom ntseeg tau tias cov npoo sib phim. Txiav ib qho ntug uas tsis ua. Qhov sab saum toj thiab hauv qab puag ncig, tawm sab laug thiab sab xis ncaj. Koj yuav rov qab hloov qhov tom qab xaws xwv kom tsis txhob ua ob sab puag ncig thiab tso qhov siab txaus rau ntawm ob sab kom thawb qhov hloov pauv yooj yim thaum koj ua tiav. Hloov tawm lub tiaj tiaj ntawm thawj thiab qhov kawg hloov. Kav mus rau ntawm koj lub tshuab xaws thiab muab ob qho ntawm ib puag ncig ua ke kom qhov zoo sib ntsib ib leeg thiab xaws ib lub seam ntawm qhov tiaj. xaws, txiav plaub fab tawm ntawm cov ntaub ua hluav taws xob thiab fuse ib sab. Txiav cov hlau kom ntev thiab hle ib qho kawg. xaim cov xaim nyob ib ncig ntawm lub qhov muag. (tus neeg muag khoom yuav tsis zoo li lo rau lub qhov muag) Txiav qhov me me ntawm cov ntaub ntawm ib ces kaum thiab rauj lub qhov muag kom txuas cov ntaub thiab xaim. tshem cov thaub qab los ntawm qhov fusing thiab fuse cov ntaub coj mus rau tom qab ntawm cov ntaub xim. Rov ua dua txhua qhov hloov pauv. Txhawm rau ua kom yooj yim dua, koj tuaj yeem ua kom sov cov raj sib txuas ua ke thaum twg ib lub xaim hla cov xaim rau qhov hloov mus tom ntej. Tsis zoo li cov hloov xim, qhov no yog ib daim ntev. Qhov no yuav yog dab tsi cov nyees khawm kov los ua qhov txuas. Txiav qhov me me thiab txuas cov xaim rau nws nrog lub qhov muag, zoo li cov xim hloov pauv saum. Fuse nws mus rau sab nraum qab ntawm cov ntaub hauv qab. Lub sab saum toj thiab hauv qab ua ke nrog cov ntaub ua kom pom lub ntsej muag tawm, siv lub tiaj tiaj los thim cov txheej tom qab nws tau xaws. ib lub voj voog ces cia li tshem tus pas nrig thiab txiav. Txiav lawv kom zoo thiab ntxig rau hauv cov hloov pauv. Qhov no yog dab tsi tuav cov ntaub npog sib nrug. Nws yuav yooj yim dua rau ntxig cov batting thaum koj tab tom hloov pauv qhov hloov pauv tom qab. Cov khoom kuv tau siv los tsoo qhov tsis zoo thaum kuv tau ntxig nws thiab kuv yuav tsum tau txais qhov sib txawv batting. Cov kab hauv qab ntev yuav yog hauv av.

Kauj Ruam 6: Yam Koj Xav Tau Rev 3

Yam Koj Xav Tau Rev 3
Yam Koj Xav Tau Rev 3

Hauv Rev 3 Kuv tau ua cov hloov pauv ywj pheej ntawm cov thaiv. Qhov no tau cawm lub sijhawm ntau. Kuv kuj nyiam qhov ua tiav ntawm qhov ua tiav ntau ntxiv. Yog li, ntawm no yog ntu tshiab uas koj xav tau: Snaps, Tsuas yog tau txais lawv los ntawm JoAnn's. Lawv tuaj nrog cov cuab yeej teeb tsa tsis zoo rau $ 7 Kuv xav qhia ib qho ntawm cov cuab yeej pliers hloov chaw raws li kuv yuav tsum coj kuv cov cuab yeej sib nrug los teeb tsa snaps hauv nruab nrab. Sew ons yuav yog lwm txoj hauv kev zoo, txawm hais tias lawv siv sijhawm ntev dua los ua raws. Cov xov xwm zoo, Spark Fun muaj cov khoom uas tuaj yeem nkag mus hauv koj lub tshuab xaws. Kuv yuav tsum tau mus qeeb tiag hauv kuv lub tshuab lossis cov xov yuav tawg. Koj cov nqi yuav txawv

Kauj Ruam 7: Sib dhos Rev 3

Sib dhos Rev 3
Sib dhos Rev 3
Sib dhos Rev 3
Sib dhos Rev 3
Sib dhos Rev 3
Sib dhos Rev 3
Sib dhos Rev 3
Sib dhos Rev 3

Qhov kev hloov kho no tau zoo dua li qhov kawg nyob rau lub sijhawm kom txog thaum tsim. Ntxiv rau, muaj cov hloov pauv tau cawm kuv txoj kev paub ntau dua ib zaug. Thov pib los ntawm kev ua lub hauv paus. Nws tsuas yog ib lub quilting quarter quav hauv ib nrab. Muab ib txheej ntawm batting rau saum thiab xaws, tawm hauv lub qhov los ntxeev nws. Thawb qhov dhau los ntawm lub qhov thiab koj ib txwm muaj lub hauv ncoo yam khoom. Kuv quilted nws yog li nws tau yooj yim los ua haujlwm nrog. Siv xov dawb thiab mus ceev. Kuv tau ua pob zeb diamond ntawm qhov no, tab sis zaum tom ntej kuv yuav tso zaj rau tom qab, lossis qee yam txias. Ntawm no, mus rau qhov hloov pauv. Kuv nyiam qhov kev tsim no vim tias koj tuaj yeem ua ib tuj ntawm cov no ua ntej thiab tsuas yog siv yam koj xav tau. pib los ntawm kev siv cov ntawv me me ntawm cov duab los qhia, ntawv, lossis ntaub thiab txiav cov pear zoo tawm ntawm nws. Siv qhov ntawd los ua phau ntawv qhia txhawm rau txiav ib sab saum toj thiab hauv qab rau txhua qhov hloov pauv. Kuv txiav ib qho xim rau txhua qhov hauv qab thiab xim sib txawv rau saum, tab sis koj tuaj yeem muaj tswv yim thiab ua qhov koj xav tau. Lengthen "stick" kom nws tuaj yeem qhwv hla ntug ntawm "pear." Txiav cov duab tawm ntawm cov ntaub fusing thiab cov coj ua thiab fuse ib sab ntawm cov ntaub coj ua. Tshem cov thaub qab los ntawm cov khoom fusing thiab fuse nws mus rau saum cov ntaub uas yuav nyob hauv qab thiab hauv qab ntawm cov ntaub uas yuav nyob rau saum. Qhwv me ntsis ntxiv nyob ib ncig ntawm saum. Lub taub hau hla mus rau koj lub tshuab xaws thiab tso batting nrog qhov nruab nrab ntawm cov ntaub saum toj thiab hauv qab. Xaws sab nraum cov ntaub uas siv tau thiab hla hla qhov "stick" ib feem ntawm qhov hloov. Kuv pom tias nws muaj peev xwm xaws cov ntaub ua tau zoo tshaj plaws rau hauv qab tsim luv. Nws zoo dua tsis txhob xaws los ntawm cov ntaub coj ua. Txuas snaps thiab qhov hloov pauv tau ua tiav. Kuv pom nws yooj yim dua siv tus txiv neej snap rau txhua qhov hauv qab/GND kev sib txuas thiab tus poj niam snap rau txhua sab saum toj. Qhov no ua rau txhua qhov hloov pauv hloov pauv. Qhov Circuit: Qhov hais txog kev txiav ib ncig yog tias koj muaj ntau qhov ntxiv. Kuv nqa kuv cov ntawv pov tseg, fused cov khoom loj ntawm fusing mus rau daim loj ntawm cov ntaub ua hluav taws xob thiab siv cov ntawd los txiav tawm cov duab plaub me me uas kuv siv los ua pawm. Roughly nteg tawm koj cov keyboards thiab fuse cov pawm mus rau lub hauv paus nrog chav txaus kom xaws kab rau lawv thiab muaj snap. Taw ntawm lub tshuab xaws kuv siv tsis tau ua siab zoo kom nyob ze rau lub snap, yog li nco ntsoov qhov ntawd thiab muab koj tus kheej rau qee qhov chaw. Txij li thaum kuv tau txais xov conductive uas tuaj yeem mus rau hauv kuv lub tshuab xaws kuv tsuas yog xaws ib txoj kab los ntawm ncoo rau ncoo thiab nraub qaum. Kuv yuav tsum mus qeeb lossis cov xov yuav tawg, tab sis nws tau nrawm dua li xaws tes. Tsis tas li nrog cov xov coj ua ntawm lub pob tw thiab rab koob, Kuv tau txais qhov kev sib txuas zoo tiag tiag. Cov khoom tsis zoo li vwm, tab sis cov kua nplaum me me los yog Elmers tshem qhov ntawd kom raug. Sim ua kom cov kab nyob deb ntawm ib leeg thiab koj yuav tsum tsis muaj teeb meem. Kev sib dhos zaum kawg: Kaw tag nrho koj cov keyboards, txuas lub rooj tsavxwm, thauj cov lej thiab koj ua tiav. Kuv siv xaim kom tau txais los ntawm pawg thawj coj mus rau lub ncoo thiab tom qab ntawd tsuas yog xaws xaim mus rau lub hauv paus los ntawm txhais tes. Txog qhov hloov tshiab tom ntej, Kuv yuav teeb tsa lub rooj tsavxwm hauv lub thawv yas nrog snaps txhawm rau txuas nws mus rau lub hauv paus kom cov ntiv tes tsis ua haujlwm tsis rub nws sib nrug.

Kauj ruam 8: Code

Code
Code

Yog tias koj tsis tau npaj ib lub nti ua ntej, qhov no yog qhov haujlwm txaus ntshai me ntsis. Nws tsis pab tias cov cuab yeej ua tsis tau zoo thiab feem ntau koj yuav tsum ua haujlwm tib yam ntau zaus. Ob qhov peev txheej zoo tshaj plaws uas kuv tau pom kom nkag siab txog dab tsi tshwm sim yog nplooj ntawv rau USBtinyISP, https://www.ladyada.net/make/usbtinyisp/ thiab chav sib tsoo hauv kev tsim cov khoom ua suab nrov, http:/ /blog.makezine.com/archive/2008/05/noise_toy_crashcourse_in.html Cov no yuav tsum muaj peev xwm ua rau koj pib.

Coob leej neeg nyiam Arduino rau qhov coding no thiab tsis muaj dab tsi tsis zoo nrog kev siv nws, tshwj tsis yog kuv xav tias nws ntxiv ntau qhov tawg mus rau txoj haujlwm yooj yim ib txwm muaj. Tsis tas li, kuv paub C thiab tsis paub Arduino. Tej zaum muaj ib hnub, yog tias muaj sijhawm.:) Code: {{{#include // Siv tus pin qhib SPK /// Typedefs ////////// typedef unsigned char u8; int lub ntsiab (tsis muaj dab tsi) {u8 btnState0; u8 btnState1; u8 btnState2; u8 btnState3; u8 btnState4; u8 btnState5; u8 btnState6; DDRB = (1 << DDB6); // Teeb SPK rau cov zis PORTD = (1 << PD0) | (1 << PD1) | (1 << PD2) | (1 << PD3) | (1 << PD4); // Teeb khawm Siab PORTC = (1 << PC4) | (1 << PC6); TCCR2B = (1 << CS21); // Teeb tsa Timer thaum (1) {btnState0 = ~ PINC & (1 << PC5); btnState1 = ~ PINC & (1 << PC4); btnState2 = ~ PIND & (1 << PD0); btnState3 = ~ PIND & (1 << PD1); btnState4 = ~ PIND & (1 << PD2); btnState5 = ~ PIND & (1 << PD3); btnState6 = ~ PIND & (1 << PD4); yog (btnState0) {yog (TCNT2> = 190) {PORTB ^= (1 << PD6); // Tig SPK Pin TCNT2 = 0; }} yog (btnState1) {yog (TCNT2> = 179) {PORTB ^= (1 << PD6); // Tig SPK Pin TCNT2 = 0; }} yog (btnState2) {yog (TCNT2> = 159) {PORTB ^= (1 << PD6); // Tig SPK Pin TCNT2 = 0; }} yog (btnState3) {yog (TCNT2> = 142) {PORTB ^= (1 << PD6); // Tig SPK Pin TCNT2 = 0; }} yog (btnState4) {yog (TCNT2> = 126) {PORTB ^= (1 << PD6); // Tig SPK Pin TCNT2 = 0; }} yog (btnState5) {yog (TCNT2> = 119) {PORTB ^= (1 << PD6); // Tig SPK Pin TCNT2 = 0; }} yog (btnState6) {yog (TCNT2> = 106) {PORTB ^= (1 << PD6); // Tig SPK Pin TCNT2 = 0; }}}}}}}} Cov suab lus tuaj qhov twg los? Yuav tsum tau ua lej me ntsis. Lub moos timer ntawm atmega 168 khiav ntawm 1MHz. Qhov ntawd nrawm heev rau lub suab yog li peb yuav tsum siv lub prescaler /8. Tom qab ntawd vim tias peb yuav tsum tau tig tus pin tso tawm siab tom qab ntawd qis kom ua 1 lub voj voog, peb yuav tsum faib cov lus teb los ntawm 2 thiaj li tuaj yeem ua lub suab raug. Cov mis zoo li qhov no, Suab tso rau hauv code = (1000000/8)/(Lub hom phiaj zaus*2) Rau A (440) qhov no yuav yog 125000/880 = 142.045 lossis 142 rau peb lub hom phiaj, txij li tus nqi yuav tsum yog tus lej. Lub hom phiaj nquag ntawm cov ntawv tuaj yeem pom tsuas yog nyob txhua qhov chaw hauv online thiab feem ntau zoo ib yam. Kuv tseem xav ntxiv cov ntaub ntawv hais qhia tsis txhob siv pawg Ifs thiab siv PWM los tswj lub ntim thiab suab ntawm tus hais lus zoo dua, tab sis tam sim no, qhov no ua haujlwm.

Pom zoo: