CVS: examples/libraries/fll README.txt,NONE,1.1 main.c,NONE,1.1 makefile,NONE,1.1

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/examples/libraries/fll
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26361/examples/libraries/fll

Added Files:
	README.txt main.c makefile 
Log Message:
fll_adjust usage example

--- NEW FILE: README.txt ---
Software Frequency Locked Loop (FLL)
====================================

Overview
--------
It is a simple example project for the MSP430 series MCU, the GCC port
of the mspgcc project and libmspgcc.

Features:

- Adjust DCO clock suing a watch crystal

- Makefile

  - compile and link with libmspgcc
  - convert to intel hex format
  - generate a listing with mixed C / assembly



Required hardware
-----------------

- A MSP430F1121 or larger device (any from the F1x series)

- A watch crystal (32768Hz) on XT1

- An oscilloscope or frequency counter to measure the resulting
  frequency (optional)

Disclaimer
----------
This example is part of the mspgcc project http://mspgcc.sf.net.
See license.txt_ for details.

chris

.. _license.txt: ../../license.html

--- NEW FILE: main.c ---
/* Demo application for the fll_adjust function from libmspgcc.
 *
 * A MCLK/SMCLK frequency of 2.0Mhz is set using a watch crystal.
 * The frequency can be verified on P1.4. it is divided by 8 to make
 * it easier to measure.
 *
 *                MSP430F1121
 *             -----------------
 *         /|\|              XIN|-  
 *          | |                 | 32kHz
 *          --|RST          XOUT|-
 *            |                 |
 *            |             P1.4|-->SMCLK out (250kHz expected)
 *        
 * (c) 2005,  chris <[email protected]>
 */

#include <io.h>
#include <signal.h>
#include <mspgcc/util.h>                // delay()
#include <mspgcc/fll.h>

 int main(void) {
    WDTCTL = WDTPW|WDTHOLD;             // stop watchdog timer

    // enable SMCLK out
    // note: it would be better to enable the output after the
    // frequency has been set with fll_adjust. but enabling
    // it here gives a chance to watch the FLL working on the
    // oscilloscope
    P1DIR = BIT4;
    P1SEL = BIT4;
    
    // select watch crystal, MCLK and SMCLK from DCO
    BCSCTL1 = XT2OFF|RSEL2|DIVA_DIV4;   // select 8192 Hz from XT1
    BCSCTL2 = 0;

    // fist make a delay, to give the oscillator time to settle
    delay(0xffff);
    delay(0xffff);
    
    // run the clock adjustment. This function sets the
    // ratio from ACLK to SMCLK. The divider on SMCLK is set
    // up later, below.
    fll_adjust(FLL_MULTIPLIER(2000000, 8192)); // adjust frequency
    
    // now divide the signal on the output
    BCSCTL2 = DIVS_3;                   // divide SMCLK by 8

    // wait here until the end of the world ;-)
    while (1) {
        LPM0;
    }
}

--- NEW FILE: makefile ---
# makfile configuration
NAME            = fll_demo
CSOURCES        = main.c
#~ ASOURCES        = 
CPU             = msp430x1121


ASFLAGS         = -mmcu=${CPU} -D_GNU_ASSEMBLER_ -I .
CFLAGS          = -mmcu=${CPU} -O2 -Wall -g --std=gnu99 -I .
LDFLAGS         =  -lmspgcc

#switch the compiler (for the internal make rules)
CC              = msp430-gcc
AS              = msp430-gcc

OBJECTS         = ${CSOURCES:.c=.o} ${ASOURCES:.S=.o}


.PHONY: all FORCE clean download download-jtag download-bsl

#all should be the first target. it's built when make is run without args
all: ${NAME}.elf ${NAME}.a43 ${NAME}.lst dependencies.d

#confgigure the next line if you want to use the serial download
download: download-jtag
#~ download: download-bsl

#additional rules for files
${NAME}.elf: ${OBJECTS}
	${CC} -mmcu=${CPU} -o $@ ${OBJECTS} $(LDFLAGS)

${NAME}.a43: ${NAME}.elf
	msp430-objcopy -O ihex $^ $@

${NAME}.lst: ${NAME}.elf
	msp430-objdump -dSt $^ >$@
	@echo "----- RAM/Flash Usage -----"
	msp430-size $^

download-jtag: all
	msp430-jtag -e ${NAME}.elf

download-bsl: all
	msp430-bsl $(BSLOPT) -e ${NAME}.elf

clean:
	rm -f ${NAME}.elf ${NAME}.a43 ${NAME}.lst ${OBJECTS} dependencies.d

#dummy target as dependecy if something has to be build everytime
FORCE:

#project dependencies
dependencies.d:
	$(CC) -MM ${CFLAGS} ${CSOURCES} > dependencies.d
ifdef ASOURCES
	$(CC) -MM ${ASFLAGS} ${ASOURCES} >> dependencies.d
endif

-include dependencies.d


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.