0% found this document useful (0 votes)
3 views64 pages

Unit - 4 Notes

The document discusses the functionality and programming of timers in the PIC 18 family microcontrollers, detailing their modes of operation, clock sources, and prescaling options. It explains how timers can be utilized for generating time delays and counting external events, as well as the interrupt handling mechanism associated with timer operations. Additionally, it provides insights into the configuration and initialization of timers for various applications.

Uploaded by

atharvshete42
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
3 views64 pages

Unit - 4 Notes

The document discusses the functionality and programming of timers in the PIC 18 family microcontrollers, detailing their modes of operation, clock sources, and prescaling options. It explains how timers can be utilized for generating time delays and counting external events, as well as the interrupt handling mechanism associated with timer operations. Additionally, it provides insights into the configuration and initialization of timers for various applications.

Uploaded by

atharvshete42
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
UNTT - TV pee S mM C Rexipheeal Suppost in PIC SEXKXRA Timex s and its Prograroming Conde 0-9 1) pt _Stucture Of PICisF with SER PORT B Change. Tnteerupts Use of timers foinaineweupie ie i CcP modes $ Capture , Compare $ PhIM genetation ensox. Tntee Sacing using _ADe ill__pengeam fa __enobedoled_C. Timess of § PTC 4gF xxXxx 6 PIC 18 Family has uote five _imexs i f the fami} Peo a teenie dep ending on member. Th paigee eer aineoer 1 eel gen tate a “ime delay ota cranes. Bees Count events occuring outside the rofexocontoller — IWhen the timex fs used as a timex the PIC 18s cry i h 6 x put oy tal__oscillator by a a piheleyied et amapmriadcaiece) bib ta taee=rocoNe aegi tex decides the source of clock tor -the timer. _ TE bit =0,-then the timet opetater as _a mer with pulses $40m Osct and Osc2 pias. Tt hit =1, then the times opezates like a countet and _geks the pulses outside tora _ fale Gate Peescaling Chee PanG Timess 3 The times canbe optionally —prescalled, _ The timer onetates as d -limer with sebevence tn ht Gi ee Tn_Aea| time ta_many__caltul er . a much slowet — time hase to vba Calouleited of) 2 Times 0 5 r B-bit a Se Se a a ° prograremall Lis THR > Tose. Fh, agen A | + presenter: RIECK T | 5 I fsa Sct tmpate Tacs On areeHow =m Ps2.:TOPSo Timet 0 Block Olagsam in B-Be mode Clock source selected can be _extetnal ov __ intetnal. =i4 FTnkestupt on oueet laa —jyom FH to 00H in Shit nde nnd FEEE H $0 0000H tn 16-bit mode. Edge elect tnt exteenal clock. TOCON [ Times 0 Cantal Reaister | $= =e eos J03BI1|TOCS | TOSE| PSA| ToPS2| ToPS4| TOPS OD} TMROON Ttmet 0 on] OFF cantunl bit i = Enable timet.0 0 = Digable tHmet 0 TO SRtT + Timeeo S-bit | 16-bit control bit 4 = TNmet 0 Shit timer |countee O= Timer 16-bit monde. La |FTtocs 2 “Timet 0 Clock. Bee Po) (Sets Sancition on rock tL RAS pin O = Internal to tauction cycle clock. __ (tose prom cuyctal oscillates TTOSE ¢- Times _0 source edge select ie. 1 = Tncvement on igh te [abe HanstHon on Toren 0 = Trexement on lod to high 4deansition on TOCK1 pin PSA 3 “Thme: 15 Timet 0 MOPS muni Presi le its QU es SUES OULAS ence WO = 1: 128 O10 = 1-8 lor = 1 64 OOl= 1:4 Oo = 4: 395 WOO SNA oe Miroer Oo 1 ant 6 hi odes a Step 1% load to TOCON eke 0% 164i) mode £ peescale. =e D2 load the TMROH and e01_ _Aegistess with the tniHal count [for @-bit mode load the IHPol. neqtshes with fnittal. count) — Step 2% Start the Himet As Obsexve the TMROTE flag. Exit tym loon when the. mente dag ts sek > — [Numeicals s- | Find values Erste see ello tnto Hier 0 registers enetate a quare wave _of 5 kHz on — Port @-0- ere a =| To geneeate square-wave = 5 He pla -|| Time Period = 1 = 200us Sku2 - || Assume 50 7% aluby © eS ON dime =OFF time =10 =| Fose =40 Me ( Assume) Tro: UDxto® -||Using Times 0, 4 g Tiimee ick with prescales = “tm = EOF sli 16 Enea Cis iitcu Co ed tas Re CIR SMe go Sa 649. womint 1-6 us load eVedey g Hae ful [nH Trial cathe eet ad ‘ayjer 63. count Reload = 65536 - 63 S(ruaaeeM “TM ROH Mol. oxga | “Timez 0 on, 16-bit, Intetnal Clock , prescales assiqne ToCON = with these value each overblown oceuxs period &% 2. % 400-2 ws / « Resultinw Ff, x S a sae = 4-46 kK (% 5 kUy) ) N44 sa orn =| Bogsam Be eit lsat 4 ## Include ¢ P18. 18f4550-h) aigepeers | ~ void times. isa Cvotd) 5 4 [) Timet 0 Tnie: ‘ = void 44 ub a TMROH = OXFFs // Reload Tine 0 bute iH La AMROL = OXC41§ // Reload Tires 0 low bute wilh over 4 I Thes makes Timer 0 ows tla evr #400 1 PORTB bits. RBO = © PORTB bits- RB0; / | Toa le BBD pin IL Square wave OP Se eRe = 03 Icleae Trmet 0 _overklous t Pinte: upt dla — iF f 4 x = 0x 0008 gud high Tsk (void) _ asm Iinseets assembly code [3 a £ton. f Sends -execiilfory to Wour Tse fuck —endasm +h # pragma code A TS = SH Note - When a Wah _palond Ey ‘interrupt occurs, program | _fum, eo | a | = s ee el a rel mmr es Wedd eat -TRISBhits -TRISBD = 03 PORTBbitsR BO = | TMROW = OX FF; load Th TMROL= OX C15 J load Ts TOCON = 0% 335 |/ Tymee OQ oN, 3! INTCON= 0X As | Enable global inter» while(+) 3 Caleulatfon of 0x3 9% oxAn = here leas he ee ae os ATS 2 dX kom [To 8027] es Tose] PsA] Tops? |ToPsd | ToPSO | 4 0 (mee On OF Mors walt 3 | (4000 0011), = (0X83 See ee ee Pee re Tao Trore| Fainaaeince tere plies 0 alt 0 0 0 0 0. (4010 0000). =(0x% Ad) irae Melber sia Ad Fo 4 e -||16-bit times Rees Malet ayade goth Aegistees ache! sine won) opeiMiR yy Scot U poctaleet AD dios ial = [Both the registers ave teadable and writable. ____ Bicinieenal ox extee nol clock select. -|| Totes suipt on _oveeblow tyom FFFEH tp 0000H when _ se yie Retest oi ii Blineteiitvome-c : spatial event niggee. TINRITE ep. Special vet 99 sey. FREE bit] ET TMRION SI =e Fesgn & f 4 Prescalew Syncnonize | i "JOSCEN e238 detect i Tp O—10 Ape pepe mt = FRARLES “Times 1 Block. Diagram RD 16] —| Tick psil Tack Psd Diss | Rote eae end f antteemode + —— 4 = Enable 16-bit mode __+-— 0 = Enable two 2=-bit wip rosea: hs 2s TACK Psd 2 Tick Pso ed 1 (ae ee ba i ee lee oluee 0 al Sperm oe Vawe 0 0 SA Beccale “Value TLOSCEN ¢- Ti ‘Vator i i 42 Times 1 cosctilatow fs enabled = 0 = Ti ose| wit a TASYNC $ Timee 1 oscillatox enable bit cy nchovial When TMRics= 4, counter_mode synchronized to exteénal clock input TLSYNc bit ts tanosed _- ig TMRICS =0. - IMRICS * Thmevt clock source Lies E 4 = Exteenal clock trom pin Reol Tosco|tLekr — Con _xfsing edge) 7 Uv + = Fosc. ‘| - pity + “EMR 1DN Times 1 ON bit fe ee See Timee 1 A O = Stop _Trmee_1 Timez 2 3= a TIFT fs S-hit 44 TMR2 register) -|tt has an—8=bit period neat. eo ee = Gath aeiie_ a umaatle hed nate =| Xe Acceomste =| -Tnteraupt on TMR2 Be: PRO =|ssp module that uses TMR2 output tor genecating sthemeciockioichit tell! | ak | THRE Flag bie Prescaler TMRD i rea Att, 4:4 and ii fips iit¢ Registee | TouT ps3: TouTPs o Timee 2 Block Diagram THCONIL “timex 2. Cal Regishes # mei area aes meet SF ae = [TouTPs3 | TouTps2 oes [rarao| Taken | sy = 1 TTOUTPs 3 2 Toutes o &- Timet 2 output postsealers et electmnitsmee tT Ati Postscales pal a 2 Postscaler AH Chins Posternien TIM R2ON $+ Times 2 on [OFF bit 5 = Start imez 2 signin i ) T2CkPsd % TACK PSO & Timet 2 Clock Prescale selec bits. 00 — Prescales is 4 Me eC isan -eninion il “Tt has two @-bik veafstens » TMR3H and TMR3L- Spih_seaisters ave seaolable and writable Tt has” tntewml ox externa) clock select. Tt has a Software Proqsaromable prescales( 1:4 | Abr pepe les pees] 1.85) Tt can he reset by a module trig qe 4xorn Gcp4 /speaiede CCE ga TMRIT EL yee : Boe a T1656” py EU Deen jeleny oS 1 Prescaler Ee + 2 “5 3 ___| deteck Th6 eas # TMR3CS : Sleep IP F3ckk Pso, Block Diagram of timex 2° aiClock we_TOCKI_pfn meets! pin None _ Cextee nial ob Timet 4 a q oscillatr (14s¢) Ei 1 Clock Gedling! Prescaley B-bits | Prescalex 2-hits| Bescaler = | —avotlab) [12> diese] | fan [Link], [fres, 124, 1:1] © CResolutteh) 48] Poskscaley 2 "| Ci > $40) © Doterupt | On Overdlow Tm Ree _ even EF > oo FEFEh >) vichecl_ PRO 7 Cun ie aa pac Fo NO Yes No ~ le ||/ a! Tatenunt Stiuctive of Pro 18 £%xx =| Antervsupt fog %- aio jos aaa fves' fi ato. ler. Can pee eric. There “are. -hoo swohfch _ dlevices __] xeceive service liom lhe mferocentsoller. Tnterupt_| Ob polling.- Tatesupt method h meres any device needs the —tmfcentontrnller—_| cesvice, the device notifies: Sake by Sending —din — tnkevu pt —sfgna}e Upon rec cving on Internipt stanal_, tine __—__ 2 Bree gies 8 ch atop and serves the — clevice. [he method moi t Sct os Eas. || statu | Aftee that. tt moves on do Seveeal devices _ a. genve each of as SMe ee ie met, tt is an el ficient use of microconnollex_ on the faciosites a. igned to it EI “The pred method can not a sign pri because checks all devices fn a vound—= —_ xobin. jollens time SS El Steps in eat ain _cubntermdipas nod) Hl ques ao i SES iat: f is exec L saves 4 ok fi fi E _on the Stack. » rt furnp< to a dixed Location to_memory called cman u G vector table divecks the microcomyuller +o the Sp. ! i prc | Sousces d-Tnterupt Ss Stauehe ok : as (Sing aT isis a a ee C eee ats ca b Pier are. anys a — jhe) Pac 1g. UY depen sng oo _cthip--— {s_ incoxporated —into— ae used sources 04 ui ere es 1 ee i a ia A ae ee ch. i} —__ [eee ae ul 2| h Ms aa El u 5 : ater 2.02 a ij 4)| Port 8 change tn_fntesvupt = oF a > WiyGre— Oat i 6, ceP module ni ie | Tintenxuot Ben tecs of PIC g= An_intesxupt {sa communication process 40 _panutde sewvices to ditterent internal and external devices = executing, Ish [ Intemupt Serkce Routine] iS =_A_ device = = Requests He MPU +e stop pr cessing = “Tntexnol, ox external mlhes M4 Pulee= = Ack now wiedges athe , request = Attends to -lhe nequest — Goes back 4 esi ez intesrupted. Re tio act en ee un = ee ees) il I Ahe event ba tag ee action is xsequix: hed pve diac setusw a contol 0 fia raain Bape eso Conn3 W) 2 Low pstoct And enu bt: te 1 e she events that cause — -thern “Types ok Interrupts cn __ Tntesupts foot alah ly ian cco tothe black } Piotie Aitinee Gn iiameset es slate tov. Geneeation of 2 kHa jon PORT B+ Calculations eae Ge of oo 5 2500s Time pextod of 4 Square wave J = ae Lek's assume S07 duty cycle ok Square Lay - The sau ; = i loxa fox 25 us. i Ei = 10m Times clock | 40 mua a Jk A Atmpaba otic {ris hd! dost) one yey | Pericles ieae N= ON MNmex of square we Timer clock Period. MN iin “DIDS ce Oy us / aay Pears tn timex ~4egisters 2+ TMROH TMROL Ox FD H OxgF H wip -||Proqvom s- s i ott include < Pigr4sso-hs Se defin hit PoRTAbtts: RBS ee mafnty TRISH hits TRISRS = 03 Weeofiguve RBS as Olp- while (4) i maybit an Mybit § ae 3 ofc y 0) Tocon = 0x08; |/Timet0, 1643+ mode no pescalex TMROH = OXED; // load TimetO values fox okHe Tr ADL = OX SF 5. I || Calculations = = Fuse = 10 MHz prescaleys 124 —~ ~~ —_| Times clock en ty = & 4 4. = 0:6es Mz. = - |e i = ft a 7 loxios 7 p/p get ol elay of 50 msec. eae N = ft) a See a Ses aes ema (BIE Guint a5 RS Yeaded in Hmmecif ots, =. 65536 - 312750 a 34236], > eset], “| TPIROH = 0 IrM Ror = Ox Ee TOCON ¢= =rmRoON | TosBI frose [cal-roesa| toes -rarsol C 6 e Prescaler = TOCcON = 0000 Doo4L Ox OL | Prox rar s— +t fnclude Cpigeas Soh) gilmaten eee = “TaIsabits- TRIS BS = Os while C1) “a PORTBbIts. RBS =v PORTBbItS-RBS s olelay () 3 g TOCON = 0X043 || Timer 0, 1:4 Prescales ty Le-bit mode. mon = 0x26" 3 I/load Time with ~ TMROL= Ox EE} calculeted count. TOCoN hits-TMROON = 15 J) stop timezo INTcONhbits-TMROTE = 03 // clear TMport = Flag. ‘f Registes psi Shine peer os via = [Dx B41) DexBO CoP y M3 CCP. M2 [dcx81 2 DEnBO = PWM duty cycle bit-4 7 bo a a _ fer ¢cP™ module X 2 Capture mode = unused - a Compate mode = Unused i RW! mode = These two bits are the tet LsQs Chit a2 pito) of OE cIhe io-bit Pin duty cycle. a CCPx MS 2 CCP MO - CoP module x ode seleck bits _ M 0.000 = Capture [compare] PU disakled resets C¢Py moclule) — 00°)\ = Resesved O° 1 =Comparemode, toggle 1p on match (CCRIe bit ‘eal a ClOmle = 0.100 = Capture mode, every galling edge Z| G10! = Captuse mode, EMER alsing eolae a 0110 = Capture mode, everg ath gising edge 2 O\\1 = Capture mode,_eaced 16" xlsing cde i Gnitialize CCP pi oO (000 = ee ot aieeecc eel vo! La Cc Wn is ce at iN s. (po\ = Compare. yaad falitaltze ¢cf, pin igh, on Compars melch_— mcd CoP Pin lo CECPxAF bit Is s o\o =¢ Compare mattn (cop) pin unaFFeded, CoPxtF bit js s- outs A ‘ sek) lfey CePd 2 CcP2: Teed 0% Times is reset on — event al 5| PORTE Interrupt = On= Change tc E| ‘An_input- change on PORTE <'1:4) sets fis Rie, |RETE CINTCON ), So sig lemme £| niewvupt _prioxt ‘4 yor PORT B_ Snkexrupk= on -Change - not | the value contained “inthe —_- inter ‘i m1 P CIN Tcon 2 407). 4 am exteenal_intesvupts CINTOs INTL and INT?) — lean wake-up the processor _ {rom the power— - eI -tronag ed modes 14k 5_ TIINT2LE, was set 4 - et ie peal | Ree elo eT pt Enahi_ bi ee seer Pts seh, the ninceasax Jill branch +o lees DUPE ectaxe follastng on ke - p. al NT2 Prioy +o cing Ben inton te powex= mi 4 een eeeSeR Ct J Global —Interxupt Enable tai Baste eek. _dhe processor will _ba.anél ee teriupt priority fos fox IN TA < ue contain be oe opevated fn polieee 0 Contuse Compare. Prim | Module = classmate PECISEM4SSD microcontroller fs _ provicled with on — anu one the three modes. | Capt Mocle ! Captu xe mode, cn cep pin wfll Panik, : ee fo_c rent ~_D) Putco Width Modulation 3— \ \ This feature allows +o Create pulses of Ween = jGenecal. Features of CcP Ptodule#- = Fash 3 mecaey ertipeliile je requires. the use of dimes __yesource . je capture ox compare inode, the —< cep ieee oa Je Trene ATO e © . D identical ate exception o even asf mode present on Gara and Cc P2.~ termined 4 bi the T3CoN YC. Tacp2. ¢ and bit 2 of SLacepL IRIE, |_Capture, Compare and PWM modules 2 —_— ‘gach CoP (Ge Capture] Compare DIN metal WleuAemtarns ee operate as a 16-bit —Copbre tepisten » Os Q 16-bit Compare _xegtsters_ox Oso ed ee ee ae ister. pe amt ‘Caphure. Compare ane _ Pulse Width Modulation(pun) _ | module Is accociated otth a contol xe: cE | Kieren ona ada =o ister Cccere). ea 1 aor a | K iS e a | = bik Cann pare — register H- = Cle PWM segietey Ue: lw Filmes 2 used og dock fox Pik o ‘the assignment of a particulas fimer te a! ! following table shows the assfnment —— of Himens fox CCP modes: He a nee f | CCP Mode Timers Resource — Cipluvedls ila oitmeetn de “Tt ae ee ‘ 7 Gomparve | Times 1 ox “Timers dhe PWM. “Timee 2 a 7 a eee “Moale - ¢- faa cae A Aaslon = "The mode ele ccPx M3 ——ide _coPx mp bits, of CCPICON weg fistox t, _—_Letther a5 values : 01x x Chlheve x¥ = 0, a1, 10 i -_— and 4.4). gi p—IRCS /ccp 1 pir eed input _ 7 7 7 \ Aj iiner_/ synchronous counter. , When the 3" bit of pret register | “te: CoPate 15 set content of times. Valye x TMRtL fs copied on _ orl. segistex_Ton—-ine_xtsing I falls a edge owt Reo/ ccPi” sees dimer Value eaister TmR4- ts copfed on CcCPR4 aepis! Snes os eo. aq module must be disabled while ere Je. q =| Applic ae are = eet) Sees 0am veloxaltag by) Pexfod measurement 2 Wiclth measurement d) | Ta teniuphsls 9 entation UN aks it | ©) Event counting | Time Tekerence. “Pj Dlby — ele —meaaixements S [Compare Mode oo Si CCPRCON <3: Ee Mmode select oO i El Timea Tm RIM [rea Froese S He 0 oe a) Difven i b). Oriven Lows cy T Output eae bit copize is eo 2 set] Mee pe Make a cop! (timex 4 - fife = Fae yeah reerierclelat To the stn ein the betel aegistex _palx.— a Pee = i S|Sree een eit [felt yemeGl>-ee p modules can___——- ce oe emerect TR aH Genetate -this ev i Ong EMR depending on 2hich—Hmer ali reek eee bas eeee ine [PML Pulse IWickth Modulation | rade 2- ~ CCP value _ Megistex 10-bit mode [—— A agen = CoP TRIsc { tateenal Ocleck 1 os from Prescalar zi PWM ic is peenees of ae cep. “module, mich | Lollows the programm err. to generate. pulse _|Lof vaxiable — — a Senco = Shei ol cid ian _tmpovtant. factors considered al luting —— _genexation ar PWM ere eel al : Seale fal. fal al ee eer 5 it LIL LDLL fox 75 % duty cycle s= | ceprae == ON Rr XL PRO i Ba aad fo eeCCRAM = 0175 x 244 ee c= 2 acai he ie dail Ep ilieccerat = ise. 7s = lige n= ConBaly > a —— (Tacs tie Det gy sat 7 = x & e182 DCaBi | Decimal iad i s RO) olin ud eee 0 0 ° a © 4 ous a a ° Os 3 2 4 0-15 | iS ifs tr a é sg org x a IE ES fa Fl ce a3 i 4 it cs a M i S. Rey TN4 0 — Be al [2990 a | Pee: Driver Tc ee a [Sfeod Gontvoliol [Link] 2- {Teer fuse Width Modulation [i= ae |The peediumbathe motor depends on _- shee | _|| Factors? Load and Current. We com — maintain a ot speed ba sing sca method — called PWM at as c fi pee aed eae o te : rr amount of poner provided to the motor, — thereby Eee nq or clecre asi ng -the aa omy =| Pulse= Width Modulation (Pwr) os utp cycle variation methods a O%ts. ee oy ts elefined as athe. of 0 cle. al cen: om a cael at eg aed —— +5 volts 7 wosans 3 a Block Diagram of n= built ADC With. Control. Regis: nes Chap ee Te ty eo NBT ANID tes ‘ toe OT BTA z (po Sol —Bxq] Ante r (19 LOL BANG i Ba tN ia zc ees AN FO | [4o- bie Sree ane i Convertet VAIN ; Se ANSC) AlD Coput vollage).1 5 0 D180 JAN CAnalogy, © (p95 Sot IANS ipo oto TAN eRe eS CoO} JANE pe ee ap a ol ne ! Refrene | |VREF+ igen ‘Vo tage : vaee=l, poli Laer i oe

You might also like