'XmegaE5 Clock Test V1.bas
'April 11, 2014, Bascom, JEC
'Test setting up the Xmega's Clock in several different configurations.
'Flash an LED as output.
'Hardware: Xmega32E5 DIP Module with an External 4.0 MHz Xtal.
'Hardware:
'Xmega32E5 DIP has Ports A, C, and D, Full Ports available.
'PortC.0 = LED1 Red
'PortC.1 = LED2 Yel
'PortC.2 = LED3 Grn
'-------------------------------------------------------------------------------
'Header:
$regfile = "xm32E5def.dat" 'Specify the uC
$crystal = 32000000 '32 MHz
$hwstack = 128 ' default use 32 for the hardware stack
$swstack = 128 ' default use 10 for the SW stack
$framesize = 128 ' default use 40 for the frame space
$map 'Debug Info
Led1 Alias Portc.0 'Led1 Red High is On
Led2 Alias Portc.1 'Led2 Yellow High is On
Led3 Alias Portc.2 'LED3 Green High is On
'Now Configure the Port's Pins for Input or Output mode.
'Config the General Digital I/O pins.
'The special purpose modules will config their own pins.
'Config Port C for the LEDs for now, skip PortA and PortD, default = All Input.
'Config PortC I/O for 3 LEDs:
Portc_pin0ctrl = &B00000000 'PortC.0 Control Totem Pole Output
Portc_pin1ctrl = &B00000000 'PortC.1 Control Totem Pole Output
Portc_pin2ctrl = &B00000000 'PortC.2 Control Totem Pole Output
Portc_dir.0 = 1 'PortC.0 = Output
Portc_dir.1 = 1 'PortC.1 = Output
Portc_dir.2 = 1 'PortC.2 = Output
'Define Variables:
Dim Ledlp As Byte 'Loop Counter
Dim Rvbit As Bit 'For Register Setup
Dim Regdata As Byte 'For Register Setup
'///////////////////////////////////////////////////////////////////////////////
Startup:
'Xmega Clock Initialization Routines:
'I can set up the Xmega clock using Bascom for a number of settings, as
'shown below, which work.
'But I can't get the Ext Xtal with PLL working using the Bascom Instructions.
'Clock: 2 MHz Internal 2 MHz RC, Direct, PLL NOT enabled. Works.
' Config Osc = Enabled
' Config Sysclock = 2mhz , Prescalea = 1 , Prescalebc = 1_1
'Clock: 8 MHz Internal 2 MHz RC, via PLL, with PLLx4. Works.
' Config Osc = Enabled , Pllosc = Enabled , Pllsource = Rc2mhz , Plldiv2 = Disabled , Pllmul = 4
' Config Sysclock = Pll , Prescalea = 1 , Prescalebc = 1_1
'Clock: 32 MHz Internal 2 MHz RC, via PLL, with PLLx16. Works.
' Config Osc = Enabled , Pllosc = Enabled , Pllsource = Rc2mhz , Plldiv2 = Disabled , Pllmul = 16
' Config Sysclock = Pll , Prescalea = 1 , Prescalebc = 1_1
'Clock: 32 MHz Internal 32 MHz RC, PLL Not enabled. Works.
' Config Osc = Enabled , 32mhzosc = Enabled
' Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
'FALIS: <<<<<<<<<<<<<<<<<<<<<<<
'Clock: 32 MHz External 4 MHz Xtal, PLL x 8
' Config Osc = Enabled , Pllosc = Enabled , Extosc = Enabled , Range = 2mhz_9mhz , Startup = Extclk , Pllsource = Extclock , Plldiv2 = Disabled , Pllmul = 8
' Config Sysclock = External , Prescalea = 1 , Prescalebc = 1_1
'Set up the Xmega clock. Works.
'Clock: 32 MHz, Run on External Xtal, 4 MHz, via the PLL x8.
'This MANUALLY turns on the Xmega PLL.
'Xmega runs at 2MHz on power up.
Osc_xoscctrl = 75 'Ext Osc: 2-9MHz, 16 K Clks
Osc_ctrl = 9 'PLL Off, Ext Xtal On, Int 2M OSC On
Clk_psctrl = 0 'No PreScaler in use, i.e. Div by 1
Osc_pllctrl = 200 'PLL: Ext Xtal, Div by 2 Off, PLL Multi x8
Waitms 1
Osc_ctrl = 25 'PLL ON, Ext Xtal Enabled, 2 MHz Int RC Osc also Enabled
Waitms 1
Cpu_ccp = 216 'Config Change Protection
Clk_ctrl = 4 'Use PLL as Clock Source
'Main: Just flash an LED at Approximately 1 Hz
Main:
Do
Set Led1
Waitms 100
Reset Led1
Waitms 900
Loop
|