Read the SysTick_Wait subroutine and answer the following questions. 1) What val
ID: 3602677 • Letter: R
Question
Read the SysTick_Wait subroutine and answer the following questions.
1) What values should be passed into the subroutine through R0 if we want a time delay of 25ms, 40ms and 100ms, respectively?
2) If the core clock was changed to 16 MHz, What values should be passed into the subroutine through R0 if we want a time delay of 25ms, 40ms and 100ms, respectively?
3) What is the maximum time delay that can be provided by the subroutine?
; Time delay using busy wait.
; Input: R0 delay parameter in units of the core clock 80 MHz(12.5 ns each tick)
; Output: none
SysTick_Wait
SUB R0, R0, #1 ; delay-1
LDR R1, =NVIC_ST_RELOAD_R
STR R0, [R1] ; time to wait
LDR R1, =NVIC_ST_CURRENT_R
STR R0, [R1] ; any value written to CURRENT clears
LDR R1, =NVIC_ST_CTRL_R
SysTick_Wait_loop
LDR R0, [R1] ; read status
ANDS R0, R0, #0x00010000 ; bit 16 is COUNT flag
BEQ SysTick_Wait_loop ; repeat until flag set
BX LR
Explanation / Answer
#define NVIC_ST_CTRL_R(*((volatile uint32_t *)0xE000E010))
#define NVIC_ST_RELOAD_R(*((volatile uint32_t *)0xE000E014))
#define NVIC_ST_CURRENT_R(*((volatile uint32_t *)0xE000E018))
void SysTick_Init(void){
NVIC_ST_CTRL_R = 0; // 1) disable SysTick during setup
NVIC_ST_RELOAD_R = 0x00FFFFFF; // 2) maximum reload value
NVIC_ST_CURRENT_R = 0; // 3) any write to CURRENT clears it
NVIC_ST_CTRL_R = 0x00000005; // 4) enable SysTick with core clock }
// The delay parameter is in units of the 80 MHz core clock(12.5 ns)
void SysTick_Wait(uint32_t delay){
NVIC_ST_RELOAD_R = delay-1; // number of counts
NVIC_ST_CURRENT_R = 0; // any value written to CURRENT clears
while((NVIC_ST_CTRL_R&0x00010000)==0){ // wait for flag } }
// Call this routine to wait for delay*10ms
void SysTick_Wait10ms(uint32_t delay){
unsigned long i; for(i=0; i<delay; i++){ SysTick_Wait(800000); // wait 10ms }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.