We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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; } } }
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".
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.
hi friends!! can anybody help to configure systic timer to run for 1 sec only. currently it is running two times for every 1 sec