Ngezikhonkwane zedijithali kunye neze-analog, onokuzisebenzisa kwibhodi yakho yeArduino, unokufumana okanye uthumele imiqondiso yombane ukulawula okanye ukufumana idatha kwiiprojekthi zakho zombane. Ukongeza, kukho eminye imiqondiso enomdla kakhulu kolu hlobo lweplate, kwaye ezo zi PWM, Unako ukulinganisa umqondiso we-analog ngaphandle kokuba uyi-analog. Oko kukuthi, zizikhonkwane zedijithali ezinokusebenza ngendlela efanayo (azifani) njengomqondiso we-analog.
Ezi ntlobo zemiqondiso zisebenza kakhulu xa ungafuni kuphela ukusebenzisa uphawu lwedijithali oluphezulu kunye LOKUPHANTSI, oko kukuthi, 1 okanye 0, ON kunye OFF, kodwa ufuna ukuya phambili kwaye uchaze imiqondiso ethe kratya. Umzekelo, unokumodareyitha isantya sefayile ye- Imoto yeDC, Okanye ukukhanya kokukhanya kwesibane, kwi-solenoid, njl.
Inkqubo ye-Analogs yedijithali
Iisekethe zombane zingahlulwa zibe ziintsapho ezimbini ezinkulu okanye iindidi: yedijithali kunye ne-analog. Xa sithetha nge-elektroniki yedijithali, sisebenzisa ubuninzi ngamaxabiso ahlukeneyo, oko kukuthi, inkqubo yokubini emelwe ngumqondiso wombane wombane ophantsi okanye ophezulu ukutolika imeko yezo zinto ziphathwayo. Kwelinye icala, xa kufikwa kwisekethe ye-analog, amanani asetyenziswa ngokuqhubekayo.
Kwiinkqubo zedijithali kunokufumaneka ngokulandelelana ezo zodidi lokudibanisa kunye nezolo hlobo olulandelelanayo. Oko kukuthi, ezangaphambili zezo zikukuphuma kwenkqubo kuxhomekeke kuphela kwimeko yegalelo. Kwelinye icala, ngokulandelelana, izinto zememori zibandakanyiwe, kwaye iziphumo ziya kuxhomekeka kwimeko yangoku yegalelo nakwimo yangaphambili egcinwe.
Kwimeko yee-analogs akukho maqela mabini makhulu okanye okwahlukileyo, kuba apha zizimpawu eziqhubekayo eziya kuhlala zixhomekeke umqondiso Inkqubo yangoku. Umzekelo, kwisandisi-lizwi, isiginali enikezelweyo iya kuxhomekeka kwisandi ofuna ukusivelisa kwakhona. Kuyafana ngemakrofoni, eya kuthi ivelise umqondiso we-analog ngokuxhomekeke kwisandi esisifumanayo. Ngokuqinisekileyo uyibonile kunye nezinye izinto ezininzi esizichazile kule bhlog kwaye zisebenza ngeempawu ze-analog (kwaye ke, ifomula kufuneka yenziwe ukuze amaxabiso kamva abalwe okanye abekwe kwimizobo yeArduino IDE ) ...
Ezi mpawu zenye nenye zenza ezinye zibe nazo izinto eziluncedo nezingalunganga, njengesiqhelo phantse kuyo yonke into. Umzekelo, ezidijithali zihlala zingabizi kakhulu, zikhawuleza, kulula ukuziphuhlisa, ulwazi lungagcinwa ngokulula, zichanekile ngakumbi, zinokucwangciswa, azikho sichengeni seziphumo zengxolo, njl. Kuyinyani ukuba ii-analogs unokusebenza kunye neempawu ezimbaxa.
por ejemplo, Uhlobo lwedijithali Inzwa yesiphumo seHolo inokubona kuphela ubukho okanye ukungabikho kwentsimi yomazibuthe ekufuphi. Endaweni yoko, inzwa yesiphumo seHolo ye-analog inokukwenza oko kwaye ichonge ubungakanani bentsimi yemagneti ebuleweyo kwisimboli ye-analog eyivelisa kwimveliso yayo. Ukwazi indlela yokutolika loo mqondiso wamandla amakhulu okanye angaphantsi kakuhle, ungabazi ngokulula ubungakanani. Uneminye imizekelo ngobuninzi bobukhulu bendalo onokuyilinganisela ngokobungakanani ngenkqubo ye-analog, enje ngeqondo lobushushu, ixesha, uxinzelelo, umgama, isandi, njl.
Analog vs uphawu lwedijithali
Oko kuthethiweyo, a uphawu lwe-analog Iya kuba ngumbane okanye umbane ohluka ngokuhamba kwexesha kwaye ngokuqhubekayo. Ukuba i-graphed, isignali ye-analog iya kuba yinto enye ye-frequency sine wave.
Ngokuphathelele isiginali yedijithali, ngumbane ohluka ngendlela yenyathelo ngokubhekisele kwixesha. Oko kukuthi, ukuba imelwe kwigrafu, iya kuba ngumqondiso wesinyathelo ongafaniyo ngokuqhubekayo, kodwa utshintsho kumanyathelo okanye ukunyuka okungafaniyo.
Kuya kufuneka uyazi ukuba kukho imijikelezo yokuhamba ukusuka kumqondiso we-analog ukuya kwidijithali okanye ngokuchaseneyo. Ezi abaguquleli baziwa ngokuba yi-DAC (iDigital-to-Analog Converter) kunye ne-ADC (Analog-to-Digital Converter). Kwaye bahlala rhoqo kwizixhobo ezininzi esizisebenzisayo namhlanje, ezinje ngeTV, iikhompyuter, njl. Ngazo unokuguqula imiqondiso yedijithali esetyenziswe zezi zixhobo ziye kwinqanaba le-elektroniki ukuze usebenze kunye nezinye iipheripherali okanye izinto ezisebenza kwi-analog.
por ejemplo, Isithethi okanye imakrofoni eneempawu ze-analog ezisebenza nekhadi lesandi, okanye amakhadi emizobo edijithali ayenayo idhiphu ye-RAMDAC edumileyo yamazibuko okujonga i-analog ... eArduino olu hlobo lokuguqula lusetyenziselwa iiprojekthi ezininzi, njengoko siza kubona. ...
Yintoni iPWM?
Nangona kunjalo I-PWM (i-Pulse-Width Modulation), okanye ukuguqulwa kwemodyuli yobubanzi, inesiseko sedijithali, ukumila komqondiso wayo kufana nophawu oluthile "lwesikwere". Ivumela kusetyenziswa ukubetha kwedijithali ukwahluka umqondiso wokulinganisa inkqubo ye-analog njengoko sele ndigqabile ngaphambili. Ngapha koko, ukuba ujonga igama, sele ikunika umkhondo wento eyenzayo, kububanzi beepults digital.
Oku kuyanceda Arduino kuba baninzi oomatshini abazenzekelayo okanye izinto ze-elektroniki onokuthi uzongeze kwiiprojekthi zakho kwaye abanako ukubonelela ngophawu lwangempela lwe-analog, kodwa basebenzisa le PWM ukusebenza. Kananjalo abanakho ukusebenzisa umqondiso we-analog okhethiweyo, Oko kukuthi, oya kumandla ombane ukutsiba ukufana nedijithali. Into abanokuyenza kukusebenzisa imveliso yedijithali -Vcc okanye iVcc yohlobo lwedijithali ukuvelisa olu phawu lukhethekileyo ...
Ke ngoko, i-PWM luhlobo "lwenkohliso" apho iArduino kunye nezinye iinkqubo ezinokuthi zisebenzisane nolu hlobo lweempawu azifani ncam kwaye aziyiyo eyedijithali yesiqhelo. Ukwenza ukuba kwenzeke, bagcina imveliso yedijithali isebenza ixesha elithile okanye icinyiwe, kuxhomekeke kumdla ngawo onke amaxesha. Oku kukude kunento enokuba yikloko yedijithali okanye uphawu lwekhowudi yokubini, eneempundu ezinobubanzi obulinganayo.
Kwiiprojekthi zakho ngeArduino ungalujonga olu hlobo lweempawu ze-PWM apho kugcinwa khona rhoqo ukubangela ukubetha kwexesha, kodwa kodwa ububanzi bale pulses buyahluka. Ngapha koko, ibizwa ngokuba ngumjikelo womsebenzi xa isiginali igcinwe phezulu ngokubhekisele kumjikelo uwonke. Ke ngoko, uMjikelo woMsebenzi unikwe kwi%.
Khumbula ukuba kwi-PWM awusebenzi njengophawu lwe-analog, phakathi kwamaxabiso ombane aliqela kwaye iyatshintsha phakathi kwabo. Kwimeko ye-PWM luphawu lwesikwere kwisitayile sedijithali kwaye elona xabiso liphezulu yiVcc. Umzekelo, ukuba usebenza ngombane we-3V, unganika ii-pulses ze-3V okanye ze-0V, kodwa hayi i-1V okanye naliphi na elinye ixabiso eliphakathi njengoko kunokwenzeka kwi-analog yokwenyani. Into eya kwahluka kwimeko apho bububanzi bempilo, esinokugcina i-30% kwelo xabiso liphezulu le-Vcc, okanye i-60% ukuyinika amandla angaphezulu, njl.
Kodwa lumka, kuba ukuba isixhobo sixhasa umda we-Vcc kwaye sigqithisiwe nge-PWM sinokonakala. Ke kuyakuhlala kuyimfuneko ukuhlonipha amaxabiso edatha enikezwe ngabavelisi. Kwakhona, kwezinye izixhobo ezinje ngee-DC motors, Ukubuyisela, ii-electromagnets, njl., ukurhoxiswa kwevolthi emva koXinzelelo loMsebenzi kunokuthetha ukuba imithwalo enomdla inokubangela umonakalo. Kungenxa yoko le nto ifayile ye- ukhuseleko ngexesha elifanelekileyo.
PWM kwiArduino
Ngoku ukuba uyazi ukuba isebenza njani, masibone imeko ethile ye-PWM kwilizwe leArduino ...
I-PWM: ikhonkco kwiArduino
Kwiibhodi zeArduino unokufumana izikhonkwane ezininzi ezisebenzisa i-PWM yehardware. Ungabachonga kwi-PCB uqobo kuba bane uphawu ~ (intloko encinci) Kunye nepini yokubala. Inokwenziwa nakwisoftware kwikhowudi ye-Arduino, kodwa loo nto ingayifaka umthwalo omkhulu kwi-microcontroller ngomsebenzi, into engenangqondo xa inokwenziwa ngokwendalo nangesixhobo sehardware ...
- Arduino UNO, Mini kunye neNano-Uneziphumo ezi-6 ezisi-8 ze-PWM kwizikhonkwane 3, 5, 6, 9, 10, no-11, eziya kuthi zibe nayo phambi kwenani.
- UArduino Mega-Kweli bhodi yeArduino inamandla uneziphumo ezili-15 ezisibhozo ze-PWM. Bakwizikhonkwane ezi-8 ukuya kwezi-2 nangama-13 ukuya kwangama-44.
- Arduino Ngenxa: kule meko kukho iziphumo ezili-13 ezisibhozo ze-PWM. Zikwiikhonkwane ezi-8 ukuya kwezi-2, kunye nezinye iziphumo ezibini ezenziwe yi-DAC ngesisombululo esili-13.
Xa uthetha ngesisombululo se-8-bit okanye i-12-bit, njl., Kolu hlobo lweziphumo ze-PWM, ubhekisa kwigumbi lokuqhuba onalo. Kunye Iibhithi ezi-8 zinamanqanaba angama-256 phakathi kwawo onokwahluka, kwaye iibits ezili-12 ziye kumaqondo angama-4096.
Ulawulo lwexesha
Kulawulo lwe-PWM lwezixhobo, Arduino uya kusebenzisa izibali maxesha ngayo. Ixesha ngalinye langoku linokuhambisa iziphumo ezi-2 okanye ezi-3 ze-PWM. Irejista yokuthelekisa imveliso nganye igcwalisa le nkqubo ukuze xa ixesha lifikelela kwixabiso lerejista, urhulumente okanye ixabiso lesiphumo sitshintshiwe ukumisa loo mijikelo yomsebenzi. Nangona zimbini iziphumo ezilawulwa liXesha elifanayo, zombini zinokuba nee-Duty Cycle ezahlukeneyo, nangona zisabelana ngokufanayo.
Kwimeko yeXesha elinxulumene nepini nganye ye-PWM, iya kwahluka kuxhomekeke kuhlobo lwebhodi yeArduino ukuba unayo:
- Arduino UNO, Mini kunye neNano:
- Ixesha 0-5 kunye 6
- Ixesha 1-9 kunye 10
- Ixesha 2-3 kunye 11
- UArduino Mega:
- Ixesha 0-4 kunye 13
- Ixesha 1-11 kunye 12
- Ixesha 2-9 kunye 10
- Ixesha 3 - 2, 3 kunye 5
- Ixesha 4 - 6, 7 kunye 8
- Ixesha 5 - 44, 45 kunye 46
Irejista emiselweyo iya kwahlula ixesha ngenani elipheleleyo kwaye iTimer yenza okuseleyo ukulawula isiphumo ngasinye esihambelana noko sePWM. Ukuguqula ixabiso lobhaliso kunokutshintsha imeko. Inkqubo ye- amaza Ziya kwahluka ngokuxhomekeka kwiTimer kunye nembasa.
- Arduino UNO, Mini kunye neNano:
- I-Timer0: ivumela ukubekwa phambili kwe-1, 8, 64, 256 kunye ne-1024. Ukuhamba rhoqo kungama-62.5 Khz.
- Isibali-xesha1: kucwangciswe kwangaphambili ngo-1, 8, 64, 256 kunye no-1024.Nemvamisa ye-31.25 Khz.
- I-Timer2: ilingana neTimer1, kuphela kukuba yongeza ukubekwa phambili kwama-32 kunye ne-128 ukongeza kwezi zangaphambili.
- UArduino Mega:
- Timer0, 1, 2: iyafana nale ingasentla.
- Isikhathi, 3, 4, kunye no-5: nobuninzi be-31.25 Khz kunye nokubekwa kwangaphambili kwe-1, 8, 64, 256 kunye ne-1024.
Ukungahambelani kunye neengxabano
Ixesha enxulunyaniswa neziphumo ayisiyiyo eyomsebenzi kuphela, isetyenziswa nangabanye. Ke ngoko, ukuba zisetyenziswa ngomnye umsebenzi, kuya kufuneka ukhethe phakathi kwenye okanye enye, awungekhe uzisebenzise zombini ngaxeshanye. Umzekelo, ezi zezinye zezinto ezingangqinelaniyo onokuzifumana kwiiprojekthi zakho:
- Ithala leencwadi leServo: Xa usebenzisa ii-servo motors, amaXesha asetyenzisiweyo ngokuqinileyo, anokukhokelela kungxabano. Ngokukodwa sebenzisa i-Timer1 ye-UNO, iNano kunye neMini, Oko kukuthi, awungekhe usebenzise izikhonkwane ze-9 kunye ne-10 ngelixa usebenzisa umzobo onelo thala leencwadi. Kwi Mega kuyakuxhomekeka kwinani le servos ...
- SPI: Ukuba unxibelelwano lwe-SPI lusetyenziswa kwibhodi yeArduino, ipini ye-11 isetyenziselwa umsebenzi we-MOSI. Kungenxa yoko le nto ipini ye-PWM ingenakusetyenziswa.
- ilizwi: lo msebenzi usebenzisa iTimer2 ukusebenza. Ke ukuba iyasetyenziswa, wenza izikhonkwane ezi-3 kunye nezili-11 (okanye ezisi-9 nese-10 zeMega) zililize.
Uvavanyo lwezandla kunye noArduino
Ukuba ufuna ukubona kwisiza ukuba iPWM isebenza njani kwiArduino, eyona nto unokuyenza kukudibanisa umlinganiso okhokelayo voltmeter okanye multimeter (ekusebenzeni ukulinganisa i-voltage) phakathi kwepini ye-PWM oyikhethileyo kunye nepini yomhlaba okanye i-GND yebhodi yeArduino. Ngale ndlela, kwiscreen sesixhobo sokulinganisa uya kuba nakho ukubona ukuba ombane utshintsha njani kunye nemveliso eyimbulelo yedijithali kobu buqhetseba be-PWM.
Ungayitshintsha i-voltmeter / multimeter nge-LED ukubona ukuba ukukhanya kwesibane kuyahluka njani, kunye nemoto ye-DC, okanye ngayo nayiphi na into oyifunayo. Ndiyenze lula kumzobo ngeFritzing nge-LED ngaphandle kokungaphezulu, kodwa uyazi ukuba inokubonisa neengcebiso zemultimeter ...
Ukuba usebenzisa i-LED, khumbula ukuxhathisa kwi-cathode kunye ne-GND.
ukuba ikhowudi yemvelaphi Ukulawula i-microcontroller yebhodi ye-Arduino ukwenza yonke into isebenze, kuya kufuneka ufake oku kwi-Arduino IDE (kule meko ndisebenzise i-PWM pin 6 ye Arduino UNO):
const int analogOutPin = 6; byte outputValue = 0; void setup() { Serial.begin(9600); pinMode(ledPIN , OUTPUT); bitSet(DDRB, 5); // LED o voltímetro bitSet(PCICR, PCIE0); bitSet(PCMSK0, PCINT3); } void loop() { if (Serial.available()>0) { if(outputValue >= '0' && outputValue <= '9') { outputValue = Serial.read(); // Leemos la opción outputValue -= '0'; // Restamos '0' para convertir a un número outputValue *= 25; // Multiplicamos x25 para pasar a una escala 0 a 250 analogWrite(ledPIN , outputValue); } } } ISR(PCINT0_vect) { if(bitRead(PINB, 3)) { bitSet(PORTB, 5); // LED on } else { bitClear(PORTB, 5); // LED off } }
Molweni ngemini elungileyo. Okokuqala ndifuna ukukubulela ngexesha elizinikele kule ngcaciso entsha.
Ndingathanda ukukwenzela umbuzo. Ndizama ukuqhuba ikhowudi kwiproteus 8 yesiphelo seArguino Mega. Ndidibanisa i-voltmeter ukuya ku-pin 6, i-Proteus iqhagamshelwe kwizibuko le-serial, kodwa andazi ukuba ndenze njani okanye nditshintshe njani ukuze i-voltages ezahlukeneyo zikhuphe. Kwafuneka ndenze uhlengahlengiso oluncinci kwikhowudi ukuyenza. Ndiyabulela kakhulu ngoncedo lwakho