Quantcast
Viewing all articles
Browse latest Browse all 20599

BASCOM-AVR : Xmega TcD0 configuration results : REPLY

Entry2: Clockopt6: Here is an example of setting up the Xmega to use an external crystal and the PLL to double the clock frequency. This uses a 16 MHz crystal instead of a 14.x MHz crystal, which doesn't matter. The code is the same. Note that in this example I don't actually poll the register to see when the clock source is stable, I just put in a couple of wait 1 mSec delays. This works fine. I included another example Clockopt5 which does show how to read the internal register to see when the clock source is stable. This is a little bit faster than waiting for the 1 mSec delays used above. This is an example, it reads the status of the Internal 32 MHz, osc. The bit being read would have to be changed for the external crystal clock source if you wanted to do this for an external crystal. The point is you don't need to actually read the clock status if you just delay, but the above shows how to do so if you want to. You must change the code a little, however, to watch the correct clock source. Also, as you noted there are a number of clock dividers. The way to get a higher frequency is to use the PLL to multiply the clock to a higher frequency, then divide it down to what is desired. JC [code:1:e65351180a] Clockopt5: 'Set up the Xmega Clock. 'Run at 32 MHz from the Internal 32 MHz Osc, set by my code. 'Xmega runs on Int 2MHz Osc on Startup. 'This turns on the Int 32 MHz Osc, awaits it being ready, and switches to it. 'Don't forget the Configuration Change Register Protection Trigger before 'changing the uC's Clock Source. 'First turn ON the 32 MHz Int Osc: 'They wait until the Int 32 MHz Osc is ready to be used. Osc_ctrl = 2 'Int 32 MHz Osc ON Rvbit = 0 'Clear flag While Rvbit = 0 'Read the Int 32 MHz Osc Status Regdata = Osc_status 'Status of all Int Osc Sources Rvbit = Regdata.1 'Int 32 MHz Osc Status, 1 = Ready Wend Cpu_ccp = 216 'Config Change Protection Clk_ctrl = 1 'Use Int 32 MHz Osc Return Clockopt6: 'Set up the Xmega clock. 'Run on External Xtal, (16 MHz), at 32 MHz, via the PLL x2. 'This MANUALLY turns on the Xmega PLL. 'Xmega runs at 2MHz on power up. Osc_xoscctrl = 203 'Ext Osc: 12-16MHz, 16 K Clks Osc_ctrl = 9 'PLL Off, Ext Xtal On, Int 2M OSC On Clk_psctrl = 0 'No PreScaler in use Osc_pllctrl = 194 'PLL: Ext Xtal 16 MHz, Multi x2 Waitms 1 Osc_ctrl = 31 'PLL ON, All Osc Sources On Waitms 1 Cpu_ccp = 216 'Config Change Protection Clk_ctrl = 4 'Use PLL as Clock Source Return [/code:1:e65351180a]

Viewing all articles
Browse latest Browse all 20599

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>