Jump to content
ELFORUM - Forumul Electronistilor
Sign in to follow this  
Guest jewelia

Help - intarzieri

Recommended Posts

Guest jewelia

Va rog sa ma ajutati si p mine sa fac un program care genereaza intreruperi de EXACT 4422microsecunde(ceas intern). Stiu ca 1 instructiune->2microsec, atunci: 4422/2=2211; 2211/256=8,63. Aleg prescaler 1:16 ? daca da, 2211/16=138,18 deci ar trebui k timer-ul sa se incrementeze de 138 ori? Nu prea cred k ajung asa la exact 4422microsec, dar totusi... cum implementez asta?ORG 0x0000 clrf STATUS movlw 0x00 movwf PCLATHclrf n ; var care numara d cate ori se incrementeaza TIMER0org 0x0004 ; pentru intrerupere movlw 137 ;w=137 subwf n,w btfss status, z ; z=1? retfie ; daca da bcf INTCON, TOIF ;daca z=0 goto mainmain clrf TMR0 clrf INTCON BSF OPTION_REG, INTEDG BSF OPTION_REG, PS1 BSF OPTION_REG, PS0 BCF STATUS, RP0 BSF INTCON, TOIE BSF INTCON, GIE INCF nendVa rog sa ma corectati.

Share this post


Link to post
Share on other sites

TCY=2ms4422/2=22112211/16=138256-138=118=0x76TMR0 se incrementeaza, cand ajunge la 256 (0x00) se genereaza intreruperea; ne intereseaza sa parcurgem 138 incrementari ale TMR0nu ai specificat tipul picului... codul scris mai jos se aplica 12f629, dar poate fi portat usor catre alt picORG 0x0000goto mainORG 0x0004;aici mai erau ceva instructiuni de salvare a W si STATUScall int_service ;2TCY;aici se mai pot adauga instructiuni de restaurare a W si STATUSretfiemaincall Init_tmr; aici se trateaza restul de initializari...Loop:goto LoopInit_tmr:bcf STATUS,RP0bsf INTCON,GIEbsf INTCON,PEIEclrf TMR0movlw b'10000011 ;prescaler 16 PS3:0=011, asignat catre TMR0, PSA=0banksel OPTION_REGmovwf OPTION_REGreinit_tmr:banksel TMR0 ;1TCYmovlw 0x76 ;1TCYmovwf TMR0 ;1TCYbsf INTCON,T0IE ;1TCYreturn ;2TCYint_service:;daca am intrerupere pe TMR0bsfsc INTCON,T0IF ;1TCYcall int_tmr ;2TCY;alte intreruperi...returnint_tmr:bcf INTCON,T0IE ;1TCYcall reinit_tmr ;reinitializez TMR0 2TCY;tratare eveniment - 2TCY, daca se face apel la o rutina...bcf INTCON,T0IF ;resetez flagul de intreruperereturntrebuie sa avem in vedere ca pana la declansarea efectiva a tratarii evenimentului mai trece ceva timp, adica cel putin 14TCY=28 msnu am intentionat sa calculez exact valoarea de scris in TMR0, insa codul scris de tine era (cred eu) structural gresit.cam asa tratez eu intreruperile si-mi merge. eventualele erori puneti-le pe seama faptului ca nu mi-am baut inca cafeaua.

Share this post


Link to post
Share on other sites
Guest jewelia

Multumesc mult.... :smt003

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.