I-PWM: ukulingisa izikhonkwane ze-analog nebhodi lakho le-Arduino

Izimpawu ze-PWM

Ngezikhonkwane zedijithali neze-analog, ongazisebenzisa ebhodini lakho le-Arduino, ungathola noma uthumele amasiginali kagesi ukulawula noma ukuthola idatha kumaphrojekthi wakho we-elekthronikhi. Ngaphezu kwalokho, kunezinye izibonakaliso ezithakazelisa kakhulu kulolu hlobo lwepuleti, futhi lezo yizo PWM, lokho kungalingisa isignali ye-analog ngaphandle kokuba i-analog. Lokho wukuthi, yizikhonkwane zedijithali ezingasebenza ngendlela efanayo (hhayi efanayo) njengesiginali ye-analog.

Lezi zinhlobo zamasignali ziyasebenza uma ungafuni ukusebenzisa kuphela amasiginali we-digital HIGH kanye ne-LOW, okungukuthi, 1 noma 0, ON and OFF, kepha ufuna ukuqhubeka nokuchaza amasiginali athe xaxa. Isibonelo, ungalinganisa ijubane le- Imoto ye-DC, noma ukukhanya kwesibani, kwe-solenoid, njll.

Uhlelo lwe-Analog vs digital

I-analog vs isignali yedijithali

Amasekethe kagesi angahlukaniswa abe yimindeni emibili emikhulu noma ngezigaba: yedijithali ne-analog. Lapho sikhuluma nge-elekthronikhi yedijithali, sisebenzisa inani elinamanani ahlukile, okusho ukuthi, uhlelo olunambambili olumelwe yizimpawu zikagesi zamandla kagesi aphansi noma aphezulu ukutolika isimo salezo zingcezu eziphethwe. Ngakolunye uhlangothi, uma kukhulunywa ngesifunda se-analog, inani elinamanani aqhubekayo liyasetshenziswa.

Ngaphakathi kwezinhlelo zedijithali kungatholakala ngokulandelana lezo zohlobo oluhlanganayo nalezo zohlobo ezilandelanayo. Lokho wukuthi, okwedlule yilezo lapho ukukhishwa kohlelo kuncike kuphela esimweni sokufakwayo. Ngakolunye uhlangothi, kokulandelanayo, izinto zememori zifakiwe, futhi umphumela uzoncika esimweni samanje sokufakwayo nesimo sangaphambilini esigciniwe.

Endabeni yama-analogs awekho la maqembu amabili amakhulu noma okuhlukile, ngoba lapha kuyizimpawu eziqhubekayo eziyohlala zincike kuzo isiginali uhlelo lwamanje. Isibonelo, ngelawudispikha, isignali enikezwe yona incike emsindweni ofuna ukuwukhiqiza kabusha. Okufanayo ngombhobho, ozokhiqiza isignali ye-analog kuye ngomsindo owutholayo. Impela uyibonile nezinye izinzwa eziningi esizichazile kule bhulogi futhi ezisebenza ngamasiginali we-analog (ngakho-ke, ifomula bekufanele lenziwe ukuze kamuva amanani azobalwa noma abekwe kumidwebo ye-Arduino IDE ) ...

Lezi zici zokunye nokwenza ezinye zinazo izinzuzo nezinkinga, njengokujwayelekile cishe kuyo yonke into. Isibonelo, ezidijithali ngokuvamile zishibhile, ziyashesha, kulula ukuzithuthukisa, ulwazi lungagcinwa kalula, lunokunemba okukhulu, lungahlelwa, alusengozini yemiphumela yomsindo, njll. Kodwa futhi kuyiqiniso ukuthi ngama-analogs ungasebenza ngamasignali anzima kakhulu.

Por ejemplo, inzwa yohlobo lwedijithali ye-Hall effect sensor ingathola kuphela ubukhona noma ukungabikho kwamandla kazibuthe aseduze. Esikhundleni salokho, inzwa ye-analog Hall effect ingakwenza lokho futhi ibuye inqume ubukhulu bensimu kazibuthe eshiwo ngenxa yesiginali ye-analog ukuthi ikhiqiza lapho ikhiqiza. Ukwazi ukuthi usitolika kanjani leso siginali samandla kagesi amakhulu noma amancane kahle, ungabazi kalula lobo bukhulu. Unezinye izibonelo ngobuningi bobukhulu bemvelo ongazilinganisa ngobuningi ngohlelo lwe-analog, njengokushisa, isikhathi, ingcindezi, ibanga, umsindo, njll.

I-analog vs isignali yedijithali

Lokho kushiwo, a isignali ye-analog Kuzoba ngamandla kagesi noma kagesi ahluka ngokuya kwesikhathi nangokuqhubekayo. Uma i-graphed, isignali ye-analog ingaba igagasi elilodwa le-sine wave.

Ngokuqondene ne isignali yedijithali, amandla kagesi ahluka ngendlela yesinyathelo maqondana nesikhathi. Okusho ukuthi, uma imelwe kugrafu, kuzoba yisiginali yesinyathelo engafani ngokuqhubekayo, kepha eshintsha ezinyathelweni noma ekukhuphukeni okuhlukile.

Kufanele wazi ukuthi kunemijikelezo okufanele isuswe kusiginali ye-analog iye kwidijithali noma okuphambene nalokho. Lezi abaguquli aziwa njenge-DAC (Digital-to-Analog Converter) ne-ADC (Analog-to-Digital Converter). Futhi zivame kakhulu kumadivayisi amaningi esiwasebenzisa namuhla, njenge-TV, amakhompyutha, njll. Ngazo ungaguqula amasiginali edijithali asetshenziswe yile mishini aye ezingeni le-elektroniki ukuze asebenze namanye amapheripherali noma izingxenye ezisebenza ku-analog.

Por ejemplo, isipikha noma imakrofoni enezimpawu ze-analog ezisebenza nekhadi lomsindo, noma amakhadi emidwebo edijithali abene-chip ye-RAMDAC edumile yamachweba wokuqapha i-analog ... E-Arduino lolu hlobo lokuguqula lusetshenziselwa amaphrojekthi amaningi, njengoba sizobona ...

Yini i-PWM?

graphic duty umjikelezo

Noma kunjalo I-PWM (Pulse-Width Modulation), noma ukushintshashintsha kobubanzi be-pulse, inesisekelo sedijithali, ukuma kwesiginali yayo kufana nesiginali ye-analog "eyisikwele" ngandlela thile. Ivumela ngokusebenzisa ukushaya kwedijithali ukushintsha isignali ukulingisa uhlelo lwe-analog njengoba ngike ngaphawula ngaphambilini. Eqinisweni, uma ubheka igama, selivele likunikeza izinkomba zalokho elikwenzayo, ngokusebenzisa ububanzi bezinhlamvu zedijithali.

Lokhu kuzuzisa i- I-Arduino ngoba kunemishini eminingi ezenzekelayo noma izinto zikagesi ongangeza kumaphrojekthi akho nokuthi azikwazi ukunikela ngesiginali yeqiniso ye-analog, kepha basebenzisa le PWM ukusebenza. Futhi abakwazi ukusebenzisa isignali ye-analog ekhethiwe, okungukuthi, eya kuma-voltage jumps ukuze afane ne-digital. Abangakwenza ukusebenzisa ukukhishwa kwedijithali -Vcc noma iVcc yohlobo lwedijithali ukukhiqiza lesi siginali esikhethekile ...

Ngakho-ke, i-PWM iwuhlobo "lwenkohliso" i-Arduino nezinye izinhlelo ezingasebenzisana ngayo nalolu hlobo lwesiginali akuzona i-analogue impela futhi akuyona eyedijithali ejwayelekile. Ukwenza kwenzeke, bagcina ukukhishwa kwedijithali kusebenza isikhathi noma ukuvalwa okuthile, kuya ngentshisekelo ngaso sonke isikhathi. Lokhu kukude kunalokho okungaba iwashi ledijithali noma isignali yekhodi kanambambili, ama-pulses ayo anobubanzi obufanayo.

Kumaphrojekthi akho nge-Arduino ungabheka lolu hlobo lwezimpawu ze-PWM lapho kugcinwa khona imvamisa eqhubekayo yokushaya ngamandla kokuhamba kwesikhathi, kepha ububanzi bala mapulse buyehlukahluka. Eqinisweni, ibizwa nge-Duty Cycle lapho isiginali igcinwa phezulu maqondana nengqikithi yomjikelezo. Ngakho-ke, i-Duty Cycle inikezwa ngo-%.

Khumbula ukuthi ku-PWM awusebenzi njengakwisiginali ye-analog, phakathi kwamavelu amaningi wamandla futhi iyashintshashintsha phakathi kwawo. Endabeni ye-PWM kuyisiginali esikwele ngesitayela sedijithali futhi inani laso eliphakeme lingu-Vcc. Isibonelo, uma usebenza ngamandla ka-3V, unganikeza ama-pulses ama-3V noma ama-0V, kodwa hhayi i-1V noma elinye inani eliphakathi njengoba kungenzeka ku-analog yangempela. Okungahluka kuleso simo ububanzi be-pulse, esingagcina ama-30% kulelo nani eliphakeme le-Vcc, noma i-60% ukuyinika amandla amaningi, njll.

Kepha qaphela, ngoba uma idivayisi isekela umkhawulo we-Vcc futhi yeqiwa nge-PWM ingalimala. Ngakho-ke kuzohlala kudingeka njalo ukuhlonipha amanani wamasheya anikezwe abakhiqizi. Futhi, kwamanye amadivayisi afana nama-DC motors, udlulisela, ama-electromagnets, njll., ukuhoxiswa kwamandla ngemuva kwe-Duty Cycle kungasho ukuthi imithwalo engenayo ingadala umonakalo. Kungakho ifayili le- ukuvikelwa ngesikhathi esifanele.

I-PWM ku-Arduino

Ibhasi le-Arduino I2C

Manje njengoba uyazi ukuthi isebenza kanjani, ake sibheke icala elithile le-PWM emhlabeni we-Arduino ...

I-PWM: pinout ku-Arduino

Emabhodini e-Arduino ungathola izikhonkwane eziningana ezisebenzisa i-Hardware PWM. Ungazikhomba ku-PCB uqobo ngoba zine- uphawu ~ (ikhanda elincane) kanye nezikhonkwane. Kungenziwa futhi ngesoftware kwikhodi ye-Arduino, kepha lokho kuzolayisha ngokweqile i-microcontroller ngomsebenzi, into engenangqondo lapho ingenziwa ngokwendabuko nange-hardware ...

  • Arduino UNO, UMini noNano- Unemiphumela engu-6 8-bit PWM kuzikhonkwane 3, 5, 6, 9, 10, no-11, okuzoba naleyo ~ phambi kwenombolo.
  • I-Arduino Mega- Kuleli bhodi le-Arduino elinamandla kakhulu unemiphumela engu-15 8-bit PWM. Zikhona kuzikhonkwane 2 kuya ku-13 kanye no-44 kuya ku-46.
  • Arduino Ngenxa: kulokhu kunemiphumela engu-13 8-bit PWM. Zisezikhonkweni 2 kuya ku-13, kanye neminye imiphumela emibili ye-analog eyenziwe yi-DAC ngokulungiswa okungama-12-bit.

Uma ukhuluma ngesixazululo se-8-bit noma esingu-12-bit, njll., Kulolu hlobo lwemiphumela ye-PWM, ubhekisa egumbini lokuqondisa onalo. Nge Izingcezu eziyi-8 zinamazinga angama-256 Phakathi kwalokho ungahluka, futhi izingcezu eziyi-12 zikhuphukela emazingeni angama-4096.

Lawula Ngezikhathi

Ukulawulwa kwe-PWM yehadiwe, i-Arduino izosebenzisa izibali sikhathi ngakho. Isikhathi ngasinye samanje singakhipha imiphumela engu-2 noma engu-3 ye-PWM. Irejista yokuqhathanisa kokukhipha ngakunye igcwalisa lolu hlelo ukuze kuthi lapho isikhathi sifinyelela kunani lerejista, isimo noma inani lomkhiqizo liguqulwe ukumisa leyo mijikelezo yomsebenzi. Yize kunemiphumela emibili elawulwa yi-Timer efanayo, womabili angaba nama-Duty Cycles ahlukile, yize abelana ngemvamisa efanayo.

Endabeni yezibali sikhathi ezihambisana nephini ngalinye le-PWM, lizohluka kuye ngohlobo lwebhodi le-Arduino onakho:

  • Arduino UNO, UMini noNano:
    • Isikhathi: 0 - 5 no-6
    • Isikhathi: 1 - 9 no-10
    • Isikhathi: 2 - 3 no-11
  • I-Arduino Mega:
    • Isikhathi: 0 - 4 no-13
    • Isikhathi: 1 - 11 no-12
    • Isikhathi: 2 - 9 no-10
    • Isikhathi 3 - 2, 3 no-5
    • Isikhathi 4 - 6, 7 no-8
    • Isikhathi 5 - 44, 45 no-46

Irejista ebekiwe izohlukanisa isikhathi ngenamba bese i-Timer yenza konke ukulawula umphumela ngamunye we-PWM ohambisanayo. Ukuguqula inani lokubhalisa kungashintsha imvamisa. I- imvamisa Futhi zizohluka ngokuya ngesibali sikhathi nepuleti:

  • Arduino UNO, UMini noNano:
    • I-Timer0: ivumela ukubekwa kuka-1, 8, 64, 256 no-1024. Imvamisa ingu-62.5 Khz.
    • Isikhathi1: kusethwe kusengaphambili okungu-1, 8, 64, 256 no-1024. Ngokuvama kwama-31.25 Khz.
    • I-Timer2: ilingana ne-Timer1, kuphela ingeza ukucaciswa kwama-32 no-128 ngokungeziwe kokungaphambilini.
  • I-Arduino Mega:
    • Isikhathi0, 1, 2: kuyafana nangaphezulu.
    • Isikhathi 3, 4, no-5: nobuningi be-31.25 Khz futhi kubekiwe u-1, 8, 64, 256 no-1024.

Ukungalingani kanye nezingxabano

Isikhathi okuhlobene nemiphumela akuyona eyalowo msebenzi kuphela, isetshenziswa nabanye. Ngakho-ke, uma zisetshenziswa ngomunye umsebenzi, kufanele ukhethe phakathi kokunye noma okunye, ngeke ukwazi ukuzisebenzisa zombili ngasikhathi sinye. Isibonelo, lokhu okunye kokungalingani ongakuthola kumaphrojekthi akho:

  • Umtapo wezincwadi weServo: Uma usebenzisa ama-servo motors, isebenzisa kakhulu ama-Timers, ngakho-ke kungadala izingxabano. Ngokukhethekile sebenzisa i-Timer1 ye-UNO, iNano neMini, okungukuthi, awukwazi ukusebenzisa izikhonkwane 9 no-10 ngenkathi usebenzisa umdwebo nalowo mtapo wezincwadi. EMega kuzoya ngenani lama-servos ...
  • SPI: Uma ukuxhumana kwe-SPI kusetshenziswa ebhodini le-Arduino, i-pin 11 isetshenziselwa umsebenzi we-MOSI. Kungakho le phini le-PWM lingenakusetshenziswa.
  • Tone: lo msebenzi usebenzisa i-Timer2 ukusebenza. Ngakho-ke uma isetshenziswa, unikeza izikhonkwane ezi-3 no-11 (noma eziyi-9 no-10 zeMega) ezingasizi ngalutho.

Ukuhlolwa kwezandla no-Arduino

I-Arduino PWM ihlelile nge-LED

Uma ufuna ukubona ku-situ ukuthi i-PWM isebenza kanjani e-Arduino, into engcono kakhulu ongayenza ukuxhuma umkhondo wokulinganisa i-voltmeter noma i-multimeter (isebenza ukukala amandla kagesi) phakathi kwephini le-PWM okhethe ukulisebenzisa kanye nephini lomhlabathi noma i-GND yebhodi le-Arduino. Ngale ndlela, esikrinini sedivayisi yokulinganisa uzokwazi ukubona ukuthi i-voltage ishintsha kanjani ngokukhipha okuyi-digital ngenxa yalesi senzo se-PWM.

Ungashintsha i-voltmeter / multimeter nge-LED ukuze ubone ukuthi ukukhanya kokukhanya kwehluka kanjani, ngemoto ye-DC, noma nganoma iyiphi enye into oyifunayo. Ngiwenze lula kumdwebo nge-Fritzing ene-LED ngaphandle kokuningi, kepha uyazi ukuthi futhi ingamela amathiphu we-multimeter ...

Uma usebenzisa i-LED, khumbula ukumelana ku-cathode naku-GND.

para ikhodi yomthombo Ukulawula i-Arduino board microcontroller ukwenza yonke into isebenze, kufanele ufake lokhu ku-Arduino IDE (kulokhu ngisebenzise iPWM pin 6 of 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  
   } 
} 
Ngikweluleka ukuthi udlale ngamanani ubone imiphumela ekukhanyeni noma ku-voltmeter. Uhlelo lungamukela amanani kusuka ku-0 kuye ku-9 ukuze ubone ukuthi konke kuhluka kanjani. Ngeminye imininingwane, ngikweluleka inkambo ye-arduino ukuthi sinokulanda mahhala ...

Okuqukethwe yi-athikili kunamathela ezimisweni zethu ze izimiso zokuhlelela. Ukubika iphutha chofoza lapha.

Amazwana, shiya okwakho

Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe.

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.

  1.   Jose kusho

    Sawubona usuku oluhle. Okokuqala ngifuna ukukubonga ngesikhathi esinikezelwe kule ncazelo entsha sha.
    Ngingathanda ukukwenzela umbuzo. Ngizama ukusebenzisa ikhodi kusiprosesi se-proteus 8 se-Arguino Mega. Ngixhuma i-voltmeter ukuze ngiphine u-6, uProteus uxhunywe ethekwini le-serial, kepha angazi ukuthi kuzokwehluka kanjani noma yini ukuze kukhishwe amanani ahlukile. Bekufanele ngenze ushintsho oluncane kukhodi ukuyenza ihlanganiswe. Ngiyabonga kakhulu ngosizo lwakho

Isivivinyo sesiNgisiHlola isiCatalanimibuzo yeSpanishi