This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

can you change systick configuration throughout the program?

I've written some code where leds light up in a sequence. I used the systick to trigger an interrupt and light up the next led in the sequence. I want to gradually increase the speed of the sequence so I tried reconfiguring the systick settings throughout the code, but the speed always remains the same as the first time I configured it.

Any ideas what I might be doing wrong?
Is it even possible to reconfigure systick and other setups multiple times??
Has it maybe got something to do with the 24-bit RELOAD and CURRENT values?

I really appreciate your responses, happy to take any suggestions :)


// snippit of main function

GPIO_Setup_B();
SetupSystick(6000000);
NVIC_ST_CTRL |= 0x1; // start timer
Delay(1000);
NVIC_ST_CTRL &= ~0x1; // stop timer
SetupSystick(3000000); // speed should double, but remains the same
NVIC_ST_CTRL |= 0x1; // start timer
Delay(1000);
NVIC_ST_CTRL &= ~0x1; // stop timer
SetupSystick(2000000);
NVIC_ST_CTRL |= 0x1; // start timer
Delay(1000);
NVIC_ST_CTRL &= ~0x1; // stop timer
SetupSystick(1000000);
NVIC_ST_CTRL |= 0x1; // start timer
Delay(1000);

// setup systick function
void SetupSystick(unsigned int time)
{
        NVIC_ST_CTRL &= ~0x1;
        NVIC_ST_RELOAD |= time;
        NVIC_ST_CURRENT |= time; // clear count status
        NVIC_ST_CTRL |= 0x6;
        NVIC_SYS_PRI3 &= ~0xE0000000;
        NVIC_SYS_PRI3 |= 0x40000000;
}

// systick ISR
void SysTick_Handler(void)
{
        if (updown == 1) {
                GPIOB_DATA <<= 0x1;
                if (GPIOB_DATA >= 0x10) {
                        updown = 0;
                }
        } else if (updown == 0) {
                GPIOB_DATA >>= 0x1;
                if (GPIOB_DATA <= 0x1) {
                        updown = 1;
                }
        }
}

Parents
  • I don't know, but an alternative (more conventional?) approach would be to just set the SysTick at the maximum speed required, and use this as a "timebase" to derive you variable timing in software.

    This is more like the way the SysTick is designed to be used - as the name suggests, a "System Tick".

Reply
  • I don't know, but an alternative (more conventional?) approach would be to just set the SysTick at the maximum speed required, and use this as a "timebase" to derive you variable timing in software.

    This is more like the way the SysTick is designed to be used - as the name suggests, a "System Tick".

Children