Jump to content
ELFORUM - Forumul Electronistilor
Sign in to follow this  
MihaiStoica

PIC18F45K80

Recommended Posts

Stimati colegiIncerc sa construiesc un montaj cu 4 canale PWM independente, in sensul de factor de umplere. Mi-a picat cu tronc PIC18F45K80 care se lauda cu 4 canaleProgramelul de test, urmand a fi extins este:#include #include "config.h"void main(void) { PR2 = 249; // PWM Period = [(PR2) + 1] x 4 x TOSC x (TMR2 Prescale Value) CCPR2L = 25; // PWM Duty Cycle = (CCPR2L:CCP2CON<5:4>) x TOSC x (TMR2 Prescale Value) TRISCbits.TRISC2 = 0; TMR2ON = 1; CCP2M3 = 1; CCP2M2 = 1; TRISB = 0xFF; for(;;){ if(PORTBbits.RB0 == 0) CCPR2L = 125; }}PROBLEMA: Mareste factorul de umplere chiar daca pe RB0 am 1 logic (o rezistenta de 10k la VDD). Am pus un delay. Pe osciloscop se vede cum porneste cu factor de umplere mic (CCPR2L = 25) si imediat sare la factor de umplere mare (CCPR2L = 125)Lucrez cu MPLAB X si compilator HI-TECH PICC18. La fel se intampla daca il compilez cu XC8Multumesc anticipat

Share this post


Link to post
Share on other sites

cred ca trebuie sa-l faci digital portul B:ANSELB=0x00;

Share this post


Link to post
Share on other sites

Incerc si asta, desi in mod default ANCON1 ar trebui sa aiba 0 pe ANSEL11<10:8>, adica digitalIntr-adevar, daca are 1, il configureaza ca analogic si orice intrare este citita ca fiind 0 (asa scrie in datasheet)Orice idee este binevenitaMultumesc

Share this post


Link to post
Share on other sites

Pana la urma i-am dat de capIntai configurez portul ca fiind iesire (TRISx= 0x00), ii pun 1 pe iesire (PORTx=0xFF) si il fac intrare (TRISx=0xFF)Chiar daca intrarea este in aer (ar trebui sa citeasca 1) i-am pus si cate o rezistenta de 10k la VDD

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.