Cov txheej txheem:

Arduino thiab TLC5940 PWM LED Tsav IC: 7 Kauj Ruam
Arduino thiab TLC5940 PWM LED Tsav IC: 7 Kauj Ruam

Video: Arduino thiab TLC5940 PWM LED Tsav IC: 7 Kauj Ruam

Video: Arduino thiab TLC5940 PWM LED Tsav IC: 7 Kauj Ruam
Video: Уроки Ардуино. Управление нагрузкой в сети переменного тока 2024, Kaum ib hlis
Anonim
Arduino thiab TLC5940 PWM LED Tsav Tsheb IC
Arduino thiab TLC5940 PWM LED Tsav Tsheb IC

Hauv kab lus no peb yuav tshuaj xyuas Texas Instruments TLC5940 16-channel LED tsav IC. Peb qhov laj thawj ua qhov no yog ua kom pom lwm qhov, txoj hauv kev yooj yim ntawm kev tsav ntau lub LEDs - thiab tseem ua haujlwm. Ua ntej tshaj, ntawm no yog qee qhov piv txwv ntawm TLC5940. Koj tuaj yeem xaj TLC5940 los ntawm PMD Txoj Kev nrog xa dawb thoob ntiaj teb.

TLC5940 muaj nyob hauv DIP version, thiab tseem nto-mount. Nws yog qhov yooj yim, tso cai rau koj kho qhov ci ntawm kaum rau tus kheej LEDs ntawm PWM (mem tes-dav kev hloov pauv)-thiab koj tseem tuaj yeem daisy-saw ntau dua ib qho TLC5940 los tswj ntau ntxiv.

Hauv qhov kev qhia no peb yuav piav qhia yuav ua li cas tswj ib lossis ntau TLC5940 ICs nrog LEDs thiab tseem saib xyuas kev tswj hwm servos. Txij ntawm no mus, thov rub daim ntawv theej ntawm TLC5940 (.pdf) raws li koj yuav xa mus rau nws los ntawm cov txheej txheem no. Ntxiv mus, thov rub tawm thiab teeb tsa TLC5940 Arduino lub tsev qiv ntawv los ntawm Alex Leone uas tuaj yeem pom ntawm no. Yog tias koj tsis paub yuav teeb lub tsev qiv ntawv li cas, nyem qhov no.

Kauj Ruam 1: Tsim kom muaj TLC5940 Circuit Circuit Demonstration

Tsim kom muaj TLC5940 Circuit Court Demonstration Circuit
Tsim kom muaj TLC5940 Circuit Court Demonstration Circuit

Cov hauv qab no yog qhov tsawg kawg yuav tsum tau tswj kaum rau LEDs los ntawm koj Arduino lossis sib xws. Koj tuaj yeem siv nws los sim nrog ntau txoj haujlwm thiab tau txais lub tswv yim ntawm qhov ua tau. Koj yuav xav tau:

  • Arduino Uno lossis pawg thawj coj saib tau
  • 16 qhov ib txwm muaj, niaj hnub LEDs uas tuaj yeem muaj lub zog tam sim no mus txog 20 mA
  • a 2 kΩ resistor (muab lossis coj 10%)
  • 0.1uF ceramic thiab 4.7uF electrolytic capacitor

Nco tseg ntawm LED kev taw qhia-thiab nco ntsoov TLC5940 yog ib qho-anode LED tsav tsheb-yog li txhua qhov LED anodes txuas nrog ua ke thiab tom qab ntawd mus rau 5V.

Kauj ruam 2:

Rau qhov tshwj xeeb hauv Circuit no, koj yuav tsis xav tau lub zog 5V sab nraud - txawm li cas los xij koj yuav xav tau ib qho yav tom ntej. Lub hom phiaj ntawm tus tiv thaiv yog tswj hwm tus nqi tam sim no uas tuaj yeem ntws los ntawm LEDs. Tus nqi tiv thaiv uas xav tau yog xam nrog cov qauv hauv qab no:

R = 39.06 / Imax qhov twg R (hauv Ohms) yog tus tiv thaiv tus nqi thiab Imax (hauv Amps) yog qhov siab tshaj plaws tam sim no koj xav ntws los ntawm LEDs.

Piv txwv li, yog tias koj muaj LEDs nrog 20 mA rau tom ntej tam sim no - qhov ntsuas qhov ntsuas yuav yog: R = 39.06 / 0.02 = 1803 Ohms. Thaum koj muaj lub rooj sib txoos sib dhos - qhib Arduino IDE thiab xa cov duab kos BasicUse.pde uas yog nyob hauv cov piv txwv nplaub tshev rau TLC5940 lub tsev qiv ntawv.

Koj yuav tsum tau nthuav tawm nrog cov zis zoo ib yam li tau qhia hauv video.

Kauj Ruam 3: Tswj TLC5940

Tam sim no qhov kev ua haujlwm hauv Circuit Court, peb yuav tswj hwm TLC5940 li cas? Ua ntej, qhov yuav tsum tau ua haujlwm - suav nrog lub tsev qiv ntawv thaum pib kos duab nrog:

#suav nrog "Tlc5940.h"

thiab tom qab ntawd pib lub tsev qiv ntawv los ntawm kev tso cov hauv qab no rau hauv qhov tsis muaj teeb tsa ():

Tlc.init (x);

x yog ib qho kev xaiv tsis tau - yog tias koj xav teeb tsa txhua txoj hauv kev kom muaj qhov ci ci sai li sai tau thaum kos duab pib, koj tuaj yeem tso tus nqi nruab nrab ntawm 0 thiab 4095 rau x hauv Tlc.init () muaj nuj nqi.

Tam sim no tig lub channel/LED qhib lossis tua. Txhua cov channel tau suav los ntawm 0 txog 15, thiab txhua txoj kev ci ntsa iab tuaj yeem hloov kho ntawm 0 thiab 4095. Qhov no yog ob ntu txheej txheem… Ua ntej-siv ib lossis ntau qhov ntawm cov haujlwm hauv qab no los teeb tsa cov kev xav tau thiab qhov ci ntsa iab (PWM) qib):

Tlc.set (channel, ci ntsa iab);

Piv txwv li, yog tias koj xav kom muaj thawj peb txoj hauv kev ntawm qhov ci ntsa iab, siv:

Tlc.set (0, 4095); Tlc.set (1, 4095); Tlc.set (2, 4095);

Qhov thib ob yog siv cov hauv qab no los hloov kho TLC5940 nrog cov lus qhia xav tau los ntawm ntu ib:

Tlc.update ();

Yog tias koj xav tua txhua txoj hauv kev ib zaug, tsuas yog siv:

Tlc.clear ();

Kauj ruam 4:

Koj tsis tas yuav hu TLC.update () tom qab ua haujlwm meej. Cov hauv qab no yog qhov piv txwv nrawm uas teeb tsa qhov ci ci/PWM qhov tseem ceeb ntawm txhua txoj hauv kev mus rau qib sib txawv:

#include "Tlc5940.h" tsis muaj teeb meem teeb tsa () {Tlc.init (0); // initialise TLC5940 thiab teeb tsa txhua txoj hauv kev tawm}

void lub voj ()

{rau (int i = 0; i <16; i ++) {Tlc.set (i, 1023); } Tlc.update (); ncua (1000); rau (int i = 0; i <16; i ++) {Tlc.set (i, 2046); } Tlc.update (); ncua (1000); rau (int i = 0; i <16; i ++) {Tlc.set (i, 3069); } Tlc.update (); ncua (1000); rau (int i = 0; i <16; i ++) {Tlc.set (i, 4095); } Tlc.update (); ncua (1000); }

Lub peev xwm los tswj tus kheej qhov ci rau txhua tus channel/LED kuj tseem tuaj yeem muaj txiaj ntsig thaum tswj RGB LEDs - tom qab ntawd koj tuaj yeem xaiv cov xim xav tau ntawm qib sib txawv ci ci rau txhua ntu. Kev ua yeeb yam tau qhia hauv video.

Kauj Ruam 5: Siv Ob lossis Ntau TLC5940s

Koj tuaj yeem daisy-saw ntau ob peb TLC5940s ua ke los tswj ntau LEDs. Ua ntej - xaim txuas ntxiv TLC5940 mus rau Arduino raws li qhia hauv kev qhia ua haujlwm - tshwj tsis yog txuas SOUT tus pin (17) ntawm thawj TLC5940 mus rau SIN tus pin (26) ntawm TLC5940 thib ob - raws li cov ntaub ntawv taug kev los ntawm Arduino, thawj TLC5940 mus rau qhov thib ob thiab ntxiv rau. Tom qab ntawd rov ua cov txheej txheem yog tias koj muaj thib peb, thiab lwm yam. Tsis txhob hnov qab tus resisotr uas teeb tsa tam sim no!

Tom ntej no, qhib cov ntaub ntawv tlc_config.h nyob hauv TLC5940 lub tsev qiv ntawv tais ceev tseg. Hloov tus nqi ntawm NUM_TLCS rau tus naj npawb ntawm TLC5940s koj tau txuas nrog ua ke, tom qab ntawd khaws cov ntawv thiab tseem tshem tawm cov ntawv Tlc5940.o kuj tseem nyob hauv tib daim nplaub tshev. Thaum kawg rov pib dua IDE. Tom qab ntawd koj tuaj yeem xa mus rau cov channel ntawm qhov thib ob thiab txuas ntxiv TLC5940 ua ntu zus los ntawm thawj qhov. Ntawd yog, thawj yog 0 ~ 15, qhov thib ob yog 16 ~ 29, thiab ntxiv rau.

Kauj Ruam 6: Tswj Servos Nrog TLC5940

Raws li TLC5940 tsim PWM (mem tes-dav tes taws los piav) tso tawm, nws yog qhov zoo rau kev tsav servos ib yam. Ib yam li LEDs - koj tuaj yeem tswj tau txog kaum rau ib zaug. Qhov zoo tshaj plaws los tsim cov kab laug sab-zoo li neeg hlau, lub moos coj txawv txawv lossis ua suab nrov.

Thaum xaiv koj lub servo, xyuas kom meej tias nws tsis kos ntau dua 120 mA thaum ua haujlwm (qhov siab tshaj tam sim no rau ib channel) thiab tseem mloog "Tswj tam sim no thiab cua sov" ntu kawg ntawm qhov kev qhia no. Thiab siv lub zog sab nraud nrog servos, tsis txhob cia siab rau Arduino's 5V kab.

Txhawm rau txuas tus pabcuam yog yooj yim - GND kab txuas rau GND, 5V (lossis muab cov khoom siv hluav taws xob) txuas rau koj 5v (lossis lwm yam khoom siv tsim nyog) thiab servo tswj tus pin txuas rau ib qho ntawm TLC5940 qhov kev tso tawm. Thaum kawg - thiab qhov no tseem ceeb - txuas 2.2kΩ resistor ntawm TLC5940 tus pin tso tawm (s) raug siv thiab 5V. Tswj kev pabcuam tsis txawv li LED. Koj xav tau thawj ob kab thaum pib kos duab:

#include "Tlc5940.h" #include "tlc_servos.h"

tom qab ntawd hauv qhov tsis muaj teeb tsa teeb tsa ():

tlc_initServos ();

Tom ntej no, siv cov haujlwm hauv qab no los xaiv qhov servo (channel) los ua haujlwm thiab lub kaum sab xis uas xav tau (angle):

tlc_setServo (channel, lub kaum ntse ntse);

Ib yam li cov LEDs koj tuaj yeem ua ob peb qhov no ua ke, thiab tom qab ntawd ua cov lus txib nrog:

Tlc.update ();

Yog li cia saib txhua yam hauv kev nqis tes ua. Cov piv txwv hauv qab no kos duab sweeps plaub servos hla 90 degrees:

#include "Tlc5940.h" #include "tlc_servos.h"

void teeb tsa ()

{tlc_initServos (); // Nco tseg: qhov no yuav tso PWM qhov sib txawv mus rau 50Hz. }

void lub voj ()

{rau (int angle = 0; angle = 0; angle--) {tlc_setServo (0, angle); tlc_setServo (1, lub); tlc_setServo (2, lub kaum ntse ntse); tlc_setServo (3, lub ntsej muag); Tlc.update (); ncua (5); }}

Cov vis dis aus qhia qhov kos duab no hauv kev ua nrog plaub servos.

Yog tias koj lub servos tsis tig mus rau lub kaum sab xis raug - piv txwv li koj thov 180 degrees thiab lawv tsuas yog tig mus rau 90 lossis nyob ntawd, yuav tsum tau ua haujlwm ntxiv me ntsis.

Koj yuav tsum qhib cov ntaub ntawv tlc_servos.h nyob hauv TLC5940 Arduino lub tsev qiv ntawv tais ceev tseg thiab sim nrog qhov txiaj ntsig rau SERVO_MIN_WIDTH thiab SERVO_MAX_WIDTH. Piv txwv hloov SERVO_MIN_WIDTH los ntawm 200 txog 203 thiab SERVO_MAX_WIDTH los ntawm 400 txog 560.

Kauj Ruam 7: Tswj Tam Sim No thiab Tshav Kub

Raws li tau hais ua ntej, TLC5940 tuaj yeem ua haujlwm siab tshaj 120 mA rau ib channel. Tom qab qee qhov kev sim koj yuav pom tias TLC5940 tau sov - thiab qhov ntawd zoo.

Nco ntsoov tias muaj qhov txwv ntau tshaj plaws rau lub zog uas tuaj yeem yaj tawm ua ntej yuav rhuav tshem ib feem. Yog tias koj tsuas yog siv cov vaj zaub ntau yam LEDs lossis cov servos me me, lub zog yuav tsis muaj teeb meem. Txawm li cas los xij yog tias koj tab tom npaj siv TLC5940 mus rau qhov siab tshaj plaws - thov tshuaj xyuas cov ntawv sau los ntawm cov kws sau ntawv hauv tsev qiv ntawv.

Xaus

Ib zaug ntxiv koj nyob ntawm koj txoj hauv kev los tswj hwm qhov muaj txiaj ntsig zoo nrog koj Arduino. Tam sim no nrog qee qhov kev xav koj tuaj yeem tsim txhua hom kev pom pom lossis muaj kev lom zem nrog ntau yam kev pabcuam.

Cov ntawv tshaj tawm no tau coj tuaj rau koj los ntawm pmdway.com - uas muaj TLC5940 cov khoom lag luam nrog rau txhua yam rau cov neeg tsim khoom thiab cov khoom siv hluav taws xob, nrog kev xa khoom dawb thoob ntiaj teb.

Pom zoo: