generate 20MHz clock

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
octal
XCore Addict
Posts: 228
Joined: Thu Jan 27, 2011 3:30 pm
Location: Argenteuil - France

generate 20MHz clock

Post by octal »

Hello,
I'm fighting with XS1L at 400MHz with 20MHz crystal (I'm using an XK-1A), and I want to generate a 20MHz clock on a pin. I tried all fiddling with clock divisors, changing clock and refClock in the XN file ... but I can't got it to work. When I use for example a div == 5 do divide the 100MHz ref clock, I got an exception, I tried to change the RefClock to 80 or 320 and keep the div multiple of 4, but it doesn't work :(
can anyone give a hint on how to achieve that?

PS. I'm using a pin clocked by a clock block.

Regards


GerhardNorkus
Active Member
Posts: 55
Joined: Wed Jan 05, 2011 2:15 pm

Post by GerhardNorkus »

If you can deal with using a slower reference frequency, you can achieve the desired result using the following.

1. Change the reference frequency in the XN file to 80MHz (there are other ways but this is easiest). Look at the first "Node Id" in the following sample XN file.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Network xmlns="http://www.xmos.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xmos.com http://www.xmos.com">
  <Type>Board</Type>
  <Name>XK-1A Development Board</Name>
  <BoardId>0005021X</BoardId>

  <Declarations>
    <Declaration>tileref tile[1]</Declaration>
  </Declarations>

  <Packages>
    <Package id="0" Type="XS1-L1A-TQ128">
      <Nodes>
        <Node Id="0" InPackageId="0" Type="XS1-L1A" Oscillator="20MHz" SystemFrequency="400MHz" ReferenceFrequency="80MHz">
          <Boot>
            <Source Location="SPI:bootFlash"/>
          </Boot>
          <Tile Number="0" Reference="tile[0]">
            <Port Location="XS1_PORT_1I" Name="PORT_UART_RX"/>
            <Port Location="XS1_PORT_1J" Name="PORT_UART_TX"/>
    
            <Port Location="XS1_PORT_1K" Name="PORT_BUT_1"/>
            <Port Location="XS1_PORT_1L" Name="PORT_BUT_2"/>
    
            <Port Location="XS1_PORT_1M" Name="PORT_SPI_MISO"/>
            <Port Location="XS1_PORT_1N" Name="PORT_SPI_SS"/>
            <Port Location="XS1_PORT_1O" Name="PORT_SPI_CLK"/>
            <Port Location="XS1_PORT_1P" Name="PORT_SPI_MOSI"/>

            <Port Location="XS1_PORT_4F" Name="PORT_LED"/>
          </Tile>
        </Node>
      </Nodes>
    </Package>
  </Packages>

  <Links>
  </Links>

  <ExternalDevices>
    <Device NodeId="0" Tile="0" Class="SPIFlash" Name="bootFlash" Type="AT25FS010">
      <Attribute Name="PORT_SPI_MISO" Value="PORT_SPI_MISO"/>
      <Attribute Name="PORT_SPI_SS"   Value="PORT_SPI_SS"/>
      <Attribute Name="PORT_SPI_CLK"  Value="PORT_SPI_CLK"/>
      <Attribute Name="PORT_SPI_MOSI" Value="PORT_SPI_MOSI"/>
    </Device>
  </ExternalDevices>

  <JTAGChain>
     <JTAGDevice NodeId="0"/>
  </JTAGChain>

</Network>
2. Set up your clock with the correct divider using configure_clock_rate. Here is an XC example

Code: Select all

// Copyright (c) 2011, XMOS Ltd., All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>
/*
 ============================================================================
 Name        : $(sourceFile)
 Description : Sample Clock program for the XK-1 board 
 ============================================================================
 */

#include <xs1.h>

out port led = XS1_PORT_1D;
clock g_refclk = XS1_CLKBLK_1 ;

int main(void)
{
    configure_clock_rate (g_refclk,  80,4);  // 20MHz
    configure_port_clock_output (led, g_refclk ) ;
    start_clock (g_refclk);
    while (1) ;
    return 0;
}
User avatar
octal
XCore Addict
Posts: 228
Joined: Thu Jan 27, 2011 3:30 pm
Location: Argenteuil - France

Post by octal »

Hi GerhardNorkus,
I already tried adding the ReferenceFrequency and setting it to 80 (and later to 320 and 400) MHz, but it didn't worked. I'll try again today by night and post any results.

Thx
User avatar
octal
XCore Addict
Posts: 228
Joined: Thu Jan 27, 2011 3:30 pm
Location: Argenteuil - France

Post by octal »

Well,
just tried it. It worked correctly. My mistake was that the XN file was not in my project. I had to right click on it and "IMPORT" it into the project to make things works as expected.

Thank you for your help :)
GerhardNorkus
Active Member
Posts: 55
Joined: Wed Jan 05, 2011 2:15 pm

Post by GerhardNorkus »

No problem..

But if I only had $1 for every time I did the same thing...

: )
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

The joys of IDEs :-P

Btw, how would 320MHz work? With a system clock of
400MHz you could use a reference clock of 20, 40, 80,
200, or 400MHz, but no others, if I did the back-of-envelope
right?
GerhardNorkus
Active Member
Posts: 55
Joined: Wed Jan 05, 2011 2:15 pm

Post by GerhardNorkus »

I assume he tried to adjust the PLL by using the sswitch setting functions.

By the way, Segher, can you check my may 2ND posts? You actually came close to a solution for me in a previous post.....
User avatar
octal
XCore Addict
Posts: 228
Joined: Thu Jan 27, 2011 3:30 pm
Location: Argenteuil - France

Post by octal »

GerhardNorkus wrote:I assume he tried to adjust the PLL by using the sswitch setting functions.
+1
I done (in desperation) it when adding the attribute ReferenceFreq didn't worked (cause XN was not in the project).