Hi
The standard timer in all M4/M0+ cores (rather than peripheral timers) is the SYSTICK. Often this is used as a periodic interrupt for the OS and then for SW timing.
It won't make 1s if the clock is high - about 335ms max. at 50MHz - but is probably the best one to start with. Generally one uses a higher rate TICK to generate longer SW delays from.
Below is code to configure it as a periodic timer interrupt:
eg. #define TICK_RESOLUTION 50 // 50ms TICK rate
// Routine to initialise the Tick interrupt (uses Cortex M4/M0+ SysTick timer)
//
#define REQUIRED_MS ((1000/TICK_RESOLUTION)) // the TICK frequency we require in kHz
#define TICK_DIVIDE (((CORE_CLOCK + REQUIRED_MS/2)/REQUIRED_MS) - 1) // the divide ratio required
extern void fnStartTick(void)
{
VECTOR_TABLE *ptrVect;
ptrVect = (VECTOR_TABLE *)(RAM_START_ADDRESS);
SYSTICK_RELOAD = TICK_DIVIDE; // set reload value to determine the period
ptrVect->ptrSysTick = _RealTimeInterrupt; // enter interrupt handler
SYSTEM_HANDLER_12_15_PRIORITY_REGISTER |= (SYSTICK_PRIORITY << 24); // enter the SYSTICK priority
SYSTICK_CSR = (SYSTICK_CORE_CLOCK | SYSTICK_ENABLE | SYSTICK_TICKINT); // enable timer and its interrupt
}
_RealTimeInterrupt() is called. You will need to fill out the register details depending on which headers you use.
static __interrupt void _RealTimeInterrupt(void)
{
INT_CONT_STATE_REG = PENDSTCLR; // reset interrupt
// + code
}
Regards
Mark