PWM: kutulutsa zikhomo za analogi ndi bolodi lanu la Arduino

Zizindikiro za PWM

Ndi zikhomo za digito ndi analogi, zomwe mungagwiritse ntchito pa bolodi lanu la Arduino, mutha kulandira kapena kutumiza zizindikiritso zamagetsi kuti muziwongolera kapena kupeza zambiri kuchokera kuzinthu zamagetsi. Kuphatikiza apo, pali zikwangwani zina zosangalatsa kwambiri pamtundu wamtunduwu, ndipo awa ndiwo PWM, zomwe zingatsanzire chizindikiro cha analog popanda kukhala analogi. Ndiye kuti, ndi zikhomo zadijito zomwe zimatha kuchita chimodzimodzi (osati chimodzimodzi) ngati chizindikiro cha analog.

Zizindikiro zamtunduwu ndizothandiza kwambiri ngati simukufuna kugwiritsa ntchito zizindikilo za digito za HIGH ndi PANSI, ndiye kuti, 1 kapena 0, ON ndi OFF, koma mukufuna kupitilira ndikufotokozera Zizindikiro zina zovuta. Mwachitsanzo, ndizotheka kusintha liwiro la a DC mota, kapena kuunika kwamphamvu kwa kuwala, kogwiritsa ntchito solenoid, ndi zina zambiri.

Analog vs dongosolo la digito

Chizindikiro cha analog ndi digito

Ma circuits amagetsi amatha kugawidwa m'mabanja akulu akulu kapena magulu: digito ndi analogi. Tikamayankhula zamagetsi zamagetsi, tikugwiritsa ntchito zochulukirapo ndi ma discrete, ndiye kuti, njira yoyambira yomwe imayimilidwa ndi ma siginolo amagetsi otsika kapena okwera kutanthauzira mabatani omwe agwiridwa. Kumbali inayi, zikafika pagawo la analog, zochuluka zomwe zimakhala ndizopitilira ntchito zikugwiritsidwa ntchito.

Mukamagwiritsa ntchito digito mutha kupeza nawonso za mitundu yophatikiza ndi zamtundu wotsatira. Ndiye kuti, akale ndi omwe kutulutsa kwamachitidwe kumadalira momwe zinthu zilili. Kumbali inayi, motsatizana, zinthu zokumbukira zimaphatikizidwa, ndipo zotulutsa zake zimadalira momwe zinthu ziliri pano ndi zomwe zidasungidwa kale.

Pankhani ya ma analogs palibe magulu akulu awiriwa kapena mitundu ingapo, popeza pano ndi zizindikiritso zopitilira muyeso zomwe zimadalira nthawi zonse chizindikirocho dongosolo lamakono. Mwachitsanzo, pachokuzira mawu, chizindikiritso chomwe chimaperekedwa chimadalira phokoso lomwe mukufuna kubereka. Zomwezo ndi maikolofoni, yomwe ipange chizindikiro cha analog kutengera phokoso lomwe ikulandila. Zachidziwikire kuti mwaziwonanso ndi masensa ena ambiri omwe tafotokoza mu blog iyi komanso omwe ali ndi zizindikilo za analog (ndipo chifukwa chake, chilinganizo chimayenera kupangidwa kuti pambuyo pake zikhalidwezo zitha kuwerengedwa kapena kukhazikitsidwa pazithunzi za Arduino IDE ) ...

Makhalidwe amenewa ndi ena amapangitsa ena kukhala nawo zabwino ndi zovuta, monga mwachizolowezi pafupifupi chilichonse. Mwachitsanzo, ma digito amakhala otsika mtengo, othamanga, osavuta kupanga, zidziwitso zimatha kusungidwa mosavuta, zimakhala zolondola kwambiri, zimatha kusinthidwa, sizikhala pachiwopsezo cha phokoso, ndi zina zambiri. Komanso ndizowona kuti ndi ma analogs mutha kugwiritsa ntchito zizindikiritso zovuta kwambiri.

Por ejemplo, chojambulira chamtundu wa Hall effect sensor chimatha kuzindikira kupezeka kapena kupezeka kwa mphamvu yamaginito yapafupi. M'malo mwake, chojambulira cha analog Hall athari chimatha kuchita izi ndikuwonetsanso kuchuluka kwa maginito chifukwa cha chizindikiro cha analog chomwe chimatulutsa. Kudziwa kutanthauzira chizindikirocho cha mphamvu yayikulu kapena yocheperako, mutha kudziwa kukula kwake. Zitsanzo zina muli nazo pamlingo waukulu wachilengedwe zomwe mutha kuziyeza mochulukirapo ndi mawonekedwe a analog, monga kutentha, nthawi, kuthamanga, mtunda, mawu, ndi zina zambiri.

Chizindikiro cha analog ndi digito

Izi zikunenedwa, a chizindikiro cha analogi Kudzakhala magetsi kapena magetsi omwe amasiyanasiyana ndi nthawi komanso mosalekeza. Ngati graphed, chizindikiritso cha analogi chimakhala funde limodzi lama frequency sine.

Kwenikweni chizindikiro cha digito, ndi voliyumu yomwe imasiyanasiyana mosiyanasiyana poyang'ana nthawi. Ndiye kuti, ngati ikuyimiridwa pa graph, chidzakhala chizindikiro chosasinthasintha mosiyanasiyana, koma chimasintha masitepe kapena zowonjezera.

Muyenera kudziwa kuti pali ma circuits oti achoke pa chizindikiro cha analog kupita ku digito kapena mosemphanitsa. Izi osintha amadziwika kuti DAC (Digital-to-Analog Converter) ndi ADC (Analog-to-Digital Converter). Ndipo ndizofala pazida zambiri zomwe timagwiritsa ntchito masiku ano, monga TV, makompyuta, ndi zina zambiri. Ndi iwo mutha kusintha ma digito omwe amagwiritsidwa ntchito ndi zida izi kukhala zamagetsi kuti mugwire ntchito ndi zotumphukira kapena ziwalo zina zomwe zimagwira ntchito mu analog.

Por ejemplo, wokamba kapena maikolofoni okhala ndi zizindikilo za analog zomwe zimagwira ndi khadi yomveka, kapena makhadi ojambula pa digito omwe anali ndi chipangizo chotchuka cha RAMDAC chamalo oyang'anira ma analoji ... Ku Arduino otembenuza amtunduwu amagwiritsidwanso ntchito pazinthu zingapo, monga tionere ...

PWM ndi chiyani?

zojambulajambula

Ngakhale PWM (Kugunda-Ufupi Kusinthasintha), kapena zimachitika m'lifupi kusinthasintha, ili ndi digito, mawonekedwe amawu ake amafanana ndi chizindikiro cha "square" cha analog. Zimaloleza pogwiritsa ntchito ma digito kuti asinthe chizindikirocho kuti atsanzire dongosolo la analog monga ndanenera kale kale. M'malo mwake, ngati mungayang'ane dzinalo, limakupatsani chidziwitso cha zomwe limachita, kudzera pazithunzithunzi zama digito.

Izi ndizopindulitsa kwa Arduino popeza pali makina ambiri kapena zida zamagetsi zomwe mungaonjezere pazinthu zanu ndi izo sangathe kupereka chizindikiro chenicheni cha analog, koma amagwiritsa ntchito PWM kuyendetsa. Komanso sangagwiritse ntchito chizindikiritso cha analogi, ndiye kuti, chomwe chimapita kudumpha kwamagetsi kuti chikhale ngati digito. Zomwe angathe kuchita ndikugwiritsa ntchito digito yotulutsa -Vcc kapena Vcc yamtundu wa digito kuti apange chizindikiro chapaderachi ...

Chifukwa chake, PWM ndi mtundu wa "chinyengo" chomwe Arduino ndi machitidwe ena amatha kulumikizana ndi zizindikilo zamtunduwu zomwe sizofanana kwenikweni kapenanso si digito wamba. Kuti izi zitheke, amasungabe zojambulidwa za digito kwakanthawi kapenanso kuchotsera, kutengera chidwi chomwe chimakhalapo nthawi zonse. Izi zili kutali kwambiri ndi zomwe zingakhale nthawi yadijito kapena chikhomo cha binary, chomwe chimakhala ndi kukula kofanana.

M'mapulojekiti anu ndi Arduino mutha kuwunika ma PWM amtunduwu momwe kuwongolera kosalekeza komwe kumachitika nthawi, koma m'lifupi mwake. M'malo mwake, amatchedwa Duty Cycle pomwe chizindikiritso chimasungidwa pamwamba pokhudzana ndi kuzungulira kwake. Chifukwa chake, Duty Cycle imaperekedwa mu%.

Kumbukirani kuti mu PWM simukugwira ntchito ngati chizindikiro cha analog, pakati pamagetsi angapo ndipo amasintha pakati pawo. Pankhani ya PWM ndi siginecha yayitali pamachitidwe a digito ndipo amene mtengo wake wapamwamba ndi Vcc. Mwachitsanzo, ngati mukugwira ntchito ndi magetsi a 3V, mutha kupereka 3V kapena 0V nyemba, koma osati 1V kapena mtengo wina uliwonse wapakatikati monga momwe zingachitikire mu analog yeniyeni. Zomwe zingasinthe pakadali pano ndikutambalala kwa pulse, komwe titha kusunga 30% pamtengo wapamwamba wa Vcc, kapena 60% kuti tiupatse mphamvu zambiri, ndi zina zambiri.

Koma samalani, chifukwa ngati chida chikuthandizira malire a Vcc ndipo chikadutsa ndi PWM, chitha kuwonongeka. Chifukwa chake nthawi zonse zimakhala zofunikira kulemekeza zofunikira zamasamba omwe amapangidwa ndi opanga. Komanso, pazinthu zina monga ma DC motors, yolandirana, ma electromagnets, ndi zina zambiri, kuchotsedwa kwamagetsi pambuyo pa Duty Cycle kungatanthauze kuti katundu wolowerera akhoza kuwononga. Ichi ndichifukwa chake chitetezo panthawi yake.

PWM pa Arduino

Basi ya Arduino I2C

Tsopano popeza mukudziwa momwe zimagwirira ntchito, tiyeni tiwone momwe PWM ilili mdziko la Arduino ...

PWM: pini pa Arduino

Pa matabwa a Arduino mutha kupeza zikhomo zingapo zomwe zimagwiritsa ntchito PWM ya Hardware. Mutha kuzizindikira pa PCB palokha chifukwa ali ndi chizindikiro ~ (mutu wawung'ono) pamodzi ndi pini yowerengera. Zingathenso kuchitidwa ndi pulogalamu ya Arduino code, koma izi zimachepetsa ma microcontroller pantchito, china chake chosamveka ngati chingachitike mwachilengedwe komanso ndi zida za ...

  • Arduino UNO, Mini ndi Nano- Muli ndi zotuluka za 6-bit PWM pazikhomo 8, 3, 5, 6, 9, ndi 10, zomwe zidzakhale ndi ~ patsogolo pa manambala.
  • Mega Arduino- Pa bolodi lamphamvu kwambiri la Arduino muli ndi zotulukapo za 15 8-bit PWM. Ali pazikhomo 2 mpaka 13 ndi 44 mpaka 46.
  • Arduino Chifukwa: pamenepa pali zotsatira za 13 8-bit PWM. Ali pazikhomo 2 mpaka 13, kuphatikiza zotuluka zina ziwiri za analog zomwe zakonzedwa ndi DAC ndimasankho a 12-bit.

Mukamayankhula za 8-bit kapena 12-bit resolution, ndi zina zambiri, pazotulutsa zamtunduwu za PWM, mukutanthauza chipinda chamayendedwe omwe muli nawo. Ndi Mabatani 8 ali ndi milingo 256 Pakati pa zomwe mungasinthe, ndipo ma bits 12 amakwera mpaka 4096.

Kuwongolera ndi Timers

Pazowongolera zida za PWM, Arduino idzagwiritsa ntchito nthawi chifukwa chake. Nthawi iliyonse ilipo itha kutulutsa zotsatira za 2 kapena 3 za PWM. Rejista yofananizira chilichonse chomwe chimakwaniritsidwa chimakwaniritsa dongosolo ili kuti nthawi ikafika pamtengo, muyezo kapena phindu la zomwe zimatulutsidwa zimasinthidwa kuyimitsa ma Duty Cycles. Ngakhale pali zotuluka ziwiri zoyendetsedwa ndi Timer yomweyo, zonsezi zimatha kukhala ndi ma Duty Cycle osiyanasiyana, ngakhale amagawana pafupipafupi chimodzimodzi.

Pankhani ya Ma Timers omwe amagwirizanitsidwa ndi pini iliyonse ya PWM, zimasiyana kutengera mtundu wa Arduino board kuti muli:

  • Arduino UNO, Mini ndi Nano:
    • Nthawi: 0 - 5 ndi 6
    • Nthawi: 1 - 9 ndi 10
    • Nthawi: 2 - 3 ndi 11
  • Mega Arduino:
    • Nthawi: 0 - 4 ndi 13
    • Nthawi: 1 - 11 ndi 12
    • Nthawi: 2 - 9 ndi 10
    • Nthawi 3 - 2, 3 ndi 5
    • Nthawi 4 - 6, 7 ndi 8
    • Nthawi 5 - 44, 45 ndi 46

Rejista yoyikidwiratu igawika nthawi ndi wochulukirapo ndipo Timer imachita zonse kuwongolera zotuluka zonse za PWM. Kusintha kuchuluka kwa registry kumatha kusintha mafupipafupi. Pulogalamu ya mafunde Adzakhalanso osiyana kutengera Nthawi ndi mbale:

  • Arduino UNO, Mini ndi Nano:
    • Timer0: imalola kuyika 1, 8, 64, 256 ndi 1024. Pafupipafupi ndi 62.5 Khz.
    • Timer1: yokhala ndi 1 8, 64, 256, 1024 ndi 31.25. Pafupipafupi XNUMX Khz.
    • Timer2: yofanana ndi Timer1, imangowonjezera kuwerengera kwa 32 ndi 128 kuphatikiza koyambirira.
  • Mega Arduino:
    • Timer0, 1, 2: chimodzimodzi pamwambapa.
    • Timer3, 4, ndi 5: pafupipafupi 31.25 Khz ndikuwonetsera 1, 8, 64, 256 ndi 1024.

Kusagwirizana komanso mikangano

Nthawi Zokhudzana ndi zotuluka sizongogwira ntchitoyi kokha, imagwiritsidwanso ntchito ndi ena. Chifukwa chake, ngati akugwiritsidwa ntchito ndi ntchito ina, muyenera kusankha pakati pa imzake, simungagwiritse ntchito zonse nthawi imodzi. Mwachitsanzo, izi ndi zina mwazovuta zomwe mungapeze mumapulojekiti anu:

  • Laibulale ya Servo: Mukamagwiritsa ntchito ma servo motors, amagwiritsa ntchito kwambiri Timers, chifukwa chake zimatha kuyambitsa mikangano. Makamaka gwiritsani ntchito Timer1 ya UNO, Nano ndi Mini, ndiye kuti, simungagwiritse ntchito zikhomo 9 ndi 10 mukamagwiritsa ntchito zojambula ndi laibulale ija. Ku Mega zimatengera kuchuluka kwa ma servos ...
  • SPI: Ngati kulumikizana kwa SPI kumagwiritsidwa ntchito pa bolodi la Arduino, pini 11 ikugwiritsidwa ntchito pa ntchito ya MOSI. Ichi ndichifukwa chake pini ya PWM singagwiritsidwe ntchito.
  • kamvekedwe: ntchitoyi imagwiritsa ntchito Timer2 kugwira ntchito. Chifukwa chake ngati agwiritsidwa ntchito, mukupanga zikhomo 3 ndi 11 (kapena 9 ndi 10 za Mega) zopanda ntchito.

Kuyesa pamanja ndi Arduino

Arduino PWM yoyenda ndi LED

Ngati mukufuna kuwona patsamba momwe PWM imagwirira ntchito pa Arduino, chinthu chabwino kwambiri chomwe mungachite ndikulumikiza njira zoyeserera za voltmeter kapena multimeter (ikugwira ntchito kuyeza magetsi) pakati pa pini ya PWM yomwe mwasankha kugwiritsa ntchito ndi pini yapansi kapena GND ya board ya Arduino. Mwanjira imeneyi, pazenera la chida choyezera mudzatha kuwona momwe magetsi akusinthira ndi zotulutsa zomwe zili digito chifukwa cha chinyengo ichi cha PWM.

Mutha kusintha voltmeter / multimeter ndi LED kuti muwone momwe kuwala kukusiyana, ndi DC mota, kapena china chilichonse chomwe mukufuna. Ndachipanga kukhala chosavuta pachithunzipa ndi Fritzing wokhala ndi LED yopanda zambiri, koma dziwani kuti itha kuyimiranso maupangiri a multimeter ...

Ngati mumagwiritsa ntchito LED, kumbukirani kukana kwa cathode ndi GND.

Para nambala yachinsinsi Kuti muwongolere microcontroller wa Arduino kuti zonse zizigwira ntchito, muyenera kuyika izi mu Arduino IDE (pano ndagwiritsa ntchito PWM pin 6 ya 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  
   } 
} 
Ndikukulangizani kuti muzisewera ndi malingaliro ndikuwona zotsatira zake pa kuwala kapena voltmeter. Pulogalamuyi imatha kulandira zofunikira kuyambira 0 mpaka 9 kuti muwone momwe zonse zimasiyanasiyana. Kuti mumve zambiri, ndikukulangizani maphunziro a arduino kuti tili nawo kutsitsa kwaulere ...

Zomwe zili m'nkhaniyi zikutsatira mfundo zathu za malamulo okonzekera. Kuti mufotokoze cholakwika dinani Apa.

Ndemanga, siyani yanu

Siyani ndemanga yanu

Anu email sati lofalitsidwa. Amafuna minda amalembedwa ndi *

*

*

  1. Wotsogolera pazosankhazi: Miguel Ángel Gatón
  2. Cholinga cha deta: Control SPAM, kasamalidwe ka ndemanga.
  3. Kukhazikitsa: Kuvomereza kwanu
  4. Kulumikizana kwa zomwe zafotokozedwazo: Zomwezo siziziwululidwa kwa anthu ena kupatula pakukakamizidwa mwalamulo.
  5. Zosunga: Zosungidwa ndi Occentus Networks (EU)
  6. Ufulu: Nthawi iliyonse mutha kuchepetsa, kuchira ndikuchotsa zidziwitso zanu.

  1.   Jose anati

    Moni tsiku labwino. Choyamba ndikufuna kukuthokozani chifukwa chodzipereka kuti mufotokozere zatsopano.
    Ndikufuna ndikupangire funso. Ndikuyesera kuyendetsa kachidindo pa proteus 8 emulator ya Arguino Mega. Ndikulumikiza voltmeter kuti ndikhomere 6, Proteus amalumikizidwa ndi doko lofananira, koma sindikudziwa momwe ndingasinthire kapena kusiyanasiyana kuti ma voltages osiyanasiyana atuluke. Ndinayenera kupanga zosintha zazing'ono pamalamulo kuti ipangidwe. Zikomo kwambiri chifukwa chothandizidwa