MSP430F5XX_中文翻译第三章_UCS
- 格式:doc
- 大小:453.71 KB
- 文档页数:18
MSP430混合信号微控制器数据手册产品特性●低电压范围:2.5V~5.5V 超低功耗●超低功耗——活动模式:330μA at 1MHz, 3V——待机模式:0.8μA——掉电模式(RAM数据保持):0.1μA ●从待机模式唤醒响应时间不超过6μs ●16位精简指令系统,指令周期200ns ●基本时钟模块配置基本时钟模块配置——多种内部电阻——多种内部电阻——单个外部电阻——单个外部电阻——32kHz晶振晶振——高频晶体——高频晶体——谐振器——谐振器——外部时钟源——外部时钟源●带有三个捕获/比较寄存器的16位定时器(Timer_A)串行在线可编程●串行在线可编程●采用保险熔丝的程序代码保护措施采用保险熔丝的程序代码保护措施该系列产品包括●该系列产品包括——MSP430C111:2K字节ROM,128字节RAM ——MSP430C112:4K字节ROM,256字节RAM ——MSP430P112:4K字节OTP,256字节RAM 原型●EPROM原型——PMS430E112:4KB EPROM, 256B RAM ●20引脚塑料小外形宽体(SOWB)封装,20引脚陶瓷双列直插式(CDIP)封装(仅EPROM)●如需完整的模块说明,请查阅MSP430x1xx系列用户指南(文献编号:SLAU049 产品说明TI公司的MSP43O系列超低功耗微控制器由一些基本功能模块按照不同的应用目标组合而成。
在便携式测量应用中,这种优化的体系结构结合五种低功耗模式可以达到延长电池寿命的目的。
以达到延长电池寿命的目的。
MSP430MSP430系列的CPU 采用16位精简指令系统,集成有16位寄存器和常数发生器,发挥了最高的代码效率。
它采用数字控制振荡器(DCO DCO)),使得从低功耗模式到唤醒模式的转换时间小于6μs.MSP430x11x 系列是一种超低功耗的混合信号微控制器,系列是一种超低功耗的混合信号微控制器,它拥有一个内置的它拥有一个内置的16位计数器和14个I/0引脚。
MSP430F54系列UCS时钟1:UCS(Unified Clock System)包含5 个时钟源:XT1CLK:可以用于低频率的32.768KHZ 或者4~32MHZ 的频率。
但不是每一个设备都支持高频率的,有些只支持32.768KHZ。
VLOCLK:内部低功耗,低频率的时钟,典型值为10KHZ。
REFOCLK:内部时钟,典型值32.768KHZ。
DCOCLK: Internal digitally-controlled oscillator (DCO) that can be stabilized by the FLL。
XT2CLK:高频时钟源,外部时钟,4 MHz 到32 MHz。
2:我们可用的从UCS 模块出来的3 个时钟:ACLK:辅助时钟。
MCLK:主时钟。
;SMCLK:系统子时钟。
3:时钟操作:After a PUC, the UCS module default configuration is:1)XT1 in LF mode is selected as the oscillator source for XT1CLK. XT1CLK is selected for ACLK.2)DCOCLKDIV is selected for MCLK.3)DCOCLKDIV is selected for SMCLK.4)FLL operation is enabled and XT1CLK is selected as the FLL reference clock, FLLREFCLK.5 )XIN and XOUT pins are set to general-purpose I/Os and XT1 remains disabled until the I/O ports areconfigured for XT1 operation.6 )When available, XT2IN and XT2OUT pins are set to general-purpose I/Os and XT2 is disabled.4:设置时钟的相关寄存器:。
msp430f5419/38学习笔记之时钟系统(2011-11-30 10:41:30)分类: msp430标签:msp430f541xmsp430f543xucs时钟系统注:msp5419/38中,如果你使用SMCLK做TIMER_A的时钟,那么进入低功耗3或低功耗4是不会把SMCLK关掉的,这点5系列和其他系列的不一样。
UCS模块是一个低成本超低功耗系统,通过选择使用3个内部时钟信号,用户可以得到性能和功耗的最佳平衡点。
UCS可以由软件配置其工作模式,如配置成:不需要任何外部器件、使用1或 2个外部晶振等。
一、时钟系统UCS模块具有5个时钟源:XT1CLK:低频/高频振荡器,既可以与低频 32768HZ钟振、标准晶振、外部振荡器,又可以与外部4M-32MHZ时钟源一起使用,XT1CLK可以作为FLL模块内部的参考时钟。
有些芯片XT1CLK只允许使用外部的低频晶振,具体可参考数据手册;XT2CLK:可选高频振荡器,可与标准晶振,振荡器或者 4MHZ~32MHZ外部时钟源一起使用;VLOCLK:内部低功耗、低频振荡器,频率典型值为10KHZ;REFOCLK:内部低频振荡器,典型值为 32768HZ,可作为 FLL基准时钟源;DCOCLK:可以通过 FLL来稳定的内部数字控制振荡器(DCO);DCOCLK经过 FLL分频后可得DCOCLKDIV。
UCS模块可以提供3种时钟信号:ACLK:辅时钟;MCLK:系统主时钟;SMCLK:子系统主时钟。
二、UCS操作PUC之后,UCS的默认配置模式如下:XT1CLK 选择LF模式下的XT1作为时钟源,ACLK 选择 XT1CLK 作为时钟源;MCLK 选择DCOCLKDIV作为时钟源;SMCLK 选择DCOCLKDIV作为时钟源;FLL操作使能,FLL基准时钟(FLLREFCLK)选择XT1CLK;XIN 和 XOUT作普通IO 口使用,禁止了 XT1 功能,直到 I/O 口重新配置为 XT1 模式;如果有 XT2IN 和XT2OUT,则一并配置为普通 IO 口,禁止 XT2 功能。
MSP430F552X中文手册及例程一、先写一篇开个头:这样快速闯入MSP430学习过程进入各个电子产品公司的网站,招聘里面嵌入式占据了大半工程师职位。
广义的嵌入式无非几种:传统的什么51单片机、 MSP430称做嵌入式微控制器;ARM是嵌入式微处理器;当然还有DSP;FPGA。
我们现在就不说别的,就说MSP430单片机,多数想学MSP430的童鞋,对89C51内核系列的单片机是很熟悉的,为了加深对MSP430 系列单片机的认识吗,迅速闯入MSP430学习过程,就必须彻底了解MSP430单片机,我们不妨将51单片机和MSP430两者进行一下比较。
第一点, 51内核单片机是8 位单片机。
其指令是采用的被称为“ CISC ”的复杂指令集,共具有111 条指令。
而MSP430 单片机是16 位的单片机,采用了精简指令集( RISC )结构,只有简洁的27 条指令,大量的指令则是模拟指令,众多的寄存器以及片内数据存储器都可参加多种运算。
这些内核指令均为单周期指令,功能强,运行的速度快。
第二点,MCU主要分为两种工作模式:待机与执行。
51内核单片机正常情况下消耗的电流为mA级 ,在掉电状态下,其耗电电流仍约为3mA左右 ;即使在掉电方式下,电源电压可以下降到2V ,但是为了保存内部RAM 中的数据,还需要提供约50uA的电流。
而430单片机功耗是在uA级的,工作电流极小,并且超低功耗,关断状态下的电流仅为0.1μA,待机电流为0.8μA,常规模式下的(250μA/1MIPS@3V),端口漏电流不足50 nA,并可零功耗掉电复位(BOR)。
另外,该芯片属低电器件,仅需1.8~3.6V电压供电,因而可有效降低系统功耗。
MSP430将低功耗模式扩展为7种,分别对应不同应用场合及任务的低功耗方式。
以睡眠模式为例,包括深度睡眠模式RTC:只有时钟在跑而其他都不动,目前,TI宣布其MSP430在RTC模式下最低功耗仅为360nA。
MSP430Microcontroller BasicsMSP430Microcontroller Basics John H.DaviesAMSTERDAM•BOSTON•HEIDELBERG•LONDONNEW YORK•OXFORD•PARIS•SAN DIEGOSAN FRANCISCO•SINGAPORE•SYDNEY•TOKYONewnes is an imprint of ElsevierNewnes is an imprint of Elsevier30Corporate Drive,Suite400,Burlington,MA01803,USALinacre House,Jordan Hill,Oxford OX28DP,UKCopyright©2008,Elsevier Ltd.All rights reserved.No part of this publication may be reproduced,stored in a retrieval system,or transmitted in any formor by any means,electronic,mechanical,photocopying,recording,or otherwise,without the prior written permission of the publisher.Permissions may be sought directly from Elsevier’s Science&Technology Rights Department in Oxford, UK:phone:(+44)1865843830,fax:(+44)1865853333,E-mail:************************.You may also complete your request online via the Elsevier homepage()by selecting “Support&Contact”then“Copyright and Permission”and then“Obtaining Permissions.”Recognizing the importance of preserving what has been written,Elsevier prints itsbooks on acid-free paper whenever possible.Library of Congress Cataloging-in-Publication DataApplication submittedBritish Library Cataloguing-in-Publication DataA catalogue record for this book is available from the British Library.ISBN:978-0-7506-8276-3For information on all Newnes publications,visit our Web site at:08091011121310987654321Printed in the United States of America“To Elizabeth.”ContentsPreface (xi)Chapter1:Embedded Electronic Systems and Microcontrollers (1)1.1What(and Where)Are Embedded Systems? (1)1.2Approaches to Embedded Systems (2)1.3Small Microcontrollers (5)1.4Anatomy of a Typical Small Microcontroller (8)1.5Memory (11)1.6Software (15)1.7Where Does the MSP430Fit? (16)Chapter2:The Texas Instruments MSP430 (21)2.1The Outside View—Pin-Out (21)2.2The Inside View—Functional Block Diagram (24)2.3Memory (25)2.4Central Processing Unit (30)2.5Memory-Mapped Input and Output (32)2.6Clock Generator (33)2.7Exceptions:Interrupts and Resets (36)2.8Where to Find Further Information (37)Chapter3:Development (43)3.1Development Environment (44)3.2The C Programming Language (46)3.3Assembly Language (55)3.4Access to the Microcontroller for Programming and Debugging (57)3.5Demonstration Boards (59)3.6Hardware (64)3.7Equipment (65)viii ContentsChapter4:A Simple Tour of the MSP430 (67)4.1First Program on a Conventional Desktop Computer (68)4.2Light LEDs in C (70)4.3Light LEDs in Assembly Language (72)4.4Read Input from a Switch (80)4.5Automatic Control:Flashing Light by Software Delay (91)4.6Automatic Control:Use of Subroutines (99)4.7Automatic Control:Flashing Light by Polling Timer_A (105)4.8Header Files and Issues Brushed under the Carpet (114)Chapter5:Architecture of the MSP430Processor (119)5.1Central Processing Unit (119)5.2Addressing Modes (125)5.3Constant Generator and Emulated Instructions (131)5.4Instruction Set (132)5.5Examples (146)5.6Reflections on the CPU and Instruction Set (153)5.7Resets (157)5.8Clock System (163)Chapter6:Functions,Interrupts,and Low-Power Modes (177)6.1Functions and Subroutines (178)6.2What Happens when a Subroutine Is Called? (178)6.3Storage for Local Variables (179)6.4Passing Parameters to a Subroutine and Returning a Result (183)6.5Mixing C and Assembly Language (185)6.6Interrupts (186)6.7What Happens when an Interrupt Is Requested? (188)6.8Interrupt Service Routines (190)6.9Issues Associated with Interrupts (196)6.10Low-Power Modes of Operation (198)Chapter7:Digital Input,Output,and Displays (207)7.1Digital Input and Output:Parallel Ports (208)7.2Digital Inputs (216)7.3Switch Debounce (225)7.4Digital Outputs (238)7.5Interface between3V and5V Systems (243)7.6Driving Heavier Loads (247)7.7Liquid Crystal Displays (252)7.8Driving an LCD from an MSP430x4xx (256)7.9Simple Applications of the LCD (264)Contents ix Chapter8:Timers (275)8.1Watchdog Timer (276)8.2Basic Timer1 (281)8.3Timer_A (287)8.4Measurement in the Capture Mode (300)8.5Output in the Continuous Mode (318)8.6Output in the Up Mode:Edge-Aligned Pulse-Width Modulation (330)8.7Output in the Up/Down Mode:Centered Pulse-Width Modulation (349)8.8Operation of Timer_A in the Sampling Mode (352)8.9Timer_B (353)8.10What Timer Where? (356)8.11Setting the Real-Time Clock:State Machines (357)Chapter9:Mixed-Signal Systems:Analog Input and Output (369)9.1Comparator_A (371)9.2Analog-to-Digital Conversion:General Issues (393)9.3Analog-to-Digital Conversion:Successive Approximation (402)9.4The ADC10Successive-Approximation ADC (407)9.5Basic Operation of the ADC10 (412)9.6More Advanced Operation of the ADC10 (424)9.7The ADC12Successive-Approximation ADC (432)9.8Analog-to-Digital Conversion:Sigma–Delta (438)9.9The SD16_A Sigma–Delta ADC (446)9.10Operation of SD16_A (459)9.11Signal Conditioning and Operational Amplifiers (475)9.12Digital-to-Analog Conversion (485)Chapter10:Communication (493)10.1Communication Peripherals in the MSP430 (495)10.2Serial Peripheral Interface (497)10.3SPI with the USI (504)10.4SPI with the USCI (513)10.5A Thermometer Using SPI in Mode3with the F2013as Master (520)10.6A Thermometer Using SPI in Mode0with the FG4618as Master (526)10.7Inter-integrated Circuit Bus (534)10.8A Simple I²C Master with the USCI_B0on a FG4618 (542)10.9A Simple I²C Slave with the USI on a F2013 (549)10.10State Machines for I²C Communication (559)10.11A Thermometer Using I²C with the F2013as Master (567)10.12Asynchronous Serial Communication (574)10.13Asynchronous Communication with the USCI_A (581)x Contents10.14A Software UART Using Timer_A (590)10.15Other Types of Communication (599)Chapter11:The Future:MSP430X (601)11.1Architecture of the MSP430X (601)11.2Instruction Set of the MSP430X (607)11.3Where Next? (614)11.4Conclusion (617)Appendix A:Kickstarting the MSP430 (619)A.1Introduction to EW430 (619)A.2Developing a Project in C (621)A.3Debugging with the Simulator (627)A.4Debugging with the Emulator (630)A.5Developing a Project in Assembly Language (633)A.6Tips for Using EW430 (636)A.7Tips for Specific Development Kits (640)Appendix B:Further Reading (645)Books and Articles (645)Newsletters,Magazines,and Journals (651)Index (655)Preface About a decade ago,I took over the teaching of afirst-year,second-semester course on digital electronics.It coveredflip-flops,counters,and state machines,all built fromsmall-scale integrated circuits.One of the projects at the end was to build a digital die.In many ways it was an excellent exercise because there were so many feasible ways in which it could be approached—simple counters,Johnson counters,or state machines.My concern was that it was very close to the project that I had experienced in myfirst course on digital electronics,which was back in the mid-1970s.The technology was close to the state of the art then,but was it still appropriate after so many years?Another feature of our course is that it is taken not only by electronic engineers but also by students from the science faculty,mostly computer scientists.I wanted these students to leave with a feeling for what can readily be done with modern programmable electronics insmaller-scale systems.I therefore replaced the material in the second half of the course with microcontrollers.(Do not worry,state machines were not abandoned—they are taught with hardware description languages in the context of programmable logic devices.) More recently,I thought that the time had come to review the choice of microcontroller. We traditionally used8-bit processors because modern devices have versatile peripherals and sophisticated embedded emulation and are quite powerful enough for most applications.Then the Texas Instruments MSP430caught my eye.A problem with8-bit microcontrollers is that8bits are too few for addresses,which are typically16bits long, and this means that data and addresses cannot be treated on an equal footing.In contrast, the MSP430has a uniform,16-bit architecture throughout:The address bus,data bus,and registers in the CPU are all16bits wide.The CPU has a modern design with plenty of registers,most of which can be used equally for data or addresses.It has a small instruction set with orthogonal addressing and an ingenious constant generator,which is used to emulate many operations that would otherwise need their own,distinct instructions.In many ways these features make the16-bit MSP430simpler than a typical8-bit processor.xii PrefaceOf course an elegant architecture does not generate many sales in the real world.More important are the range of peripherals and development tools.The MSP430offers the usual selection of peripherals plus some less common modules,including sigma–delta analog-to-digital converters and operational amplifiers.Some devices include hardware multipliers and digital-to-analog converters,which provide a complete signal chain(although,of course,Texas Instruments also offers an enormous range of digital signal processors).There is a choice of two free development environments(always an important considerationin education).One is IAR Embedded Workbench,which is available for a wide range of microcontrollers.Another,Code Composer Essentials,is produced by Texas Instruments itself.A third option is the GCC toolchain for MSP430at .I have not yet mentioned the major selling point of the MSP430,which is its low power consumption.Many microcontrollers are based on long-established designs withlow-power modes grafted onto them.This means that returning to full power from alow-power mode is often awkward and in some cases is virtually a reset operation.The MSP430is refreshingly different because it was designed from the outset for low-power operation.Entry to low-power modes and exit from them is straightforward,supported by a versatile clock system.For example,the clock module includes a digitally controlled oscillator that restarts at full speed from a low-power mode in less than1s in newer devices.In many applications the MSP430is put into a low-power mode,from which it is awakened by interrupts.These automatically restore full power for the interrupt service routine and return the processor to low power when it hasfinished.No extra code is needed for this:It is an intrinsic part of the interrupt mechanism.Most peripherals are designed for low power,although this can sometimes make them a little more complicated than would otherwise be necessary.The main point is that low-power modes are easy to use.The quality of the data sheets and user’s guides is another issue in education and those for the MSP430arefine.Unfortunately one item was missing in the area of documentation:a suitable textbook in English.I wrote this book tofill the gap.OutlineMost textbooks on microcontrollers follow one of two approaches.Thefirst is to present a sequence of projects to explore successive aspects of the device.I think that this works well for simpler architectures,notably the8-bit PICs,because it enables the reader to write functioning programs rapidly.This always feels good.Unfortunately I am not sure that it works as well for more advanced peripherals,which need considerable explanation before the reader can learn to use them fully.Preface xiii The alternative approach is to describe each module in the microcontroller fully and in turn,starting with the CPU and instruction set and working out to the peripherals.This makes for a well-organized reference book but can be tedious as a textbook.I tried to steer a course between these two.My inspiration is Kernighan and Ritchie’s The C Programming Language,which starts with a“Tutorial Introduction”before exploring the language systematically in subsequent chapters.I think that it takes rather more introduction to a microcontroller so the“simple tour,”which is my equivalent to the tutorial,does not start until Chapter4.Before that,thefirst chapter contains a general introduction to embedded systems and microcontrollers.This sets the scene for Chapter2, which focuses on the MSP430and gives a broad view of its features.I include a chapter on hardware and software for developing applications,which I hope will be particularly useful for readers who are new to microcontrollers.It also contains some reminders of features of the C language that are more prominent in programs for microcontrollers than desktop computers—bitfields for instance.This leads into the tour,which runs through some simple programs to illustrate input and output,the inevitableflashing LEDs,and an introduction to one of the timers(the MSP430has several).The remainder of the book provides a more systematic description of the MSP430.I start with the CPU and instruction set,and show how the constant generator is used to provide further“emulated”instructions.The clock system is also described in this chapter.It is followed by Chapter6on subroutines,interrupts,and low-power modes.I already mentioned that a major feature of the MSP430is the way in which low-power modes are handled automatically when interrupts are serviced.Subsequent chapters are concerned with the most widely used peripherals.Chapter7on digital input and output starts with the usual parallel ports and goes on to describe liquid crystal displays,which many MSP430s can drive directly.There is a wide selection of timers in the MSP430,which are covered in the next chapter.This is followed by a lengthy chapter on analog input and output.The MSP430offers many peripherals for analog-to-digital conversion,ranging from a simple comparator to a16-bit sigma–delta module.I do not think that you can use any of these without some understanding of their characteristics,which explains the length of this chapter.Some MSP430s include operational amplifiers and digital-to-analog converters,which I described briefly.Thefinal long chapter is on communication.I cover only three types of communication—serial peripheral interface,inter-integrated circuit bus,and asynchronous—but there are several peripherals for these in different variants of the MSP430,so there is a lot to explain.xiv PrefaceThe very last chapter provides an introduction to the MSP430X,an extended architecture with a20-bit address bus that can handle1MB of memory.There is also an appendix to take the reader through the steps of editing,building,and debugging thefirst project, which can sometimes be a frustrating experience.Ifind it annoying when books contain large chunks copied directly from data sheets and have tried to avoid this.You cannot hope to program a microcontroller without the data sheet at your side.Having said that,I start by going through each bit of the registers that control the peripherals used for the early programs.The idea is to explain how a typical peripheral is configured.After that I become more selective and concentrate on the overall function of the peripheral ually I pick out a few details that I think need extra explanation but skip the more mundane aspects.They are in the example programs inany case.I include links to many of Texas Instruments’application notes because I can see no point in repeating material that has been thoroughly explained already.Ifind that many students are strangely reluctant to use this valuable resource.There are a few reminders about code examples for the same reason.C or Assembly Language?Most small microcontrollers are now programmed using the C language so the question might seem redundant.In fact often columns in newletters on embedded systems often carry articles with titles such as“Is Assembly Language Dead?”However,the answer seems to be clearly that assembly language is not dead for small microcontrollers,such as the MSP430.Most code is written in C but you may occasionally need to write a subroutine in assembly language to perform an operation that cannot be written out directly in C.Two examples are operations that require bitwise rotations rather than shifts and calculations that can be done more efficiently by exploiting special instructions of the CPU,such as binary-coded decimal arithmetic.Intrinsic functions often avoid the need for assembly language but not always.More important,assembly language is often needed for debugging and this is the most compelling reason for describing it in a textbook.Small microcontrollers typically spend much of their time interacting with hardware by manipulating the registers that control the peripherals.Debugging may require stepping through lines of assembly language to check each step.You have to look at the manual to check the details of each instruction,but it helps to have a general idea of how the assembly language works.Preface xv From a pedagogical point of view,assembly language is useful to illustrate the architecture of the processor.In fact the MSP430is simple enough that you can explore the thinking behind the design of the instruction set.Besides,assembly language can be fun(in small doses).My approach is to develop thefirst,simple programs in Chapter4using both C and assembly language to show the relation between them.However,C dominates by the end of the chapter.Assembly language makes a strong showing in the next two chapters,which cover architecture,subroutines,and interrupts,including a section on mixing C and assembly language.Almost all remaining programs are in C,with assembly language reappearing only briefly for a function to convert numbers to binary-coded decimal.The listings in the text are read directly from the programs that I tested.Companion Web SitePlease visit the companion Web site for this book at/companions/9780750682763and download the programs used as examples in the book.These programs were read into the text of the book from the workspaces that I used for testing,which means that the downloadedfiles should match the book perfectly.Links are also provided for data sheets,user’s guides,and development tools.Solutions to the odd-numbered examples are freely available on the companion Web site but the remaining solutions are offered only to instructors. AcknowledgmentsIt is a pleasure to thank numerous people who have helped me in various ways to write this book.Many are from Texas Instruments:Bonnie Baker,Jacob Borgeson,Andreas Dannenberg,Colin Garlick,Thomas Mitnacht,and Robert Owen.I am particularly grateful to Adrian Valenzuela for his comments on thefinal draft.Several engineers from other companies were kind enough to provide advice and assistance:Edward Gibbins and Steve Duckworth from IAR,Tom Baugh of SoftBaugh,Paul Curtis of Rowley Associates,David Dyer of Ericsson and Fernando Rodriguez while he was at Texas Instruments.Finally,I am grateful to colleagues and students at Glasgow University,from whom I have learnt an enormous amount over the years.I’d like to thank Fernando Rodriguez(not the same person who was at Texas Instruments)and David Muir in particular,with both of whom I have run a wide range of projects on embedded systems and microcontrollers—from tutor boxes withflip-flops to the electronic systems of a Formula Student racing car.John Davies,Milngavie。
MSP430F552X中文手册及例程(耐心开完,必有收获)一、先写一篇开个头:这样快速闯入MSP430学习过程进入各个电子产品公司的网站,招聘里面嵌入式占据了大半工程师职位。
广义的嵌入式无非几种:传统的什么51单片机、 MSP430称做嵌入式微控制器;ARM是嵌入式微处理器;当然还有DSP;FPGA。
我们现在就不说别的,就说MSP430单片机,多数想学MSP430的童鞋,对89C51内核系列的单片机是很熟悉的,为了加深对MSP430 系列单片机的认识吗,迅速闯入MSP430学习过程,就必须彻底了解MSP430单片机,我们不妨将51单片机和MSP430两者进行一下比较。
第一点, 51内核单片机是8 位单片机。
其指令是采用的被称为“ CISC ”的复杂指令集,共具有111 条指令。
而MSP430 单片机是16 位的单片机,采用了精简指令集( RISC )结构,只有简洁的27 条指令,大量的指令则是模拟指令,众多的寄存器以及片内数据存储器都可参加多种运算。
这些内核指令均为单周期指令,功能强,运行的速度快。
第二点,MCU主要分为两种工作模式:待机与执行。
51内核单片机正常情况下消耗的电流为mA级,在掉电状态下,其耗电电流仍约为3mA左右;即使在掉电方式下,电源电压可以下降到2V ,但是为了保存内部RAM 中的数据,还需要提供约50uA的电流。
而430单片机功耗是在uA级的,工作电流极小,并且超低功耗,关断状态下的电流仅为0.1μA,待机电流为0.8μA,常规模式下的(250μA/1MIPS@3V),端口漏电流不足50 nA,并可零功耗掉电复位(BOR)。
另外,该芯片属低电器件,仅需1.8~3.6V电压供电,因而可有效降低系统功耗。
MSP430将低功耗模式扩展为7种,分别对应不同应用场合及任务的低功耗方式。
以睡眠模式为例,包括深度睡眠模式RTC:只有时钟在跑而其他都不动,目前,TI宣布其MSP430在RTC模式下最低功耗仅为360nA。
单片机原理及应用第六讲 MSP430F5XX6XX的时钟模块(UCS)实验报告报告人:实验内容1、实验1 6638芯片的上电默认时钟ACLK = REFO = 32.768kHz, MCLK = SMCLK =Default 1MHz2、实验2 时钟设置实例ACLK = REFO = 32kHz, MCLK = SMCLK =8MHz3、实验3 时钟设置实例ACLK = REFO = 32kHz, MCLK = SMCLK =12MHz4、实验3 时钟设置实例ACLK = REFO = 32kHz, MCLK = SMCLK =20MHz实验步骤步骤:(1) 将PC 和板载仿真器通过USB 线相连;(2) 打开CCS 集成开发工具,选择样例工程或自己新建一个工程,修改代码;(3) 选择对该工程进行编译链接,生成.out 文件。
然后选择,将程序下载到实验板中。
程序下载完毕之后,可以选择全速运行程序,也可以选择单步调试程序,选择F3 查看具体函数。
也可以程序下载之后,按下,软件界面恢复到原编辑程序的画面。
再按下实验板的复位键,运行程序。
(调试方式下的全速运行和直接上电运行程序在时序有少许差别,建议上电运行程序)。
关键代码:实验1:Main(){WDTCTL = WDTPW+WDTHOLD; // Stop WDTP4DIR |= BIT1; // P4.1 outputP1DIR |= BIT0; // ACLK set out to pinsP1SEL |= BIT0;P3DIR |= BIT4; // SMCLK set out to pinsP3SEL |= BIT4;while(1){P4OUT ^= BIT1;__delay_cycles(60000); // Delay}实验2:#include <msp430.h>int main(void){volatile unsigned int i;WDTCTL = WDTPW+WDTHOLD; // Stop WDTP4DIR |= BIT1; // P1.1 outputP1DIR |= BIT0; // ACLK set out to pinsP1SEL |= BIT0;P3DIR |= BIT4; // SMCLK set out to pinsP3SEL |= BIT4;UCSCTL3 = SELREF_2; // Set DCO FLL reference = REFOUCSCTL4 |= SELA_2; // Set ACLK = REFOUCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx// Loop until XT1,XT2 & DCO stabilizes ‐In this case only DCO has to stabilize do {UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);// Clear XT2,XT1,DCO fault flagsSFRIFG1 &= ~OFIFG; // Clear fault flags}while (SFRIFG1&OFIFG); // Test oscillator fault flag__bis_SR_register(SCG0); // Disable the FLL control loopUCSCTL1 = DCORSEL_5; // Select DCO range 16MHz operationUCSCTL2 |= 249; // Set DCO Multiplier for 8MHz// (N + 1) * FLLRef = Fdco, (249 + 1) * 32768 = 8MHz__bic_SR_register(SCG0); // Enable the FLL control loop// Worst‐case settling time for the DCO when the DCO range bits have been// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx UG for // optimization , 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle __delay_cycles(250000);while(1){P4OUT ^= BIT1; // Toggle P1.1__delay_cycles(600000); // Delay}}实验3:#include <msp430.h>int main(void){volatile unsigned int i;WDTCTL = WDTPW+WDTHOLD; // Stop WDTP4DIR |= BIT1; // P1.1 outputP1DIR |= BIT0; // ACLK set out to pinsP1SEL |= BIT0;P3DIR |= BIT4; // SMCLK set out to pinsP3SEL |= BIT4;UCSCTL3 = SELREF_2; // Set DCO FLL reference = REFOUCSCTL4 |= SELA_2; // Set ACLK = REFOUCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx// Loop until XT1,XT2 & DCO stabilizes ‐In this case only DCO has to stabilizedo {UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);// Clear XT2,XT1,DCO fault flagsSFRIFG1 &= ~OFIFG; // Clear fault flags}while (SFRIFG1&OFIFG); // Test oscillator fault flag__bis_SR_register(SCG0); // Disable the FLL control loopUCSCTL1 = DCORSEL_5; // Select DCO range 16MHz operationUCSCTL2 |= 375; // Set DCO Multiplier for 8MHz// (N + 1) * FLLRef = Fdco, (249 + 1) * 32768 = 8MHz__bic_SR_register(SCG0); // Enable the FLL control loop// Worst‐case settling time for the DCO when the DCO range bits have been// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx UG for // optimization , 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle __delay_cycles(250000);while(1){P4OUT ^= BIT1; // Toggle P1.1__delay_cycles(600000); // Delay}}实验3:#include <msp430f6638.h>void SetVcoreUp (unsigned int level);void main(void){volatile unsigned int i;WDTCTL = WDTPW+WDTHOLD; // Stop WDTP4DIR |= BIT1; // P4.1 outputP1DIR |= BIT0; // ACLK set out to pinsP1SEL |= BIT0;P3DIR |= BIT4; // SMCLK set out to pinsP3SEL |= BIT4;// Increase Vcore setting to level3 to support fsystem=25MHz // NOTE: Change core voltage one level at a time.. SetVcoreUp (0x01);SetVcoreUp (0x02);SetVcoreUp (0x03);UCSCTL3 = SELREF_2; // Set DCO FLL reference = REFO UCSCTL4 |= SELA_2; // Set ACLK = REFO__bis_SR_register(SCG0); // Disable the FLL control loop UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODxUCSCTL1 = DCORSEL_7; // Select DCO range 50MHz operationUCSCTL2 = FLLD_1 + 609; // Set DCO Multiplier for 20MHz// (N + 1) * FLLRef = Fdco// (609 + 1) * 32768 = 20MHz// Set FLL Div = fDCOCLK/2__bic_SR_register(SCG0); // Enable the FLL control loop// Worst‐case settling time for the DCO when the DCO range bits have been// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx // UG for optimization.// 32 x 32 x 25 MHz / 32,768 Hz ~ 780k MCLK cycles for DCO to settle__delay_cycles(782000);// Loop until XT1,XT2 & DCO stabilizes ‐In this case only DCO has to stabilize do{UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);// Clear XT2,XT1,DCO fault flagsSFRIFG1 &= ~OFIFG; // Clear fault flags}while (SFRIFG1&OFIFG); // Test oscillator fault flagwhile(1){P4OUT ^= BIT1; // Toggle P4.1__delay_cycles(600000); // Delay}}void SetVcoreUp (unsigned int level){PMMCTL0_H = PMMPW_H; // Open PMM registers for write// Set SVS/SVM high side new levelSVSMHCTL = SVSHE + SVSHRVL0 * level + SVMHE + SVSMHRRL0 * level;// Set SVM low side to new levelSVSMLCTL = SVSLE + SVMLE + SVSMLRRL0 * level;while ((PMMIFG & SVSMLDLYIFG) == 0); // Wait till SVM is settledPMMIFG &= ~(SVMLVLRIFG + SVMLIFG); // Clear already set flagsPMMCTL0_L = PMMCOREV0 * level; // Set VCore to new levelif ((PMMIFG & SVMLIFG))while ((PMMIFG & SVMLVLRIFG) == 0); // Wait till new level reached// Set SVS/SVM low side to new levelSVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level;// Lock PMM registers for write accessPMMCTL0_H = 0x00;}实验现象分析实验1:示波器探头接P1.0时,测得频率为32kHz左右,接P3.4时,测得频率大概为1MHz。
第3章标准时钟系统标准时钟系统可以为器件提供各种需要的时钟信号。
本章主要讲述如何根据需要对标准时钟系统进行配置。
目录3.1时钟系统介绍3.2UCS操作模式3.3MODSOC操作3.4UCS模块寄存器3.1 时钟系统介绍UCS模块是一个低成本低功耗的时钟系统。
包含有三个内部时钟信号,用户可以自行配置,得到性能和功耗的最佳平衡点。
UCS软件配置后,只需要外部一两个晶振或者电阻,而不需要其他的任何器件。
UCS模块最多含有5个时钟源:●XT1CLK:低频/高频振荡器,可以使用低频32768HZ钟振、标准晶振、外部振荡器或者通过外部输入源输入4MHZ~32MHZ时钟。
XT1CLK可以作为内部FLL模块的参考时钟,有些器件只支持外部的低频晶振,具体可参考数据手册。
●VLOCLK:内部低功耗,低频振荡器。
典型值为10KHZ。
●REFOCLK:内部低频振荡器,典型值为32768HZ,作为FLL基准时钟源。
●DCOCLK:内部数字控制振荡器(DCO)可以通过FLL来稳定。
●XT2CLK:可选择的高频振荡器,可以使用标准晶振,振荡器或者外部时钟源输入4MHZ~32MHZ。
UCS模块可以提供三个时钟信号:●ACLK:辅助时钟。
ACLK可由软件选择来自于XT1CLK,REFOCLK,VLOCLK,DCOCLK,DCOCLKDIV,和XT2CLK(如果可以用)。
DCOCLKDIV为DCOCLK在FLL模块中通过1、2、4、8、19、32分频后得到的频率。
ACLK可由软件配置位各个模块的时钟信号。
ACLK可由1、2、4、8、16、32分频后使用。
ACLK/n是ACLK经1、2、4、8、16、32分频后通过IO口输出作为外部电路使用。
●MCLK:系统主时钟。
MCLK可由软件选择来自于XT1CLK,REFOCLK,VLOCLK,DCOCLK,DCOCLKDIV,XT2CLK(如果可以用)。
DCOCLKDIV为DCOCLK在FLL模块中通过1、2、4、8、19、32分频后得到的频率。
MCLK可以通过1、2、4、8、16、32分频后使用。
MCLK可以作为CPU和系统时钟。
●SMCLK:子系统主时钟。
SMCLK可由软件选择来自于XT1CLK,REFOCLK,VLOCLK,DCOCLK,DCOCLKDIV,XT2CLK(如果可以用)。
DCOCLKDIV为DCOCLK在FLL模块中通过1、2、4、8、19、32分频后得到的频率。
SMCLK可以通过1、2、4、8、16、32分频后使用。
SMCLK主要用于高速外围模块。
UCS模块图如下图3-1所示:图3-1 标准系统时钟框图3.2 UCS操作模式PUC信号后,UCS默认的配置模式如下所示:●XT1为LF模式,作为XT1CLK时钟源。
ACLK来自于XT1CLK。
●DCOCLKDIV作为MCLK●DCOCLKDIV作为SMCLK●FLL模块使能。
FLL基准时钟(FLLREFCLK)来自XT1CLK●XIN和XOUT管脚为普通IO口,XT1保持禁止直到将I/O口配置为XT1模式●XT2IN和XT2OUT脚作为普通IO口,XT2禁止。
如上所示,FLL和XT1默认为启用状态。
因为晶振管脚XIN,XOUT和普通I/O口复用。
所以要使能XT1,就必须将与XT1引脚对应的PSEL位置位。
当32768HZ晶振作为XT1CLK 时钟时,因为XT1不会立即稳定(参考3.2.12节),所以晶振失效标志位是置位的,这时系统会让REFOCLK作为ACLK的时钟源。
一旦晶振启动并稳定,ACLK将取自外部的32768HZ晶振,FLL将使MCLK和SMCLK稳定为1.047586MHZ和Fdco=2.097152MHZ。
(上电后FLLD默认为2)状态寄存器SCG0,SCG1,OSCOFF和CPUOFF配置MSP430工作模式,也可以使能和禁止UCS模块功能(参考系统复位、中断和操作模式章节)。
寄存器UCSCTL0~8用来配置UCS模块。
UCS模块可以在软件执行过程中的任何需要的时候进行配置和修改配置。
3.2.1 UCS模块的超低功耗应用在采用电池供电的系统应用中有一些矛盾:●为了保持长时间工作或降低功耗而采用低频时钟●快速的时钟有快速的响应能力和大的数据处理吞吐量●适应多种工作温度和电压的稳定时钟●不需要校准系统的低成本时钟应用UCS模块允许用户选择现有的3个时钟信号ACLK,MCLK,SMCLK,从而解决上述相对矛盾的问题。
3个时钟信号可以来自任何有效的时钟源(XT1CLK,VLOCLK,REFOCLK,或者XT2CLK),给系统带来非常灵活的选择时钟。
3.2.2 内部超低频振荡器(VLO)内部VLO能够提供典型10k的振荡频率(具体参数见数据手册),而不需要外接任何晶振。
VLO可以对时钟精确要求不高的的应用提供低成本和超低功耗的时钟源。
VLO可以通过设置SELA=1、SELM=1、SELS=1作为ACLK、SMCLK、MCLK的时钟源。
3.2.2 内部参考时钟(REFO)内部参考时钟可以在没有外部晶振,对成本又比较敏感的场合得到很好的应用。
内部参考振荡器可以产生一个比较稳定的频率,其典型值为32768Hz,他可以用作FLLREFCLK。
REFOCL和FLL相结合可为系统提供灵活可变的时钟,而不需要外接晶振。
REFO在不使用时,不消耗任何功耗。
REFO在以下配置时有效:●在活动模式或LPM0~3模式下时,REFO作为ACLK的时钟源(SELA=2);(OSCOFF=0)●在活动模式下REFO作为MCLK的时钟源(SELM=2);(CPUOFF=0)●在活动模式下或LPM0~1模式下时,REFO作为SMCLK的时钟源(SELS=2));(SMCLKOFF=0)●REFO作为FLLREFCLK(SELREF=2)时钟源并且在活动模式及LPM0~3模式下DCO作为ACLK的时钟源(SELA=3,4);(OSCOFF=0)●REFO作为FLLREFCLK(SELREF=2)时钟源并且在活动模式下DCO作为MCLK的时钟源(SELA=3,4);(CPUOFF=0)●REFO作为FLLREFCLK(SELREF=2)时钟源并且在活动模式及LPM0~1模式下DCO作为SMCLK的时钟源(SELA=3,4);(SMCLKOFF=0)3.2.4 晶振XT1XT1工作在低频模式时(XTS=0),提供支持32768HZ时钟的超低功耗模式。
晶振连接不需要任何其他外围器件而直接诶连接到XIN和XOUT。
在LF模式下XCAP为XT1晶振配置的内部负载电容,负载电容可以由软件编程选择2pF,6pF,9pF,12pF(典型值)。
也可以根据需要增加外接电容。
在一些设备中当XT1选择HF模式时(XTS=1)也支持高频晶振或者振荡器。
高频晶振或振荡器连接到XIN和XOUT引脚,需要在两个端口配置电容。
电容的大小需要根据晶振或者振荡器的特性来选择。
LF模式下可以通过设置XT1DRIVE来提高XT1驱动。
在上电时,XT1以最大的驱动能力来快速可靠启动。
如果需要,用户可以降低驱动能力以降低功耗。
在高频模式时也可以配置XT1DRIVE来适应不同的晶振或振荡器。
无论是在LF/HF模式下,都可以通过配置XT1BYPASS位来使用输入到XT1的外部时钟信号。
当使用外部信号给XT1提供时钟信号时,外部信号的频率必须和选择的工作模式以及数据手册上的参数相符合。
当在BYPASS模式时,XT1自动关闭电源。
XT1引脚和普通I/O口是复用。
上电后,XT1默认为LF模式。
但是,XT1仍然是禁止的,直到将IO配置成晶振模式功能。
复用IO口的配置由PSEL和XT1BYPASS决定。
选择PSEL位将使X1IN和X1OUT端口被配置成XT1模式。
如果XT1BYPASS置位,XT1将配置成支路模式。
在支路模式下,外部时钟由XIN输入,XOUT可以配置成普通IO口,这时与XOUT相对应的PxSEL位可以不用关心。
如果与XIN对应的PxSEL位清零,XIN和XOUT都将配置为普通IO口,XT1将禁止。
以下情况是XT1是允许的:●在活动模式或LPM0~3模式下时,XT1作为ACLK的时钟源(SELA=0);(OSCOFF=0)●在活动模式下XT1作为MCLK的时钟源(SELM=0);(CPUOFF=0)●在活动模式下或LPM0~1模式下时,XT1作为SMCLK的时钟源(SELS=0);(SMCLKOFF=0)●XT1作为FLLREFCLK(SELREF=2)时钟源并且在活动模式及LPM0~3模式下DCO作为ACLK的时钟源(SELA=3,4);(OSCOFF=0)●XT1作为FLLREFCLK(SELREF=0)时钟源并且在活动模式下DCO作为MCLK的时钟源(SELA=3,4);(CPUOFF=0)●XT1作为FLLREFCLK(SELREF=0)时钟源并且在活动模式及LPM0~1模式下DCO作为SMCLK的时钟源(SELA=3,4);(SMCLKOFF=0)●XT1OFF=0,在活动模式及LPM0~4模式下3.2.4 晶振 XT2某些器件有第二个晶振XT2,XT2的特性和XT1的高频模式相同。
XT2DRIVE位用来选择XT2的频率范围???(应该是驱动能力吧)。
当置位XT2BYPASS,XT2可以由外部时钟源通过XIN脚输入。
使用外部输入频率时,外部频率必须符合数据手册中XT2相关参数的规定。
XT2管脚和普通I/O口复用。
上电后,默认为XT2模式。
但是,XT2仍然是禁止的直到和XT2复用的管脚配置成XT2模式时才有效。
复用IO口的配置由与XT2对应的PSEL 位和XT2BYPASS位来确定。
设置对应的PSEL位将XT2IN和XT2OUT配置成XT2功能。
如果XT2BYPASS被置位,XT2将配置成旁路模式,在旁路模式下,XT2IN可以由外部振荡器输入,XT2OUT可配置成普通I/O口这时相应的PxSEL位可以不用关心。
如过清除与XT2IN对应的PxSEL位,XT2和XT2OUT管脚都被配置成普通I/O口,并且XT2将被禁止。
以下情况是XT2是允许的:●在活动模式或LPM0~3模式下时,XT2作为ACLK的时钟源(SELA=5,6,7);(OSCOFF=0)●在活动模式下XT2作为MCLK的时钟源(SELM=5,6,7);(CPUOFF=0)●在活动模式下或LPM0~1模式下时,XT2作为SMCLK的时钟源(SELS=5,6,7);(SMCLKOFF=0)●XT2作为FLLREFCLK(SELREF=5,6)时钟源并且在活动模式及LPM0~3模式下DCO作为ACLK的时钟源(SELA=3,4);(OSCOFF=0)●XT2作为FLLREFCLK(SELREF=5,6)时钟源并且在活动模式下DCO作为MCLK的时钟源(SELA=3,4);(CPUOFF=0)●XT2作为FLLREFCLK(SELREF=5,6)时钟源并且在活动模式及LPM0~1模式下DCO作为SMCLK的时钟源(SELA=3,4);(SMCLKOFF=0)●XT2OFF=0,在活动模式及LPM0~4模式下3.2.5 数字控制振荡器 (DCO)DCO是内部集成的数字频率振荡器。