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; } } }
Thanks for your reply! I was just thinking about that as well, it makes much more sense to do it that way.
Still curious if its possible to reconfigure things... even there's probably always a better alternative haha
I don't think there is a write-lock on the system tick. But I would recommend to use it at a fixed frequency and have other things happen every n ticks.
Just wondering - will the below code work with |= to reconfigure something that already is configured?
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;
If NVIC_ST_RELOAD is mapping to the actual register, then |= would only work if some other part of the code first clears the reload bits.
True looks like I'm just setting the bits, woops! Thanks for picking up on that.