2012-04-05 09:43 AM
My application calls for using an external oscillator (not a crystal) as a clock source. To test this, I have an arbitrary function generator outputting a 50% duty cycle square wave of the expected clock rate. The MCU is supposed to go to sleep, then upon wake up, switch to the HSE as fast as possible.
However, in tests, I find that switching to the HSE is always taking somewhere around 2.5ms. The function generator is always on, so I was expecting sub millisecond switching. Here's what I'm doing:Is there something I'm doing wrong that's causing up to 2.5ms delay? I recall when I had a regular crystal oscillator, it was adding about 1ms or so.
EDIT: I found the args for RCC_HSEConfig() are supposed to be RCC_HSE_ON or RCC_HSE_Bypass, and I'm not sure what ENABLE is defined as.2012-04-05 10:42 AM
I'm hard pressed to see why you would need RCC_HSE_ON, it's not like you need the oscillator circuit running for an external TCXO or whatever.
The system will come up with HSI, whatever time it takes that to start/stabilize. But you should just be able to grind the gears and jam the SYSCLK directly to HSE, thus : RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); /* Select HSE as system clock source */ /* Wait till HSE is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x04); // HSI 00, HSE 04, PLL 08 Should only take a couple of minutes coding to confirm if it is viable, or not.2012-04-09 09:41 AM
Thanks for your response.
It appears I misunderstood what was wanted out of the board, so I'm not using the HSE as the system clock. In fact, there was no intent on using the HSE. But a guy I spoke to about this thinks the hardware for the HSE is shut off when I go into STOP mode, and when I exit out of STOP mode, the HSE hardware needs to turn on and figure out what's the clock speed. And he thinks the wakeup time is dependent upon the speed of the clock.2012-04-09 10:04 AM
Wakeup Latency from STOP - ''HSI RC wakeup time + regulator wakeup time from Low-power mode''
HSI is spec'd to come up in 1-2 us LSI is up to 85 us Wakeup from STOP (reg in run mode) typical 3.6 us Wakeup from STOP (reg in low power mode) typical 5.4 us If you use the PLL, it's lock time is typically 200 us HSE has a typical startup time of 2 ms after VDD stabilizes, but is hugely dependent on the properties of the crystal. I can't find a number quickly for switching clocks, but the circuit probably uses some simple synchronization techniques to avoid glitching as it switches over, which might equate to a couple of clocks at the slowest rate. At a guess, less than a micro-second. The main purpose of waiting in the spin loop is probably to assure the thing is actually clocking.