Cov txheej txheem:
- Kauj Ruam 1: Xaiv Microcontroller
- Kauj Ruam 2: Hloov kho CCP MODULE
- Kauj Ruam 3: Kho Timer2 Module (TMR2 Sau Npe)
- Kauj Ruam 4: Kho PR2 (Timer2 Lub Sijhawm Teev Npe)
- Kauj Ruam 5: Kho CCPR1l Module
- Kauj Ruam 6: Sau Daim Duab Sketch ntawm Koj MPLAB X IDE Txoj Cai Muab Hauv Qab No
Video: Tsim PWM Wave Nrog PIC Microcontroller: 6 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:26
PWM yog dab tsi?
PWM STANDS FOR PULSE WIDTH MODULATION yog txheej txheem uas qhov dav ntawm cov mem tes sib txawv.
Txhawm rau nkag siab lub tswv yim no kom meej meej txiav txim siab lub moos mem tes lossis ib qho xwm txheej yoj yoj nws muaj 50% lub luag haujlwm voj voog uas txhais tau tias Ton thiab Toff lub sijhawm zoo ib yam, Tag nrho lub sijhawm uas lub teeb liab tau siab thiab lub sijhawm uas lub teeb liab tau qis yog hu ua tag nrho lub sijhawm.
Rau cov duab pom saum toj no nthwv dej muaj lub luag haujlwm ntawm 50%
Duty cycle = (ON time / Total Time)*100
Nyob rau lub sijhawm - sijhawm uas lub teeb liab tau siab
Lub sijhawm tawm - lub sijhawm tus yeeb ncuab uas lub teeb liab qis Tag nrho lub sijhawm -Lub sijhawm tag nrho ntawm lub plawv dhia (ob qho tib si ON thiab OFF lub sijhawm)
Kauj Ruam 1: Xaiv Microcontroller
Xaiv qhov tsim nyog microcontroller rau txoj haujlwm no yog qhov tseem ceeb ntawm txoj haujlwm PWM cov cim tuaj yeem tsim tawm hauv microcontrollers nrog PWM raws (CCP sau npe). Rau qhov haujlwm no kuv npaj yuav ua nrog pic16f877. koj tuaj yeem rub tawm cov ntawv txuas txuas hauv qab no
PIC16F877a cov ntaub ntawv nyem rau ntawm no
CCP module yog lub luag haujlwm los tsim PWM teeb liab. CCP1 thiab CCP2 tau sib npaug nrog PORTC. PORTC yog 8-ntsis dav dav ob qhov chaw nres nkoj. Cov ntaub ntawv coj mus rau qhov kev tso npe yog TRISC. Teeb TRISC ntsis (= 1) yuav ua tus coj PORTC tus pin raws li kev nkag. Kev tshem tawm TRISC ntsis (= 0) yuav ua rau PORTC sib thooj tus pin tso tawm.
TSI = 0; // Kev tshem tawm qhov me me no yuav ua rau PORTC ua qhov tso tawm
Kauj Ruam 2: Hloov kho CCP MODULE
CCP - CAPTURE/COMPARE/PWM MODULES
Txhua qhov Capture/Compare/PWM (CCP) module muaj 16-ntsis rau npe uas tuaj yeem ua haujlwm raws li:
• 16-ntsis Capture sau npe
• 16-ntsis Sib piv sau npe
• PWM Master/Slave Duty Cycle register
Kho CCP1CON sau npe rau PWM hom
Sau npe piav qhia
CCPxCON Daim ntawv sau npe no yog siv los teeb tsa CCP tus qauv rau Kev Ntsuas/Sib Piv/PWM kev ua haujlwm.
CCPRxL Cov npe no tuav 8-Msb khoom ntawm PWM, qis dua 2-khoom yuav yog ib feem ntawm CCPxCON sau npe.
TMR2 Kev ua haujlwm pub dawb uas yuav muab piv nrog CCPR1L thiab PR2 rau kev tsim cov PWM tso tawm.
Tam sim no kuv yuav siv binary los sawv cev rau cov khoom me me los teeb tsa CCP1CON sau npe.
xa cov duab saum toj no.
CCP1CON = 0b00001111;
Koj tseem tuaj yeem ua hom hex
CCP1CON = 0x0F; // teeb tsa CCP1CON sau npe rau PWM hom
Kauj Ruam 3: Kho Timer2 Module (TMR2 Sau Npe)
Timer2 yog 8-ntsis timer nrog prescaler thiab postscaler. Nws tuaj yeem siv ua PWM lub sijhawm pib rau PWM hom ntawm CCP module (s). TMR2 sau npe tuaj yeem nyeem thiab sau tau thiab raug tshem tawm ntawm ib lub cuab yeej Pib dua.
T2CON sau npe tau qhia
Qhov prescale thiab postscale yuav kho qhov tso zis zaus ntawm qhov tsim PWM yoj.
Zaus = zaus zaus/(4*prescaler*(PR2-TMR2)*Postscaler*suav)
Qhov twg Tout = 1/zaus
T2CON = 0b00000100;
Qhov no yuav tsim 2.5 KHz @ 1Mhz lossis 100KHz @ 4MHz siv lead ua (siv tau muaj kev txwv rau qhov PWM zaus xa mus rau cov ntawv tshwj xeeb kom paub meej ntxiv)
hex sawv cev
T2CON = 0x04; // pab T2CON yam tsis muaj Prescaler thiab teeb tsa tom qab
Kauj Ruam 4: Kho PR2 (Timer2 Lub Sijhawm Teev Npe)
Timer2 module muaj 8-ntsis lub sijhawm sau npe, PR2. Timer2 nce ntxiv los ntawm 00h txog thaum nws sib xws nrog PR2 thiab tom qab ntawd rov pib dua rau 00h ntawm lub voj voog nce ntxiv tom ntej. PR2 yog nyeem tau thiab sau tau. PR2 sau npe tau pib rau FFh thaum rov pib dua.
Kev teeb tsa qhov tsim nyog rau PR2 yuav tso cai siv los hloov lub luag haujlwm ntawm kev tsim PWM yoj
PR2 = 100; // Teev Lub Sijhawm Cycle rau 100 rau kev hloov pauv lub luag haujlwm ntawm 0-100
Rau qhov yooj yim Kuv tab tom siv PR2 = 100 los ntawm kev ua CCPR1L = 80; 80% kev ua haujlwm tuaj yeem ua tiav.
Kauj Ruam 5: Kho CCPR1l Module
Txij li PR2 = 100 CCPR1l tuaj yeem teeb tsa nyob txhua qhov chaw ntawm 0-100 kom tau txais lub luag haujlwm uas xav tau.
Kauj Ruam 6: Sau Daim Duab Sketch ntawm Koj MPLAB X IDE Txoj Cai Muab Hauv Qab No
#suav nrog
void ncua (int a) // muaj nuj nqi los tsim kev ncua {
rau (int kuv = 0; kuv <a; kuv ++)
{
rau (int j = 0; j <144; j ++);
}
}
void lub ntsiab ()
{TSI = 0; // Kev tshem tawm qhov me me no yuav ua rau PORTC ua qhov tso tawm.
CCP1CON = 0x0F; // teeb tsa CCP1CON sau npe rau PWM hom
T2CON = 0x04; // pab T2CON yam tsis muaj Prescaler thiab teeb tsa tom qab.
PR2 = 100; // Teeb tsa Lub Sij Hawm Cycle rau 100 rau kev hloov pauv lub luag haujlwm ntawm 0-100
thaum (1) {
CCPR1L = 75; // tsim tawm 75% kev ua haujlwm ncua sijhawm ncua (1);
}
}
Kuv kuj tau hloov kho me ntsis rau cov cai kom qhov zaus ntawm qhov tsim PWM yoj
Qhov no yog tus lej yog simulated hauv proteus thiab qhov tso tawm PWM yoj tau qhia hauv qab no Txhawm rau upload qhov no ntawm koj cov phiaj xwm txhim kho pic siv #suav nrog cov teeb tsa tsim nyog.
Ua tsaug
Pom zoo:
Tsev Automation Kauj Ruam ntawm Kauj Ruam Siv Wemos D1 Mini Nrog PCB Tsim: 4 Kauj Ruam
Tsev Automation Kauj Ruam Ib Leeg Siv Wemos D1 Mini Nrog PCB Tsim: Tsev Automation Kauj Ruam los ntawm Kauj Ruam siv Wemos D1 Mini nrog PCB Tsim cov tub ntxhais kawm ntawv qib siab. Tom qab ntawd ib tus ntawm peb cov tswv cuab tuaj
Yuav Tsim Li Cas 2d Tus Cwj Pwm Nrog Tus Cwj Pwm Tus Cwj Pwm hauv Unreal Engine 4 Siv Cov Ntawv Pom Zoo rau PC: 11 Kauj Ruam
Yuav Ua Li Cas Tsim Tus 2d Tus Cwj Pwm Nrog Tus Tswj Tus Cwj Pwm hauv Unreal Engine 4 Siv Cov Ntawv Pom Zoo rau PC: Yuav ua li cas los tsim 2d Tus Cwj Pwm nrog tus cwj pwm tswj hauv Unreal cav 4 siv cov ntawv pom rau PC Nyob zoo, Kuv yog Jordan Steltz. Kuv tau tsim kho cov vis dis aus ua si txij li thaum kuv muaj 15. Phau ntawv qhia no yuav qhia koj li cas los tsim tus yam ntxwv yooj yim nrog rau hauv
AVR Microcontroller Fuse Cov Khoom Kho. Tsim thiab Tshaj Tawm hauv Flash Nco ntawm Microcontroller LED Blinking Program: 5 Kauj Ruam
AVR Microcontroller Fuse Cov Khoom Kho. Tsim thiab Tshaj Tawm hauv Flash Nco ntawm Microcontroller LED Blinking Program: Hauv qhov no peb yuav tsim cov phiaj xwm yooj yim hauv C code thiab hlawv nws mus rau hauv lub cim xeeb ntawm microcontroller. Peb yuav sau peb tus kheej txoj haujlwm thiab suav sau cov ntawv hex, siv Atmel Studio ua kev txhim kho kev sib koom ua ke. Peb yuav teeb tsa fuse ob
Skateboard Nrog PIC Microcontroller thiab LEDs: 8 Kauj Ruam (nrog Duab)
Skateboard Nrog PIC Microcontroller thiab LEDs: Koj tau txais dab tsi thaum Tus Kws Tshaj Lij Hluav Taws Xob tsim Skateboard los ntawm kos rau hnub nyoog 13 xyoos Christmas tam sim no? Koj tau txais lub skateboard nrog yim LEDs dawb (teeb taub hau), yim LEDs liab (tom qab) txhua qhov tswj ntawm PIC microntroller! Thiab kuv mig
LED Zaj sawv - RGB LED PWM Tus Tswj Xyuas Kev Tsim Kho - Yooj Yim Tsim: 15 Kauj Ruam
LED Zaj sawv - RGB LED PWM Tus Kws Tswj Kev Tsim Kho - Yooj Yim Tsim: Ib kauj ruam -ib -kauj ruam, yooj yim ua raws cov lus qhia ntawm lub tsev ntawm LED Zaj sawv RGB LED PWM Tus Tswj. Tsuas yog qhov tsawg kawg nkaus ntawm qhov yuav tsum tau ua, nrog rau PIC tus txheej txheem, thiab koj tuaj yeem tsim ib qho ntawm qhov zoo tshaj plaws LED tswj muaj. Cov s