Clock Speed change from external xtal to internal RC and back again to external xtal
JohnR2010
Posts: 431
The Propeller manual talks about a three step process when changing clock speed from the internal RC to an external crystal. It says you need to set the PLLENA, OSCENA, and OSCM registers wait 10ms and then set the CLK register. Does anyone have a good example of this process? I was looking at the clock speed code for the DefCon Badge and I cant see they are doing any type of 3 step process. I have tried setting the clock speeds as laid out in the DefCon and I cant change the speed from external crystal to internal RC.
I'm sure this has been asked and answered and before someone jumps on me I searched and read through a ton of posts and haven't come up with a clean solution this cant be more than 4 or 5 lines of code. Little frustrated I have to ask this question going to walk away and come back. Arrrgggg I should be able to figure it out on my own!!
Thanks
I'm sure this has been asked and answered and before someone jumps on me I searched and read through a ton of posts and haven't come up with a clean solution this cant be more than 4 or 5 lines of code. Little frustrated I have to ask this question going to walk away and come back. Arrrgggg I should be able to figure it out on my own!!
Thanks
Comments
Edit: I see before using "SetClock" you have to use the "Init" method to let the object know what crystal you're using.
Yep that is what Im using. I can go from fast to slow. The problem I'm having is going from slow back to fast (external crystal).
Here is how I go from Fast to Slow:
clkset(0_0_0_00_001, 20_000) ' Set Clock speed slow
Here is what I'm trying to get to work to get me back to fast speed.
clkset(%0_1_1_01_001, 20_000) ' Turn on external crystal
waitcnt(cnt + (clkfreq / 100)) ' wait ~10ms
clkset(%0_1_1_01_111, 80_000_000) ' Set Clock back to high speed
I have also just tried the last clkset line without the two steps before it.
I know Im missing something.
Edit Sorry I thought you were talking about the Clkset command. I hate to have an object to change the clock speed. I will take a look at how they do it. Thanks.
I used these constants.
I used what looks like a modified clock object.
I think I just added the minimum wait amount (381) to the pause method(s). I'm just about positive the code below would work with the original version of the object.
I called Init.
To put the Prop in what I called "sleep" mode I used:
This is my "WakeUp" method.
It also contained additional housekeeping items.
I also shut down all but one cog in sleep mode and would start these cogs back up with the "WakeUp" method.
I didn't feel the need to understand how the method "SetClock" works but it looks like it's pretty well commented.
[/FONT][/SIZE]
[/FONT][/SIZE]
Is there a way I can give you a vote up in this forum? I'm used to a forum (http://stackoverflow.com) where you can give people points for helping! You and others have helped me several times and I cant see where I can do that with this forum.
Thanks Jon I looked at your code just before I posted this question on the forum. My program needs to switch clock speeds several times, I go from 80MHz to the slow internal clock (20kHz) for sleep mode and then wake up and switch back to 80Mhz. I think your 10ms delay needs to be increased when you are switching from 20kHz back out to the external crystal and oscillator circuit. My delay was also 10ms and it didn't work. Tracy gave me sample code in where it switches to RCFast 12MHz to turn on the external crystal circuit, waits 10ms and then jumps out to the Crystal for the 5MHz * 16 = 80MHz. I couldn't do this with the 10ms delay at 20kHZ but I could at 12MHz.
So to recap:
To go from fast (80MHz) external clock to internal slow (20kHz) I made this call:
To go back to 80MHz I had to follow this process:
Have you tried using your method to go from 20kHZ to 80MHz?
Thanks for posting your code!!
Useful code execution can happen during the RCfast phase while waiting for the xtal to spin up. Anything involving spi or i2c such as reading a clock chip. In some cases I have RCfast inside the low power loop, and code executed there informs the decision of whether or not to go to higher speeds and timing accuracy.
I know you use the serial port a lot for your zigbee and other things. Be sure to clear all the transmit buffers (txflush(port)+one character delay) before dropping the clock speed.