delay_ms timing is way off due to SysTick [SAME54_XPLAINED w/ASF4]

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I used an Atmel Start generated project, and I am using the following code to configure and enable systick:

 

 

    // Configure SysTick to trigger every millisecond using the CPU Clock
    SysTick->CTRL = 0;                    // Disable the SysTick Module
    SysTick->LOAD = 119999UL;                // Set the Reload Register for 1mS interrupts
    NVIC_SetPriority(SysTick_IRQn, 3);    // Set the interrupt priority to least urgency
    SysTick->VAL = 0;                    // Clear the Current Value register
    SysTick->CTRL = 0x00000007;        // Enable SysTick, Enable SysTick Exceptions, Use CPU Clock
    NVIC_EnableIRQ(SysTick_IRQn);        // Enable the SysTick Interrupt (Global)

 

 

When I run this code, my delay_ms function is off. 1 ms = roughly 4 ms for some reason.

 

I think this is because I added a delay driver in the Atmel Start generator, but added the SysTick stuff manually and they might be colliding somehow? Is there a way to turn systick on in Atmel Start that doesn't interfere with the delay driver?

This topic has a solution.

im a penguin

Last Edited: Thu. Feb 13, 2020 - 06:03 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PenguinWasHere wrote:

So I used an Atmel Start generated project, and I am using the following code to configure and enable systick:

 

 

    // Configure SysTick to trigger every millisecond using the CPU Clock
    SysTick->CTRL = 0;                    // Disable the SysTick Module
    SysTick->LOAD = 119999UL;                // Set the Reload Register for 1mS interrupts
    NVIC_SetPriority(SysTick_IRQn, 3);    // Set the interrupt priority to least urgency
    SysTick->VAL = 0;                    // Clear the Current Value register
    SysTick->CTRL = 0x00000007;        // Enable SysTick, Enable SysTick Exceptions, Use CPU Clock
    NVIC_EnableIRQ(SysTick_IRQn);        // Enable the SysTick Interrupt (Global)

 

 

When I run this code, my delay_ms function is off. 1 ms = roughly 4 ms for some reason.

 

I think this is because I added a delay driver in the Atmel Start generator, but added the SysTick stuff manually and they might be colliding somehow? Is there a way to turn systick on in Atmel Start that doesn't interfere with the delay driver?

 

Whoops. I didn't know I needed to call "delay_init(SysTick)".

im a penguin