0% found this document useful (0 votes)
17 views17 pages

Systick

Uploaded by

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

Systick

Uploaded by

jerim57595
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

TI-RSLK

Texas Instruments Robotics System Learning Kit


Module 9
Lecture: SysTick Timer - Theory

Texas Instruments Robotics System Learning Kit: The Maze Edition


| SysTick Timer - Theory SWRP171
SysTick Timer

You will learn in this module


 Fundamentals of SysTick Timer
 Measure elapsed time
• Precision
• Range
• Resolution
 Software delay

Texas Instruments Robotics System Learning Kit: The Maze Edition


2 | SysTick Timer - Theory SWRP171
SysTick Timer :
SysTick performs Timer/Counter operation in all ARM
 Create time delays
 Generate periodic interrupts

How it works
 24-bit down counter decrements at bus clock frequency
 With a 48 MHz bus clock, decrements every 20.83 ns
LOAD
 Software sets a 24-bit LOAD value of n
 The counter, VAL, goes from n → 0
VAL
• Sequence: n, n-1, n-2, n-3… 2, 1, 0, n, n-1…
 SysTick is a modulo n+1 counter:
 VAL = (VAL - 1) mod (n+1)

Texas Instruments Robotics System Learning Kit: The Maze Edition


3 | SysTick Timer - Theory SWRP171
SysTick Timer Initialization Bus clock Turn on
Flag

31-24 23-17 16 15-3 2 1 0 Name

0 0 COUNT 0 CLK_SRC INTEN ENABLE SysTick->CTRL

0 24-bit RELOAD value SysTick->LOAD

0 24-bit CURRENT value of SysTick counter SysTick->VAL

Table 9.0 SysTick Registers


void SysTick_Init(void){
SysTick->LOAD = 0x00FFFFFF;
SysTick->CTRL = 0x00000005;
}

At 48 MHz, it rolls over about every 349ms

Texas Instruments Robotics System Learning Kit: The Maze Edition


4 | SysTick Timer - Theory SWRP171
Measure Elapsed Time

Time to
Start = SysTick->VAL; execute?
SystemUnderTest();
Stop = SysTick->VAL;
Delta = 0x00FFFFFF&(Start-Stop);

At 48 MHz
# of distinct measurements
• 24-bit precision
Smallest change
• 20.83ns resolution
Largest possible
• 349ms range

Texas Instruments Robotics System Learning Kit: The Maze Edition


5 | SysTick Timer - Theory SWRP171
SysTick Timer Wait

Resistor
Wait(n)
void SysTick_Wait(uint32_t n){
SysTick->LOAD = n-1;
SysTick->VAL = 0; // clear Count
LOAD=n-1 while((SysTick->CTRL&0x00010000)== 0){};
}

Clear Count Flag


At 48 MHz, it works up to 349ms
Doesn’t work for n=0 or n=1 Count is in
bit 16
Read Count flag

0
Count

return

Texas Instruments Robotics System Learning Kit: The Maze Edition


6 | SysTick Timer - Theory SWRP171
SysTick Timer : Generate 10 ms Wait

Wait10ms(delay) void SysTick_Wait10ms(uint32_t delay){


for(uint32_t i=0; i<delay; i++){
SysTick_Wait(480000);
i=0 }
}

i >= delay
i 48 cycles is 1us

i < delay
48,000 cycles is 1ms
480,000 cycles is 10ms
Wait(480000)

i=i+1

return

Texas Instruments Robotics System Learning Kit: The Maze Edition


7 | SysTick Timer - Theory SWRP171
Summary

 SysTick is a built in timer Wait(n)


• Measuring elapsed time
• Creating software delay LOAD=n-1

Clear Count Flag

Read Count flag

0
Count

return

Texas Instruments Robotics System Learning Kit: The Maze Edition


8 | SysTick Timer - Theory SWRP171
Module 9
Lecture: SysTick Timer - PWM

Texas Instruments Robotics System Learning Kit: The Maze Edition


1 | SysTick Timer - PWM SWRP171
SysTick Timer
You will learn in this module
 Concept of Pulse Width Modulation ( PWM) and Duty Cycle
 Create pulse width modulated (PWM) signals using SysTick Timer Delay
 Use PWM to control brightness of an LED
 Apply PWM to create digital to analog converter ( DAC)

Period Period

High Low High Low

Texas Instruments Robotics System Learning Kit: The Maze Edition


2 | SysTick Timer - PWM SWRP171
How fast is the device?

Change the input (step change)


Measure the output response

Input

Out Output

time

Out(t) = A + Be-t/
Time constant, , is the time to reach 0.63 of final

Time constant , 
HLMP-4700 LED 90ns
DC motor 100ms

Texas Instruments Robotics System Learning Kit: The Maze Edition


3 | SysTick Timer - PWM SWRP171
Pulse Width Modulation

while(1){ High High


P1->OUT |= 0x01; // red LED on Dutycycle = =
High + Low Period
SysTick_Wait(High);
P1->OUT &= ~0x01; // red LED off
SysTick_Wait(Low);
}

Period Period
Input

Output
High Low High Low
time
High+Low is a constant
If fast enough, the device responses to the average

Texas Instruments Robotics System Learning Kit: The Maze Edition


4 | SysTick Timer - PWM SWRP171
PWM - Digital to Analog Converter
PWM + low pass filter 10ms

1s

P1.0

Static Linearity LPF cutoff:


DAC output (volts)

4.0 fc = 1/(2πRC)
3.0 fc > analog wave
2.0 y=3x+0
R² = 1 fc < digital frequency
1.0
0.0
0 0.5 1
Duty Cycle

Texas Instruments Robotics System Learning Kit: The Maze Edition


5 | SysTick Timer - PWM SWRP171
Applications of PWM:

 Control brightness of LEDS


 120V /60Hz appliances
 Use it to make a DAC
 Transfer power to control motors
Motor driver TI DRV8838

TA0CCR2 TA0CCR0
Driver Dutycycle=
TA0CCR2
TA0CCR0
TA0CCR1 TA0CCR0

Dutycycle=
TA0CCR1
TA0CCR0

Interface TI Launchpad with Motor driver TI DRV8838 using PWM

Texas Instruments Robotics System Learning Kit: The Maze Edition


6 | SysTick Timer - PWM SWRP171
Summary
Vout
 SysTick is a built in timer
PWM
• Measuring elapsed time Vout
• Creating software delay PWM

 PWM
Vout
• Implemented with software delays
(inefficient)
• Choose the fixed frequency faster than Vout
the device
• Device responds linearly to duty cycle
• Provides for high precision outputs

 Applications
• Dimming
• DAC
• Motors
Texas Instruments Robotics System Learning Kit: The Maze Edition
7 | SysTick Timer - PWM SWRP171
IMPORTANT NOTICE FOR TI DESIGN INFORMATION AND RESOURCES

Texas Instruments Incorporated (‘TI”) technical, application or other design advice, services or information, including, but not limited to,
reference designs and materials relating to evaluation modules, (collectively, “TI Resources”) are intended to assist designers who are
developing applications that incorporate TI products; by downloading, accessing or using any particular TI Resource in any way, you
(individually or, if you are acting on behalf of a company, your company) agree to use it solely for this purpose and subject to the terms of
this Notice.
TI’s provision of TI Resources does not expand or otherwise alter TI’s applicable published warranties or warranty disclaimers for TI
products, and no additional obligations or liabilities arise from TI providing such TI Resources. TI reserves the right to make corrections,
enhancements, improvements and other changes to its TI Resources.
You understand and agree that you remain responsible for using your independent analysis, evaluation and judgment in designing your
applications and that you have full and exclusive responsibility to assure the safety of your applications and compliance of your applications
(and of all TI products used in or for your applications) with all applicable regulations, laws and other applicable requirements. You
represent that, with respect to your applications, you have all the necessary expertise to create and implement safeguards that (1)
anticipate dangerous consequences of failures, (2) monitor failures and their consequences, and (3) lessen the likelihood of failures that
might cause harm and take appropriate actions. You agree that prior to using or distributing any applications that include TI products, you
will thoroughly test such applications and the functionality of such TI products as used in such applications. TI has not conducted any
testing other than that specifically described in the published documentation for a particular TI Resource.
You are authorized to use, copy and modify any individual TI Resource only in connection with the development of applications that include
the TI product(s) identified in such TI Resource. NO OTHER LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE TO
ANY OTHER TI INTELLECTUAL PROPERTY RIGHT, AND NO LICENSE TO ANY TECHNOLOGY OR INTELLECTUAL PROPERTY
RIGHT OF TI OR ANY THIRD PARTY IS GRANTED HEREIN, including but not limited to any patent right, copyright, mask work right, or
other intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information
regarding or referencing third-party products or services does not constitute a license to use such products or services, or a warranty or
endorsement thereof. Use of TI Resources may require a license from a third party under the patents or other intellectual property of the
third party, or a license from TI under the patents or other intellectual property of TI.
TI RESOURCES ARE PROVIDED “AS IS” AND WITH ALL FAULTS. TI DISCLAIMS ALL OTHER WARRANTIES OR
REPRESENTATIONS, EXPRESS OR IMPLIED, REGARDING TI RESOURCES OR USE THEREOF, INCLUDING BUT NOT LIMITED TO
ACCURACY OR COMPLETENESS, TITLE, ANY EPIDEMIC FAILURE WARRANTY AND ANY IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL
PROPERTY RIGHTS.
TI SHALL NOT BE LIABLE FOR AND SHALL NOT DEFEND OR INDEMNIFY YOU AGAINST ANY CLAIM, INCLUDING BUT NOT
LIMITED TO ANY INFRINGEMENT CLAIM THAT RELATES TO OR IS BASED ON ANY COMBINATION OF PRODUCTS EVEN IF
DESCRIBED IN TI RESOURCES OR OTHERWISE. IN NO EVENT SHALL TI BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL,
COLLATERAL, INDIRECT, PUNITIVE, INCIDENTAL, CONSEQUENTIAL OR EXEMPLARY DAMAGES IN CONNECTION WITH OR
ARISING OUT OF TI RESOURCES OR USE THEREOF, AND REGARDLESS OF WHETHER TI HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
You agree to fully indemnify TI and its representatives against any damages, costs, losses, and/or liabilities arising out of your non-
compliance with the terms and provisions of this Notice.
This Notice applies to TI Resources. Additional terms apply to the use and purchase of certain types of materials, TI products and services.
These include; without limitation, TI’s standard terms for semiconductor products http://www.ti.com/sc/docs/stdterms.htm), evaluation
modules, and samples (http://www.ti.com/sc/docs/sampterms.htm).

Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2018, Texas Instruments Incorporated

You might also like