Home

11 Timers Part 1

image

Contents

1. define TICTL1 TxCTL1 T near amp T1CTL1 define 72071 TxCTL1 T near amp T2CTL1 PRES_T S_T define T3CTL1_ TxCTL1 T near amp T3CTL1 PRES 1 PRES 2 PRES 4 PRES 8 PRES 16 PRES 32 PRES 64 PRES 128 typedef struct UCHAR T2I UCHAR 1 UCHAR TOI UCHAR UORXI UCHAR UOTXI UCHAR I2CI UCHAR SPII UCHAR ADCI 1800 T le uenum TMODE T TMODE ONE SHOT O0 TMODE CONTINUOUS TMODE COUNTER TMODE PWM 3 TMODE CAPTURE TMODE COMPARE TMODE GATED TMODE CAPTURE 1 define IRQO IRQO T near amp IRQO define IRQOENH IRQO T near amp IRQOENH define IRQOENL IRQO T near amp IRQOENL typedef struct UCHAR TEN 1 UCHAR TPOL 1 UCHAR PRES 3 uenum TMODE T TMODE 3 TxCTL1 void init timer 3 void TOCTL1 TEN 0 TOCTL1 TMODE TMODE CONTINUOUS TOCTL1 PRES PRES 128 TOCTL1 TPOL 0 TOCTLO 0 TOHL 0x00 reload clock prescale timeout Timeout 0 05 TOR CLOCK 128 0 05 Enable TimerO interrupt IRQOENL TOI 1 Configure the Output pin PADD amp b00000010 PAAF b00000010 TOCTL1_ TEN 1 define uenum unsigned char enum define UCHAR unsigned char uenum PRES T PRES 1 PRES 2 PRES 4 PRES 8 PRES 16 PRES 32 PRES 64 PRES 128 typedef struct UCHAR TEN UCHAR TPOL UCHAR PRES 7 359 uenum TMODE TMODE 3 TxCTL1 T define
2. Prescale 8 65535 128 5500000 1 525 seconds Minimum Reload 0001 Prescale 1 1 1 5500000 0 182 us 182 ns or 1 system clock cycle Time get shorter times which we will need we need to switch to the 18 432 MHz clock 216 is specified to run with 20 MHz clock maximum e Can overclock this some 24 MHz in Some cases Why would you use one shot timer 2 Triggered One Shot Mode J ust like the one shot but requires an external pin to start the timer TXIN is used to start the timer Must configure the appropriate GPIO pin for TxIN PAO TOIN PCO T1IN PC6 T2IN The bit is used to configure the TxIN pin for rising edge 1 or falling edge Triggered OneShot Timer Recipe Triggered One Shot 1 Write to Timer Control Register to set a disable timer b configure for triggered one shot C set prescale value d set TPOL 2 Write Timer High and Timer Low byte registers 3 Write to Timer Reload High Low registers 4 Enable timer interrupt if desired and set timer interrupt priority by writing to the interrupt registers 5 Configure the associated GPIO port pin for alternate function for TxIN and TxOUT Write to the Timer Control Register to enable timer Reload Value Start Value 1 x Prescale One Shot Mode Time Out Period s System Clock Frequency Hz Continuous Mode Just like the one shot timer
3. INSULIN PUMP SYSTEM Real Time Embedded Systems www atomi crhubarb cony embedded Lecture 1 anuary 17 2012 Topic Section Topic Where in the books Catsoulis chapter page Simon chapter page Zilog 197 eo zer series Flash Microcontroller Contest Kit User Manual Zilog UML 71 ios pevetoper studio I ZNEO User Manual Zilog PS220 eo zer series Product Specification Zilog UM188 cpu core User Manual Assorted datasheets Oscillators On Chip XTAL IPO Debugger Interrupt rhe Re WDT with System Controller uer RC Oscillator Clock Memory Buses POR VBO r3 Flash Memory RAM GPIO with External Interface Address and Data Bus 3 2 Controller Controller PWM What is a Timer a microcontroller timer Timers Most microprocessors and microcontrollers have sorne sort of timers Some have as many as sixteen timers e These are usually just digital counters that are set to a number by software and then count down or down to zero When they reach zero they generate an interrupt or set a flag or something ZNEO Timers e 16 bit counter that increments with system clock or external signal Interrupts can be triggered on counter reaching certain values Other things can happen on counter reaching certain values depends on the mode e 12 different modes Data 5 Control System Clock
4. Oz Logical analyzer g signals Analo D i D 1 i i i D 5 i i D i i i D r i i i i i I IT T VE DT DART INTE Edit obs TA 55 45 35 2 15 Jake 0 5 Oscilloscope Spectrum analyzer Recorder Logical analyzer File 05 Fa USB Oscilloscope 2 10 Hz Recall that output pin changes with EVERY timeout e output frequency is 1 2 timeout Or lOHz not 20 Hz What s TOR TOL TORL How do we know this a void init timer 1 TOCTL1 7 TOCTL1 0x39 TOCTLO 0x00 TOL 0x01 TOH 0x00 Disable timer why 0011 1001 86 O tpol 111 001 mode O mode 00 ticonfig 000 pwmd 0 incap Initial counter value reload clock prescale timeout 27 desired timeout is 0 05 seconds reload 5500000 128 0 05 4 TOR 47 IRQOENL 0x20 IRQOENH 0x20 Enable 118620 interrupt Configure the Output pin so we can see it on scope PADD amp 0x02 PAAF 0x02 TOCTL1 0x80 Enable TimerO Timer enable and disable Timer cascade define T
5. TOCTL1 T1H TIL TIRH TIRL T1PWMH T1PWML T1CTLO T1CTL1 00 00 00 00 00 01 00 00 00 105 105 106 106 106 107 107 109 105 105 106 106 106 107 107 109 Table 62 Timer 0 2 Control 0 Register TxCTLO 7 ser 9 EN mos FF E306H FF E316H FF E326H TEN ___ 6 R W FF E307H FF E317H FF E327H Bit Position Value H Description 7 Timer is enabled TEN 0 Timer is disabled 1 Timer is enabled 6 Timer Input Output Polarity TPOL This bit is a function of the current operating mode of the timer It determines the polarity of the input and or output signal When the timer is disabled the timer output signal is set to the value of this bit ONE SHOT mode If the timer is enabled the timer output signal pulses changes state for one system clock cycle after timer Reload CONTINUOUS mode If the timer is enabled the timer output signal is complemented after timer Reload 5 3 PRES 2 0 TMOD The timer input clock is divided by 27755 where PRES is set from 0 to 7 The prescaler is reset each time the timer is disabled This ensures proper clock division each time the timer is restarted Divide by 1 Divide by 2 Divide by 4 Divide by 8 Divide by 16 Divide by 32 Divide by 64 Divide by 128 This field along with the TMODE 3 bit in TOCTLO register determines the operating mode of th
6. Timer Input Timer Block Timer Control 16 Bit Interrupt Reload Register PWM and Timer Output Control 16 Bit Counter with Prescaler Gate Input 16 Bit PWM Compare Capture Input Timer Interrupt Timer Output Timers e 3 timers e TimerO Timer1 Timer2 Timer Modes One Shot Continuou Gated e Capture Compare Counter e PWM dual output PWM single output Capture Restart Capture Comparator Compare Counter e Triggered One Shot Timers Have Registers Lots of registers TxH 16 bit timer value current time TXRH 16 bit reload value TXPWMH TxPWML 16 PWM value and other uses TXCTLO 1 controls the timer configuration 0 1 2 Timers Base Address FFF E300 Timer 0 General Purpose Timer Base Address FF E300 FF E300 FF E301 FF E302 FF E303 FF E304 FF E305 FF E306 FF E307 Timer 0 High Byte Timer 0 Low Byte Timer 0 Reload High Byte Timer 0 Reload Low Byte Timer 0 PWM High Byte Timer 0 PWM Low Byte Timer 0 Control 0 Timer 0 Control 1 Timer 1 General Purpose Timer Base Address E310 FF E310 FF E311 FF E312 FF E313 FF E314 FF E315 FF E316 FF E317 Timer 1 High Byte Timer 1 Low Byte Timer 1 Reload High Byte Timer 1 Reload Low Byte Timer 1 PWM High Byte Timer 1 PWM Low Byte Timer 1 Control 0 Timer 1 Control 1 TOH TOL TORH TORL TOPWMH TOPWML TOCTLO
7. except that when the timer value reaches the reload value the timer starts over again at 1 e Forever e Until disabled TORR T Prescaler TOCTL Change Pin State Set TOH L to 01 Continuous Timer Recipe Continuous 1 Write to Timer Control Register to set a disable timer b configure for continuous C set prescale value d if using alternate function set initial output level and pin polarity 2 Write Timer High and Timer Low byte registers 3 Write to Timer Reload High Low registers 4 Enable timer interrupt if desired and set timer interrupts priority by writing to the interrupt registers 5 If using Timer Output configure the associated GPIO port pin for alternate function 6 Write to the Timer Control Renister tn enable timer Reload Value x Prescale Continuous Mode Time Out Period 5 System Clock Frequency Hz Continuous Time Reload Value x Prescale Continuous Mode Time Out Period 5 System Clock Frequency Hz One interrupt per timeout One output pin state change per timeout So the period of output 2 times the TimeOut Frequency 1 Period This is where we Stopped last week Why use a continuous timer 2 Review what we started last Continuous 1 Write to Timer Con
8. CALE 128 TIMER TPOL 0 alternate form TOCTL1 TIMER DISABLE TIMER MODE CONTINUOUS TIMER PRESCALE 128 TIMER TPOL 0 TOCTLO TIMER CASCADE NOT TIMER PWM DELAY 0 TIMER INPUT CAPTURE OFF Initial counter value TOHL 0x00 Timer reload reload clock prescale timeout desired timeout 5 CLOCK 128 0 05 Enable 118620 interrupt IRQOEN Configure the Output pin PADD amp b00000010 PAAF b00000010 TOCTL1 TIMER_ENABLE void init timer 2 void TOCTL1 TIMER DISABLE TOCTL1 TIMER MODE CONTINUOUS TIMER PRESCALE 128 TIMER TPOL 0 TOCTLO TIMER CASCADE NOT TIMER PWM DELAY 0 TIMER INPUT CAPTURE OFF Pour a 0200 an Notice that TOHL is 16 bi Timer reload So is TOR reload c prescale timeout des timeout 0 05 TOR CLOCK 128 0 05 Enable TimerO interrupt IRQOEN Configure the Output pin PADD amp b00000010 PAAF b00000010 TOCTL1 TIMER_ENABLE 5 3 The timer input clock s divided by 2 PES where PRES The prescaler resgt each time the timer is clock division eachffime the timer is restarted Divide by 1 Divide by 2 Divide by 4 Divide Sy 8 Divide by 16 Divide by 32 Divide by 64 Divide by 128 define uenum unsigned char enum define UCHAR unsigned char define TOCTL1 TxCTL1 T near amp TOCTL1
9. IMER DISABLE 0 define TIMER CASCADE 0x10 define TIMER ENABLE 0x80 define TIMER CASCADE NOT 0x00 Timer modes Timer PWM delay define TIMER MODE ONESHOT define TIMER DELAY 0 0x00 define TIMER MODE CONTINUOUS define TIMER PWM DELAY 2 0x02 define TIMER MODE COUNTER define TIMER PWM DELAY 4 0x04 define TIMER MODE PWM define TIMER PWM DELAY 8 0x06 define TIMER MODE CAPTURE define TIMER PWM DELAY 16 8 define TIMER MODE COMPARE define TIMER MODE GATED Timer capture mode define TIMER MODE CAPTURECOMPARE define TIMER INPUT CAPTURE OFF 0x00 define TIMER INPUT CAPTURE 1 Timer prescale values define TIMER PRESCALE 1 0x00 These are 1200 register bits define TIMER PRESCALE 2 0x08 All 3 IRQ registers or all 24 bits define TIMER PRESCALE 4 0x10 define IRQ TimerO 0x20 define TIMER PRESCALE 5 0x18 define IRQ Timerl 0x40 define TIMER PRESCALE 16 0x20 define IRQ Timer2 0x80 define TIMER PRESCALE 32 0x28 define TIMER PRESCALE 64 0x30 Some binary define TIMER PRESCALE 128 0x38 define b00000000 0x00 define 200000001 1 Timer output pin polarity define b00000010 0x02 define TIMER TPOL 1 0 Bed define TIMER TPOL 0 0x00 define b00001110 OxOE define b00001111 OxOF Timer Interupt Configuration define TIMER TICONFIG RELOAD 0x00 define CLOCK 5500000 Clock in HZ define TIMER TICONFIG DISABLED 0x40 void init timer 2 void TOCTL1 TOCTLI TIMER DISABLE TIMER MODE CONTINUOUS TIMER PRES
10. define _ define 2 1 define TxCTL1 T TxCTL1 T TxCTL1 T TxCTL1 T I u u near amp TOCTLI1 near amp TICTL1 near amp T2CTL1 near amp T3CTL1 Define a set of enumerated constants the value is important A bit field declaration Define a new macro of the new type at the address of the original macro Timer Part 2 Next week
11. e timer TMODE 3 0 selects from the following modes ONE SHOT mode CONTINUOUS mode COUNTER mode PWM SINGLE OUTPUT mode CAPTURE mode COMPARE mode GATED mode CAPTURE COMPARE mode PWM DUAL OUTPUT mode CAPTURE RESTART mode COMPARATOR COUNTER mode TRIGGERED ONE SHOT mode Bit Position 7 6 5 TICONFIG Value H Description Timer Mode High Bit This bit along with TMODE 2 0 field in TOCTL1 register determines the operating mode of the timer This is the most significant bit of the timer mode selection value For more details see the TOCTL1 register description Timer Interrupt Configuration This field configures timer interrupt definitions These bits affect all modes The effect per mode is explained below ONE SHOT CONTINUOUS COUNTER PWM COMPARE DUAL PWM TRIGGERED ONE SHOT COMPARATOR COUNTER Ox Timer interrupt occurs on reload 10 Timer interrupts are disabled 11 Timer Interrupt occurs on reload GATED Ox Timer interrupt occurs on reload 10 Timer interrupt occurs on inactive gate edge 11 Timer interrupt occurs on reload CAPTURE CAPTURE COMPARE CAPTURE RESTART Ox Timer interrupt occurs on reload and capture 10 Timer interrupt occurs on capture only 11 Timer interrupt occurs on reload only 4 CASCADE 3 1 PWMD INCAP Timer cascade This field allows the timers to be 68568060 for larger counts The timer is not cascaded Timer is cascaded If ti
12. mer CASCADE bit is set COMPARATOR output is used as input If timer 1 CASCADE bit is set the Timer 0 output is used as the input If timer 2 CASCADE bit is set the timer 1 output is used as input PWM Delay Value This field is a programmable delay to control the number of additional system clock cycles following a PWM or Reload compare before the timer output or the timer output complement is switched to the active state This field ensures a time gap between deassertion of one PWM output to the assertion of its complement No delay 2 cycles delay 4 cycles delay 8 cycles delay 16 cycles delay 32 cycles delay 64 cycles delay 128 cycles delay Input Capture Event Previous timer interrupt is not a result of a timer input capture event Previous timer interrupt is a result of a timer input capture event Timer Input Output Pins General Purpose Timers TOOUT TOOUT General purpose timer outputs These signals are output pins T1OUT T1OUT from the timers T2OUT T2OUT TOIN TOIN1 TOIN2 General purpose timer inputs These signals are used as the 2 capture gating and counter inputs Timer IO pins e Changes state on timeout The inverse of TxOUT TPOL register determines direction of state change e TXIN Acts as an enable or clock source on some timer modes Timer Modes One shot Triggered One Shot Continuous Counter Com
13. parison Counter Pule Width Modul ated Capture Capture Restart Compare Gated Capture Compare One Shot Mode e Timer counts up to the 16 bit Reload value e The timer input is the system clock Upon reaching the Reload value generates an interrupt A court value in the Timer High Low registers is reset to OOO1H the timer is automatically disabled and Stops counting elf Timer Output alternate function is enabled the Timer Output pin changes state for one system clock cycle from Low to High or from High to Low One Shot Timer Output can make a permanent state change upon One Shot timeout by setting the TPOL bit in the Timer Control Register to the start value before beginning One Shot mode Then after starting the timer set TPOL to the opposite bit value If interrupts are not enabled no ISR is called but a bit in IRQO 1 2 is still set to indicate timer timeout One Shot 216 Manual has very wordy description of each timer mode have flow like diagram which I think 15 clearer Not intended to be an accurate representation of hardware but to show the registers and the sequence of events Read the description in the product specification TORH TOL N System Clock Prescaler TOCTL xX Alternate Function Change Pin State This value changes with each tick of the
14. system clock How Long The timer period 15 calculated by the following equation start value 1 One Shot Mode Time Out Period s ya mern System Clock Frequency Hz reload timeout clock prescale startvalue I OneShot Timer Recipe One Shot 1 Write to Timer Control Register to set a disable timer b configure for one shot C set prescale value d if using alternate function set initial output level 2 Write Timer High and Timer Low byte registers 3 Write to Timer Reload High Low registers 4 Enable timer interrupt if desired and set timer interrupt priority by writing to the interrupt registers 5 If using Timer Output configure the associated GPIO port pin for alternate function Reload Value Start Value 1 x Prescale One Shot Mode Time Out Period s System Clock Frequency Hz Time and Clocks Time is based on the system clock What is the system clock how fast e Clocks e The ZNEO has several Ab5 5MHz internal clock Supports external crystal up to 20 MHz 18 432 MHz on board Supports external RC oscillator f we had one we dont You can switch them but for the time being 5 5 MHz is the system clock One Shot Time Reload Value Start Value x Prescale One Shot Mode Time Out Period s System Clock Frequency Hz Max time Reload FFFF
15. trol Register to set a disable timer b configure for continuous mode C set prescale value d if using alternate function set initial output level and pin polarity 2 Write Timer register TOHL 3 Write to Timer Reload High Low registers TOR 4 Enable timer interrupt if desired and set timer interrupts priority by writing to the interrupt registers 5 If using Timer Output configure the associated GPIO port pin for alternate function 6 Write to the Timer Control Renister tn enable timer Reload Value x Prescale Continuous Mode Time Out Period 5 System Clock Frequency Hz Continuous Example A ContinuousTimer c Example Example Configure TimerO for 50ms output Enable TOOUT e Use oscilloscope to examine Timer Output O e There are several ways to code the timer values 05 25 6 5 2 tuse elu iei see er 01 T2 256 5 ms 0 Ua2 uz nal parameters 0 01V 1 1 Signal parameters at the markers T1 24 75 ms U Up AS pe oe reel eee eee eee eee eee eee Sukk ada ada Hana a aaa eat U Se BATUR TE 2 42 p i Help Lipgrade 1B Tools IIT Channel at

Download Pdf Manuals

image

Related Search

Related Contents

Leica DIGITAL MODUL R Operating Instructions  Airpura Industries H600 User's Manual  P/N 45-25193  DYNEX DX-WMSE2  Bez názvu-1 - ViaNett Archive  6100 Synergie+ 10W-40 Huile Moteur Essence et Diesel    User Manual - Official Website of Onwa Marine  Service Manual    

Copyright © All rights reserved.
Failed to retrieve file