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

Go To Last Post
5 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: 1

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

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot for posting the found solution afterwards, that was really helpful. This thing was driving me nuts.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have the same problem with delay_init(SysTick) to begin with. Also it looks like SysTick is not enabled when i stop the debugger after initialization. But i see there is delay of 4mS even if systick is not enabled. Not sure this driver is running on which timer. Did anyone resolve this issue? Any information is appreciated. 

 

Thanks in advance

 

Regards,

Rishit

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

rishitborad wrote:
it looks like SysTick is not enabled when i stop the debugger

That's usually a configuration option - whether timers stop or continue during a debugger halt.

 

Your other thread on the same topic: https://community.atmel.com/foru...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...