Cov txheej txheem:

Tsim PWM Wave Nrog PIC Microcontroller: 6 Kauj Ruam
Tsim PWM Wave Nrog PIC Microcontroller: 6 Kauj Ruam

Video: Tsim PWM Wave Nrog PIC Microcontroller: 6 Kauj Ruam

Video: Tsim PWM Wave Nrog PIC Microcontroller: 6 Kauj Ruam
Video: Google Colab - Searching for News with Python! 2024, Hlis ntuj nqeg
Anonim
Tsim PWM Wave Nrog PIC Microcontroller
Tsim PWM Wave Nrog PIC Microcontroller
Tsim PWM Wave Nrog PIC Microcontroller
Tsim PWM Wave Nrog PIC Microcontroller
Tsim PWM Wave Nrog PIC Microcontroller
Tsim PWM Wave Nrog PIC Microcontroller
Tsim PWM Wave Nrog PIC Microcontroller
Tsim PWM Wave Nrog PIC Microcontroller

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 Microcontroller
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

TXHUA CCP MODULE
TXHUA CCP MODULE
TXHUA CCP MODULE
TXHUA 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)

Kev teeb tsa Timer2 Module (TMR2 Sau Npe)
Kev teeb tsa 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

Sau Daim Sketch ntawm Koj MPLAB X IDE Txoj Cai Muab Hauv Qab No
Sau Daim 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: