Part Number Hot Search : 
55N60 K2466 MSA24 AD8032 CE07001 T640N E4460 BZQ5224B
Product Description
Full Text Search
 

To Download STFLSTUDIO3UM Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  fuzzystudio tm 3.0 user manual 1 st edition may 1998
ownership stmicroelectronics is the sole owner of the software contained in the package. stmicroelectronics is the holder of the copyright to the software, including without limitation such aspects of the software as its code, sequence, organization, "look and feel", programming language and compilation names. use of the software unless pursuant to the terms of a licence granted by stmicroelectronics or as otherwise authorized by law is an infringment of the copyright. permitted use provided that you fully accept the present conditions, stmicroelectronics grants you a non-exclu- sive non transferable licence to use the product. you are also authorized to: a) install the software on an on-line storage device (for example a hard disk drive); b) maintain an archivial copy of the software on off-line storage media (such as diskettes). prohibited use all uses of the software and other elements of the product not specifically allowed in the permitted uses section of this agreement are prohibited. the following is a partial list of prohibited uses of the package. you are not allowed to: a) decompile or reverse engineer the software; b) modify the software in any manner; c) sublicense, sell, lend, lease or rent the software or any portion of the software. warranties stmicroelectronics makes no warranties, express or implied, including without limitation any warranties of merchantability or fitness for a particular purpose, regarding the software develop- ment tool and any related materials or their performance. limited damages stmicroelectronics shall not be liable for any incidental, special consequential or exemplary damages including, but not limited to loss of anticipated profits or benefits. use in life support devices or systems must be expressly authorized stmicroelectronics products are not authorized for use as critical components in life support devices or systems without the express written approval of stmicroelectronics. as used herein: 1. life support devices or systems are those which (a) are intented for surgical implant into the body, or (b) support or sustain life, and whose failure to perform, when properly used in accordance with instructions for use provided with the product, can be reasonablyexpected to result in significant injury to the user. 2. a critical component is any component of a life support device or system whose failure to perform can reasonaly be expected to cause the failure of the life support device or system, or to affect its safety or effectiveness.
table of contents before you begin i general conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i mouse conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i keyboard conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i installation and configuration ii system requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i installing fuzzystudio ? 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . ii starting to use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii user interface iv choosing commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv clicking a toolbar button . . . . . . . . . . . . . . . . . . . . . . . . . . v choosing commands from menus . . . . . . . . . . . . . . . . . . . . . v using shortcut keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . v using help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi context-sensitive help . . . . . . . . . . . . . . . . . . . . . . . . . . vi chapter 1- fuzzystudio ? 3.0 1 about st52x301 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 introduction to fuzzystudio ? 3.0 . . . . . . . . . . . . . . . . . . . . . . . 1 system variables overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 programming approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 chapter 2- project management 7 project files management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 working with a new project . . . . . . . . . . . . . . . . . . . . . . . . 7 working with an existing project . . . . . . . . . . . . . . . . . . . . . 8 saving and printing files . . . . . . . . . . . . . . . . . . . . . . . . . 8 the fuzzystudio ? 3.0 main window . . . . . . . . . . . . . . . . . . . . . . 9 the fuzzystudio ? 3.0 window application menus . . . . . . . . . . 9 the fuzzystudio ? 3.0 main windows toolbar . . . . . . . . . . . . 10 the fuzzystudio ? 3.0 main windows status bar . . . . . . . . . . 10 the fuzzystudio ? 3.0 project window . . . . . . . . . . . . . . . . . . . 11 working environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 chapter 3 - initial settings 13 global variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 how to insert a global variable . . . . . . . . . . . . . . . . . . . . . 13 deleting a global variable . . . . . . . . . . . . . . . . . . . . . . . . 14 global variable properties . . . . . . . . . . . . . . . . . . . . . . . . 14 frequency setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 peripherals configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 timer configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 triac driver configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
sections common to the three modes . . . . . . . . . . . . . . . . . 19 pwm mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 burst mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 phase partialization . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 a/d configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 parallel port configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 serial communication interface (sci) configuration. . . . . . . . . . . . . . . 24 chapter 4 - block editor tool 27 the block editor tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 block editor menus . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 block editor toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 block editor status bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 using the block editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 program starting point . . . . . . . . . . . . . . . . . . . . . . . . . 30 how to insert a block . . . . . . . . . . . . . . . . . . . . . . . . . . 30 how to link two blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 single and multiple selection of a block . . . . . . . . . . . . . . . . . . . . . 31 basic commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 how to use links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 other commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 chapter 5 - fuzzy block 33 overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 the fuzzy system editor window . . . . . . . . . . . . . . . . . . . . . . . . 34 fuzzy system editor toolbar . . . . . . . . . . . . . . . . . . . . . . 34 fuzzy system editor status bar . . . . . . . . . . . . . . . . . . . . . 34 fuzzy system editor menus . . . . . . . . . . . . . . . . . . . . . . . 35 about fuzzy variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 variable constraints definition in a fuzzy block . . . . . . . . . . . . . . . . . 36 how to insert a fuzzy variable block . . . . . . . . . . . . . . . . . . 37 how to delete a fuzzy variable block . . . . . . . . . . . . . . . . . . 37 how to close a variable window . . . . . . . . . . . . . . . . . . . . 37 fuzzy variable initialization and storage . . . . . . . . . . . . . . . . . . . . . 38 the fuzzy variable editor window . . . . . . . . . . . . . . . . . . . . . . . . 40 fuzzy variable editor menu . . . . . . . . . . . . . . . . . . . . . . . 40 fuzzy variable editor toolbar . . . . . . . . . . . . . . . . . . . . . . 41 fuzzy variable editor status bar . . . . . . . . . . . . . . . . . . . . 41 how to open a fuzzy variable block . . . . . . . . . . . . . . . . . . . . . . . 42 how to modify the fuzzy variable properties . . . . . . . . . . . . . . 43 creating and managing membership functions . . . . . . . . . . . . . . . . . 44 creating a new mbf . . . . . . . . . . . . . . . . . . . . . . . . . . 45 creating a new mbf using the rule editor (output variables) . . . . . . 45 how to customize a mbf . . . . . . . . . . . . . . . . . . . . . . . . . 45 using autofill mbf (only for input variables) . . . . . . . . . . . . . 46 fuzzystudio ? 3.0 user manual
how to delete a mbf . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 autoshift & semibase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 mbf report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 shared and copied variables . . . . . . . . . . . . . . . . . . . . . . . . . . 50 shared variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 copied variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 how to export data to clipboard . . . . . . . . . . . . . . . . . . . . . . . . . 51 fu.l.l. importer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 rule editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 defining fuzzy rules with rule editor . . . . . . . . . . . . . . . . . . . . . . 54 the rule editor window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 rule editor menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 rule editor toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 rule editor status bar . . . . . . . . . . . . . . . . . . . . . . . . . . 55 how to write a rule using guided editor . . . . . . . . . . . . . . . . . . . . 56 editing the antecedent . . . . . . . . . . . . . . . . . . . . . . . . . 57 editing the consequent . . . . . . . . . . . . . . . . . . . . . . . . . 57 using manual editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 how to write a rule . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 list updating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 how to delete rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 how to print the rules list . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 rule editor view options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 rule editor constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 rule grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 chapter 6 - arithmetic block 65 the arithmetic block window . . . . . . . . . . . . . . . . . . . . . . . . . . 65 arithmetic block menus . . . . . . . . . . . . . . . . . . . . . . . . . 65 arithmetic block toolbar . . . . . . . . . . . . . . . . . . . . . . . . . 66 arithmetic block status bar . . . . . . . . . . . . . . . . . . . . . . . 66 using the arithmetic block . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 instructions grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 conditional instructions . . . . . . . . . . . . . . . . . . . . . . . . . 71 how to check the instructions . . . . . . . . . . . . . . . . . . . . . . 73 chapter 7 - peripherals block 75 a/d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 sci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 triac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 port output pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 table of contents
chapter 8 - interrupts service routines 81 interrupts configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 interrupts mask block . . . . . . . . . . . . . . . . . . . . . . . . . . 82 priority configuration block . . . . . . . . . . . . . . . . . . . . . . . 83 chapter 9 - wait for interrupt block 85 chapter 10 - assembler block 87 the assembler block window . . . . . . . . . . . . . . . . . . . . . . . . . . 87 assembler block menus . . . . . . . . . . . . . . . . . . . . . . . . . 87 assembler block toolbar . . . . . . . . . . . . . . . . . . . . . . . . . 88 assembler block status bar . . . . . . . . . . . . . . . . . . . . . . . 88 using the assembler block . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 how to check instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 assembler block instruction syntax . . . . . . . . . . . . . . . . . . . . . . . 90 chapter 11 - conditional block 91 how to insert a conditional block . . . . . . . . . . . . . . . . . . . . . . . . 91 conditional block grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 chapter 12 - send - receive blocks 93 how to use the send and receive blocks . . . . . . . . . . . . . . . . . . . . 93 chapter 13 - restart block 97 chapter 14 - compiler 99 compiler options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 compilation error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 fatal errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 internal errors . . . . . . . . . . . . . . . . . . . . . . . . . . 105 warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 chapter 15 - debugger 109 general description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 debugger menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 debugger toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 wcl source window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 watch view window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 watch edit dialog box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 watch edit signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 locals window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 trace window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 registers window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 asm view window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 status window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 fuzzystudio ? 3.0 user manual
input editor window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 how to use debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 plot view window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 plot view menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 plot view window toolbar . . . . . . . . . . . . . . . . . . . . . . . . 122 print and copy the graphic on the clipboard . . . . . . . . . . . . . . 122 zoom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 signals and bus selection . . . . . . . . . . . . . . . . . . . . . . . . 123 changing time base . . . . . . . . . . . . . . . . . . . . . . . . . . 124 changing colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 chapter 16 - how to program st52x301 125 programmer main features . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 hardware installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 chip insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 programming phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 error messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 appendix a - fuzzy logic introduction. human language and indeterminacy a - 1 a general overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 2 the linguistic approach. . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 2 fuzzy logic, fuzzy sets and membership function . . . . . . . . . . . . . . a - 4 fuzzy reasoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 5 the mathematical definition of fuzzy sets . . . . . . . . . . . . . . . . . . . a - 7 membership functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 9 fuzzy set operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 9 set complement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 10 set union . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 12 set intersection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 13 the mathematical formalism of fuzzy logic . . . . . . . . . . . . . . . . . a - 14 fuzzy reasoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 16 fuzzy computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 17 bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 21 appendix b - quick reference w.a.r.p. control language (wcl) b - 23 general features of a wcl program . . . . . . . . . . . . . . . . . . . . b - 23 source code organization . . . . . . . . . . . . . . . . . . . . . b - 23 characters conventions . . . . . . . . . . . . . . . . . . . . . . . b - 23 naming conventions . . . . . . . . . . . . . . . . . . . . . . . . b - 23 standard libraries . . . . . . . . . . . . . . . . . . . . . . . . . . b - 23 conditional expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 24 operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 24 operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 24 library functions . . . . . . . . . . . . . . . . . . . . . . . . . . b - 25 reference labels . . . . . . . . . . . . . . . . . . . . . . . . . . b - 26 table of contents
predefined names . . . . . . . . . . . . . . . . . . . . . . . . . . b - 26 chip features definition . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 27 global variables declaration . . . . . . . . . . . . . . . . . . . . . . . . . b - 28 membership function definition . . . . . . . . . . . . . . . . . . . b - 28 global crisp variables definition . . . . . . . . . . . . . . . . . . . b - 28 procedure declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 29 arithmetic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 29 asm procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 31 control procedure . . . . . . . . . . . . . . . . . . . . . . . . . . b - 32 folder procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 35 fuzzy procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 35 fuzzy variables declaration . . . . . . . . . . . . . . . . . . . . . b - 35 fuzzy rules definition . . . . . . . . . . . . . . . . . . . . . . . . b - 36 st52x301 standard library . . . . . . . . . . . . . . . . . . . . . . . . . b - 37 predefined variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 39 peripherals configuration variables . . . . . . . . . . . . . . . . . . . . . b - 39 appendix c - assembler language c - 41 program memory and registers architecture . . . . . . . . . . . . . . . . c - 41 program memory . . . . . . . . . . . . . . . . . . . . . . . . . . c - 41 register file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 41 configuration registers . . . . . . . . . . . . . . . . . . . . . . . c - 42 input registers . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 42 peripherals data registers . . . . . . . . . . . . . . . . . . . . . . . . . c - 43 flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 43 fuzzy programming in assembler . . . . . . . . . . . . . . . . . . . . . . c - 44 membership functions definition . . . . . . . . . . . . . . . . . . c - 44 rule inference . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 45 the structure of a program . . . . . . . . . . . . . . . . . . . . . . . . . c - 47 structure of a generic code line . . . . . . . . . . . . . . . . . . c - 48 comment sequences . . . . . . . . . . . . . . . . . . . . . . . . c - 48 line label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 48 data definition section . . . . . . . . . . . . . . . . . . . . . . . . c - 48 interrupt vectors definition . . . . . . . . . . . . . . . . . . . . . . c - 49 arithmetic instructions section . . . . . . . . . . . . . . . . . . . . c - 49 fuzzy instructions section . . . . . . . . . . . . . . . . . . . . . . c - 52 appendix d - fs3asm: assembler programming tool. d- 55 fs3asm main window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d-55 fs3asm menus . . . . . . . . . . . . . . . . . . . . . . . . . . . d - 55 fs3asm toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . d - 56 fs3asm status bar . . . . . . . . . . . . . . . . . . . . . . . . . d - 56 managing and printing files . . . . . . . . . . . . . . . . . . . . . . . . . d - 57 editing commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d - 57 machine code generation . . . . . . . . . . . . . . . . . . . . . . . . . . d - 58 device programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d - 58 fuzzystudio ? 3.0 user manual
w3asm error list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . d - 59 appendix e full - fuzzy logic language e- 63 full language elements . . . . . . . . . . . . . . . . . . . . . . . . . . e - 63 token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 63 white space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 64 comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 64 punctuation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 64 operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 64 keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 65 identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 65 constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 66 expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 66 declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 68 universes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 68 modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 69 shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 70 variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 72 rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 74 full program example . . . . . . . . . . . . . . . . . . . . . . . . . . . e - 76 full language grammar . . . . . . . . . . . . . . . . . . . . . . . . . . e - 78 table of contents
fuzzystudio ? 3.0 user manual
before you begin before you start using fuzzystudio ? 3.0, it is important to understand the terms and notational conventions used in this documentation. general conventions the word "choose" is used to carry out a menu command or a command button in a dialog box. bold type in text indicates words or characters you type. italic type indicates important terms introduced in the section. upper case type in text indicates the names of commands and menus buttons of fuzzy- studio ? 3.0. a numbered list (1, 2, ...) indicates a procedure with two or more sequential steps. a bullet symbol indicates a procedure with only one step. mouse conventions fuzzystudio ? 3.0 requires two mouse buttons. the default one is the left button but you can use the right button to perform some functions. for information on changing the mouse button, see your operating system documentation. "point" means to position the mouse pointer until the tip of the pointer rests on what you want to point to on the screen. "click" means to press and immediately release the mouse button without moving the mouse. "double click" means to press the mouse button twice in rapid succession. keyboard conventions a plus sign (+) used between two key names indicates that you must press both keys at the same time. for example alt+f means that you press the alt key and hold it down while you press the f key; this is the shortcut to choose the file menu. a comma (,) between two keys names indicates that you must press those keys sequentially. for example, "press alt, f, o" means that you press the alt key and release it, press the f and release it, and then press the o and release it. this is the shortcut to choose the file open command. i getting started
i fuzzystudio ? 3.0
installation and configuration the most-commonly-asked installation questions will be answered in the following pages, providing you with everything you ever wanted to know about the installation of fuzzy- studio ? 3.0. system requirements before you install fuzzystudio ? 3.0, make sure you have all the hardware and software you need to run the program: intel type 80386 processor or higher. 8 mbytes ram memory. hard disk with at least 10 mbytes of free space. vga or higher graphics card. mouse. windows 3.1 or windows for workgroups 3.11 or windows 95. installing fuzzystudio ? 3.0 your first step is to use the setup program to install fuzzystudio ? 3.0 on your hard disk. be sure to start microsoft windows before to install fuzzystudio ? 3.0. 1 insert the installation disk 1 into the floppy disk drive a or b. 2 once windows is running, select the run option from the program manager file menu. 3 on the run options command line, type: a:\setup then choose ok or press enter 4 window mask will appear, containing a window with the " initializing setup " message. if you dont want to continue the installation choose the exit button, else choose continue. 5 a dialog box appears to set the directory where you want to install fuzzystudio ? 3.0. if a directory is not specified, the directory c:\fstudio3.0 will be automatically generated along with the device sub-directory 6 after copying the necessary files, the setup program automatically generates the group and the icon to start the program. when the setup procedure is completed, you will return back to the program manager. ii getting started
starting to use after you have installed fuzzystudio ? 3.0, you can use the application. to start fuzzystudio ? 3.0: 1 double-click the fuzzystudio 3.0 group icon in the program manager window, or open the group that contains the fuzzystudio 3.0. 2 double-click the fuzzystudio ? 3.0 icon to run the program. iii fuzzystudio ? 3.0
working area status bar title bar menu bar toolbar and buttons context- sensitive help buttons user interface this chapter provides basic skills on the use of fuzzystudio ? 3.0 and explains the items you see on the screen. youll learn how to choose commands and how to use fuzzystudio ? 3.0 online help. the first window that appears on the screen consists of the working area, the menu bar, the toolbar and the status bar. choosing commands a command is an instruction that tells fuzzystudio ? 3.0 to do something. there are different ways to choose a command: clicking a toolbar button with the mouse. choosing a command from a menu. using shortcut keys. iv getting started
clicking a toolbar button the toolbar consists of a number of icons, each representing a tool or option which you can use to create or modify your project. the toolbar is a user selectable item, it means that you can choose to hide or show it by using the related command of the view menu. choosing commands from menus fuzzystudio ? 3.0 commands are grouped in menus. some commands carry out an action immediately; others display a dialog box so that you can select options. to choose a command with either the mouse or the keyboard, you choose the menu and then the command name. to select a menu or choose a command by using the keyboard, press the key for the underlined letter in a menu or number in the command name. using the mouse if you use the mouse you have to follow these steps to choose a command: 1 to display a menu that contains the command you want, click the menu name in the menu bar. 2 click the command name. you can also point to the menu, drag to the command you want, and then release the mouse button. 3 if the command displays a dialog box, specify the information you need, (see "working in a dialog box" section). 4 when you finish with the dialog box, click the appropriate button to carry out the command. using the keyboard if you want to choose a command by using the keyboard: 1 to activate the menu bar, press alt or f10. the file menu appears selected, indicating that the menu bar is active. 2 to open a menu press the key of the underlined letter of the command name you want to select or use the left or right arrows keys to select the menu name and the down arrow key to open it. 3 if the command displays a dialog box, specify the appropriate information that you need. you can change field pressing the tab key. to close a menu, click anywhere outside the menu and the menu bar or press the esc key. to cancel a command, click the cancel button on the dialog box or press the esc key. a command name followed by the symbol > on a menu indicates that fuzzystudio ? 3.0 displays a sub-menu. using shortcut keys you can choose some commands by pressing the shortcut keys listed on the menu to the right of the command. for example, to save the current project, press ctrl+s. v fuzzystudio ? 3.0
using help fuzzystudio ? 3.0 is provided with a complete online reference tool. help is especially useful when you need information quickly or when your user manual is not available. help contains information about each command and each dialog box. when you are working with fuzzystudio ? 3.0, you can select help using the menu name on the menu bar or choosing the help button that appears on the dialog box. once you are in help, there are two ways you can move to other topics to find exactly the information you want, including: jump terms. jump terms are underlined with a solid line and are used to go to the topics in the help window. back button. the back button is used to step back through all the topics you have viewed since opening the help window. index button. the index button is used to display the list of help topics. context-sensitive help to find out about an item on the screen, click the context-sensitive help button on the toolbar. when the pointer changes to a question mark, choose the command or click the window item on which you want help. fuzzystudio ? 3.0 displays the help topic for the selected command or window item in the help window. vi getting started
vii fuzzystudio ? 3.0
chapter 1 fuzzystudio ? 3.0 about st52x301* st52x301 is an 8-bit fuzzy microcontroller with the following features: 8-bit arithmetic instruction set. fuzzy processing of systems with 4 inputs and 2 outputs. programmable peripherals for the user application driving. instruction set to control the program. programmable interrupts. for more information on st52x301 refer to st52x301 data sheet. introduction to fuzzystudio ? 3.0 fuzzystudio ? 3.0 is the development system that allows to program w.a.r.p. family of fuzzy processors. this high level tool helps you to: develop applications without assembler programming, verify a developed project and program the microcontroller through the programming board supplied with fuzzystudio ? 3.0. thanks to the fuzzy logic approach, fuzzystudio ? 3.0 makes programming fast and easy even for those development phases which follow a traditional kind of approach. since st52x301 is able to manage fuzzy functions, arithmetic calculations and logic instructions, fuzzystudio ? 3.0 allows to develop a project and the management of all the various resources. moreover, fuzzystudio ? 3.0 provides a visual programming approach to graphically define the programs logic flow by means of interconnected blo cks. this can be achieved by des igning the flow-chart which refers to your project by inserting the appropriate blo cks. each block you insert is already designed for a definite type of functionality which can be programmed either in a graphic way or with instructions at high level. the links among the blocks determine the logic flow of the program. a double-click on the single block opens a programming environment specifically dedicated to the type of block. fuzzystudio ? 3.0 is equipped with tools that allow to generate the machine code and to perform the debugging of the program. it is characterized by the following main functionalities: fuzzy programming. arithmetic programming. programs logic flow definition. peripheral configuration and activation. programming and activation of interrupts and routines associated. machine code generation. full chip emulation in graphic environment. chip eprom memory programming. possibility to program at low level using st52x301 assembler. * formerly w.a.r.p.3tc 1
fuzzystudio ? 3.0 main blocks are: start block starting point of the program. fuzzy block allows to performs the fuzzy functions. arithmetic block carries out airthmetic and logic operations. assembler block allows to insert arithmetic instructions in assembler. conditional block it is a conditional block that modifies the program flow in relation to user-defined conditions. interrupt mask block enables interrupts. interrupt priority block manages interrupt priority. peripherals block enables/disables and sets/resets the peripherals. send block sends the value to a peripheral coming from a register. receive block receives a value from a peripheral and stores it in a reg- ister. wait block stops the program until the first interrupt signal. restart block restarts the program. folder block allows to group blocks. links connects two different parts of the program. thanks to these blocks it is possbile to realize the desired project by simply drawing the program flow-chart and fixing each block functionalities. 2 fuzzystudio ? 3.0 user manual
system variables overview the systemvariables are managed through the chips internal registers. the fuzzy variables are those that are in input and output in the fuzzy computational unit. the variables support the following types: signed byte integer values included in the range [-128, 127]. byte integer values included in the range [ 0, 255]. in addition, when you define a fuzzy variable and its associated term set with the fuzzy variables edito r, it is possible to define the universe of discourse respectively in the ranges [-128, 127], [0, 255], [x, y] where x and y are values defined by the user. note there are 256 intervals available (8-bit). the arithmetic operations are performed on 8-bit variables with signed or unsigned values (signed byte [-128, 127] / byte [0, 255]) which refer to the internal registers of the machine. the variables can be global or local . the global variables can be defined by using the "global variable window", while the local variables can be defined within an arithmetic block and can be used only inside that block. the operations between different types of variables are managed in a transparent way by the compiler in order to see at an editor level the signed variable (signed byte type), although at a machine level only the type defined in the interval [0, 255] (byte type) exists. fuzzystudio ? 3.0 also supports another type of variable: predefined variables . these are particular variables having reserved predefined names. they address particular registers of the chip (typically the peripherals ones). the predefined variables must be considered as byte type and can be used to perform ordinary operations. for more information refer to chapter 6 for a list of these variables. 3 chapter 1 - fuzzystudio ? 3.0
programming approach the fuzzystudio ? 3.0 visual programming approach has been designed in order to help you in the development of a project. these are the main phases: peripherals configuration. the peripherals configuration is obtained by means of dialog boxes recalled from the project window. you can choose the peripherals working mode by clicking on the relative check box. the configurations which are not allowed are automatically disabled and in case you do not carry out a choice, default selections are available. for example, the initial state of the peripheral is considered disabled by default and to enable it you have to open the start/stop block of the peripheral at the beginning of the program. global variables definition. you can define the global variables name, type and association to the register through an apposite dialog window recalled from the project window. flow-chart creation. it is possible to design a program formed by a main program and subroutines directly defining the programs flow-chart. after opening the main program window, or a subrouti- nes folder window, to draw the programs flow chart, you must choose the type of block you want to insert by clicking on the relative button of the block editor toolbar, and then click on the client-area to insert as many blocks as you desire. you can perform the same operations with the other blocks and connect them according to the logic flow of the program. the link between two blocks is performed by means of click & drag operations. the blocks designed and interconnected can be selected to be modified, moved, deleted and so on. the links can be extended, shortened, disconnected, or deleted. open each block to be able to establish the operations you want to perform in that block. each block you insert in the flow-chart, corresponds to a peculiar editing environemnt which can be opened by double-clicking on it (except for the wait , start and restart blocks). for example: the editing tool of the arithmetic block is a text editor which allows to write the arithmetic operations that the processor has to perform. it is possible to insert the conditional statement if among the arithmetic instructions inside an arithmetic block of this type. refer to further paragraphs for the description of the possibile operations and for their grammar. all is written by the programmer can be checked by means of a check command which performs a syntactic and semantic check providing a list of the errors: with a double-click on this list you can visualise immediately the code line which has produced the error. a double-click on the fuzzy block allows to open the fuzzy system editor : the environment of the variables definition, of the membership functions and of the fuzzy rules. a project can have more than one fuzzy block defined in different points of the program and this allows to apply fuzzy adaptive control algorithms. the structure of the fuzzy controller and the membership functions are defined in a graphic way, while the rules are defined through the rule editor . the conditional block allows to modify the program flow according to defined conditions. 4 fuzzystudio ? 3.0 user manual
the assembler block allows to perform the programming of the device directly in the assembler of the chip. the folder block allows to insert a group of blocks in a separate folder window, so as to simplify the flow-charts routine. moreover, it is possible to manage the interrupts and peripherals start/stop by means of apposite blo cks. define the interrupts service routines. st52x301 can manage the interrupts which derive from the peripherals (timer, a/d, sci and triac driver) and from the external interrupt pin and perform the relative service routines. to be able to define the service routines, in terms of instructions or commands, you work as in the main program, but inside the client area related to each interrupt, recalled from the project window. compile the project to generate the debugging and the machine codes. the project compilation is carried out choosing compiler from the tools menu. then, a report window will open displaying the program errors, if any, or a message of successful compilation. after the compilation, some files are generated: a file containing the program listing in a wcl (w.a.r.p. control language) script file; an assembler code file; a file containing information used by the debugger ; and the code to be loaded in st52x301 memories in the standard format or in the one specified in the compilation options. in case of errors in the compilation, you have to correct and compile your program again. use the debugger to validate the program. after the compilation has been succesfully completed, the program can be tested by using the debugger. the debugger is a tool that allows to emulate the processor and its on-chip peripherals according to the defined program. the simulation step considered by the debugger is the single clock cycle, then the graphics that it is able to produce are in function of the time. you can choose the signals and/or the registers to visualize, as well as the time interval to simulate. moreover, it is possible to establish the breakpoints on the program and go step by step to better examine the behaviour of the device according to the program. you can also supply the input set to the chip to simulate external connections to the input pins. the registers values and the status of the signals chosen can be visualised in a table through tracing in temporal function. if the results of the simulation are not satisfying, appropriate changes have to be performed to the current program stored in memory. recalling the debugger it automat- ically starts the compilation. program st52x301 with the board supplied with fuzzystudio ? 3.0. the final step is to program st52x301 memory by means of the programming functions and the electronic board connected to the pc through the parallel port. testing of the application. now you can insert the programmed chip in your own application and test it. 5 chapter 1 - fuzzystudio ? 3.0
6 fuzzystudio ? 3.0 user manual
chapter 2 project management project files management fuzzystudio ? 3.0 stores all the project data into a single file with the extension .fs3. to select the commands for the project file management (for example, save or open), choose from the file menu . the content of the file menu is different according if there is an opened project or not. working with a new project if the project has not been opened yet, the commands available for the project file management are the new and the open commands: new the new command allows to start a new project. when you choose this command, fuzzystu- dio ? 3.0 displays the new project dialog box to define the project name, specify the target chip and describe the project (these information can be read later by choosing project info). the file name has to be compatible with a standard file name because to this will be added the extension .fs3 when saving the file. it is also possible to specify a path to locate a project file in a directory different from the default one. the browse button opens a dialog box that allows to quickly select the directory of destination of the project file. note this file is not generated when performing the command new, but after a save or save as command. in particular, the save as command allows to change the name of the file (and the name of the project) and its destination. it is easier to keep the default name i.e. untitled and then de- cide later where to store it and its name. to carry out this command in a quicker way it is possible to use the toolbar button or press ctrl+n . 7
working with an existing project open the open command allows to open a project previously saved. on the open command a dialog box will pop up, allowing you to select the project file to be loaded. acting on the provided scroll down lists, you must choose drive, directory and file name, using the ok button to finally execute command. into a networked environment, the network button can be used to connect to remote drives before selecting the data to be loaded. to carry out this command quickly it is possible to use the toolbar button or press ctrl+o. if there is an active project, the file menu is modified and the following commands are available: close project the close project command allows to quit the current fuzzystudio 3.0 project. the same effect is obtained when fuzzystudio 3 is closed from the main window or when closing the project window. then, you are asked to save the project if you have carried out some modifications not saved yet. saving and printing files save the save command will directly update the project file. a simple backup mechanism is im- plemented by copying the project file to a file with .bak extension before updating it. in this way, you can open the current project data and the previous version. to quickly perform this command use the relative toolbar button or press ctrl+s. if no modification has been carried out after the last saving, the save command is disabled. save as on the save as command a dialog box will pop up, allowing you to change current project name. the dialog box looks as the open project box, but the selected file will be used to store project data and not to retrieve from them. save command will prompt for confirmation before overwriting an existing file. project info allows to read the information relative to the project (target chip, name, working directory) and to read / write the project user description. print to print the project use the print command in file menu. to quickly perform this command press ctrl+p. printer setup and print preview commands are also available in file menu. 8 fuzzystudio ? 3.0 user manual
the fuzzystudio ? 3.0 main window this section provides an overview of the major elements of the fuzzystudio 3.0 main window, such as menus, toolbar and status bar. for additional information, see the index and online help. the fuzzystudio ? 3.0 window application menus file contains commands to create a new project, to open an existing one or to change the printer and printing options, a list of recently used files. view contains commands to show or hide main toolbar and status bar. help contains help commands. 9 chapter 2 - project management
the fuzzystudio ? 3.0 main windows toolbar for convenience, the most frequently used commands can be executed by choosing the corre- sponding buttons available on the toolbar. new open, save cut, copy, paste print, about, context-help the fuzzystudio ? 3.0 main windows status bar the status bar displayed at the bottom of the main window provides a brief description of the currently selected command. compiler, debugger, programmer 10 fuzzystudio ? 3.0 user manual
the fuzzystudio ? 3.0 project window a project definition environment can be accessed by means of the project window, that you see at a first glance when you start a new project or open an existing one. this window contains all the objects that make up the program: main program, sub-routines, interrupt routines, global variables and peripherals settings. in the project window you will find the icons that allow to access the various development and editing environments of the main parts of the project: a double-click on these icons allows to open the relative editing window. project window 11 chapter 2 - project management
working environments the project window icons allow to easily access the fuzzystudio ? 3.0 working environments. the following list briefly describes the function of the each project windows icon: main program opens the block editors main_program window . variables opens the global variables definition and editing environ- ment window. peripherals opens the peripherals programming environment. timer interrupt opens the window for the programming of the timer inter- rupts service routine. triac interrupt opens the window for the programming of the triac inter- rupts service routine. a/d interrupt opens the window for the programming of the a/d inter- rupts service routine. sci interrupt opens the window for the programming of the sci inter- rupts service routine. external interrupt opens the window for the programming of the external in- terrupts service routine. note: any window can be recalled by the window menu . 12 fuzzystudio ? 3.0 user manual
chapter 3 initial settings this chapter explains how to carry out the initial settings of your project. the first actions you have to perform to start a project will be the configuration of the devices peripherals, according to the selection of the target processor, and the definition of the programs global variables. these operations are performed through the dialog boxes which can be invoked from the peripherals and variables icons of the project window. global variables global variables are used in the arithmetic and conditional blocks. at low level, they refer to the processors registers and contain 8-bit values: byte type (from 0 to 255) signed byte type (from -128 to 127) how to insert a global variable the procedure to insert the global variables is the following: 1 click on the icon named variables in the project window to open the global variables dialog box. 2 click add button to open the dialog box add global variables. 3 insert the name of the variable. 4 select the type (byte or signed byte). 5 click ok. the dialog box closes and the variable appears in the defined variables list. 6 repeat for the other variables and then click the button close. 13
deleting a global variable you can delete a global variable in the following way: 1 in the global variables dialog-box select the variable to delete from the apposite list. 2 click the remove button. the variable is deleted from the list and will not be available anymore. 3 click close to exit and confirm the deletion. note in case you delete a global variable which is already being used in arithmetic or conditional blocks, the program remains unchanged and then in case of check or compilation, an error of the kind "not-defined variable" is generated. global variable properties clicking on the button properties, the global variable properties dialog box appears. this is similar to the dialog box for the insertion of a new global variable (add button), and allows to visualize and eventually modify the name and type of the global variable selected. when you select a global variable from the list you are shown its type at the bottom of the dialog- box. note the variables names have to be made up by alphanumeric characters, they cannot start with a number, they must not be equal to keywords (of the wcl description language and the assem- bler) and must have a maximum length of 32 characters. the names are case-sensitive. you can define 14 global variables at most, if you are using two fuzzy antecedent data memory banks. if you are using three or four fuzzy antecedent data memory banks, you can define respectively 13 or 12 global variables at most. a warning message informs you that you are defining too many variables without deleting them. 14 fuzzystudio ? 3.0 user manual
frequency setting from the peripherals icon in the project window, it is possible to specify the microcontrollers clock frequency by selecting the value from the drop-down list available on the peripherals window. note for st52x301 the available frequencies are 5 mhz, 10 mhz and 20 mhz. for more information refer to data-sheets for further information on st52x301 clock frequency. peripherals configuration you can configure st52x301 peripherals by double-clicking on the peripherals icon in the project window and in the appearing dialog-box, selecting the peripheral among the ones available in the following list: a/d converter parallel port timer sci (serial communication interface) triac driver the configuration of the peripherals can be performed by selecting the check-boxes and the radio-buttons in apposite dialog-boxes, in order to set the functionality of the chosen peripheral. to open the peripherals setting dialog-box and to perform the configuration it is necessary to select the peripheral from the list and click on the button config..., or you can directly open the setting dialog box with a double click on the peripheral name. for more information refer to the following paragrahs and st52x301 data sheet for information on a specific peripherals configuration. 15 chapter 3 - initial settings
after having completed the settings of the peripherals, click ok button to confirm the settings (if you press cancel you eliminate the changes performed). if no setting has been made or if the configuration of the peripheral selected has been partially performed, only the default values are activated. the button set default confirms the default configuration of the selected peripheral. the chosen configuration corresponds to a series of assembler instructions of the following type: ldcf reg_conf, value where: reg_conf is a value from 0 to 15 and refers to the address of the peripherals configuration registers. value is a value from 0 to 255 depending from the setting performed and from the configuration register. see appendix c for further information on assembler instructions. 16 fuzzystudio ? 3.0 user manual
timer configuration it is possible to configure the timer through the dialog-box shown below: you can note different sections of configuration each having a different meaning: frequency allows to visualize the selected working frequency of the processor clock. the possible choices are 5 mhz,10 mhz or 20 mhz and can be selected from the peripherals window. prescaler out period allows the setting of the prescaler timer, i.e. the value for which the clock frequency is divided before being passed to the counter. it is possible to specify the value (included in the range 0 and 65535) that is written in the configuration registers of the timer and visualize the corresponding value of the period in m s of the output signal of the prescaler in case the source clock is internal. viceversa, it is possible to specify the time value thus automatically obtaining the value loaded into the register. take care that if you enter a time value, it will be performed a conversion for approximation. then this value can slightly differ during the implementation in the device. output polarity allows to establish if the output signal logic level of the timer in the pin timerout has to be high or low. 17 chapter 3 - initial settings
timerout wave form allows to choose the output wave form of the signal on the timerout pin. the possible selections are square or pulse wave form, as it is shown in the figures present on the dialog-box. in the first case the timer output is equal to a square wave with a duty-cycle equal to 50 % and period equal to the period of the prescaler multiplied by the value of the count to perform. in the second case, the timer output is a pulse with length equal to a the output signal period of the prescaler. start/stop allows to choose if the timer count can be started/stopped by an external signal or by a program and if this occurs on edge or level of the external signal. counter loading from allows to choose the data source to load on the timer counter. the source of this data can be one of the two fuzzy outputs units, or a variable specified from the program. clock source allows to choose the origin of the input clock signal to the prescaler. the possible choices are the internal clock or an external clock coming from the timer_clock pin. in this last configuration the timer can work as an event counter. interrupt signal on allows to establish the event generating the timer interrupt signal. the possible choices are: - interrupt on the counter stop - interrupt on the rising edge of the signal timerout - interrupt on the falling edge of the signal timerout - interrupt on both edges of the signal timerout selecting counter stop the other two possibilities are automatically excluded and viceversa. the counter stop interrupt signal can occur both with an internal stop from the program and external stop from the timer reset pin. in this case, it is possible to use timer interrupt as external interrupt. 18 fuzzystudio ? 3.0 user manual
triac driver configuration the triac driver is a peripheral able to work in three different modes: burst mode,phase partializ- ation , pwm driver (refer to data sheet). the dialog-box used to configure the triac driver changes according to the working modality chosen. sections common to the three modes frequency allows to visualize the processors frequency: 5, 10 or 20 mhz. output polarity allows to establish the polarity of the triac output pulse in the trout pin . the possible choices are positive (logic level high) or negative (logic level low) mode allows to establish the working modality of the triac driver. the possible configurations are pwm, burst and phase partialization. modifying the selection, the lower part of the dialog-box is modified too in order to supply the configurations sections. interrupt source allows to establish the event generating the triac driver interrupt signal. you can choose among the following modes: pwm: the rising edge and/or the falling edge of the counter signals (see data sheets). burst mode:the rising edge and/or the falling edge of the counter signals (see data sheets). phase partialization: the rising edge and/or the falling edge zero crossing signals of the power line positive and negative wave, coming from the main1 and main2 pins. counter loading from allows to choose the data source to load on thetriac driver counter. the data source can be one of the fuzzy unit outputs , or a global variable stored in a register, loaded from the program. 19 chapter 3 - initial settings
pwm mode prescaler setting allows to set the triac driver prescaler. it is possible to specify the value (0 - 65535) that is written in the triac driver configuration registers and visualize the corresponding value in m s of the whole control period, that means 256 *tckp (where tckp is the period of the prescaler output). the value loaded in the counter is proportional to the ton period of the wave. see datasheet for further details. in the same way it is possible to directly set the value of the period in m s. clock source allows to choose the origin of the clock signal in input to the prescaler. the possible choices are: internal clock, external from the main 1 pin or the power line frequency through the main1 and main2 pins. main2 pin setting allows to configure the main2 pin as input/tristate to receive the frequency as external clock (see above) or in output supplying to the pin the prescaler output, that is the clock that drives the triac driver counter. then, if you set a control period of 256 m s, the main2 pin output will have a period of 1 m s. 20 fuzzystudio ? 3.0 user manual
burst mode square wave period allows to set the triac driver prescaler. in this case the the prescaler is driven by the power line frequency through main1 and main2 pins, then it is possible to specify the value (included in the range between 0 and 65535) written in the triac driver configuration registers and visualize the corresponding period value in seconds of the whole control period, that means 256*tckp where tckp is the period of the prescaler output. the value loaded in the counter is proportional to the ton period of the wave. see datasheet for further details. in the same way it is possible to directly set the value of the control period in seconds. trout impulse width allows to establish the output pulse width to drive the triac. it is possible to specify the value (included in the range between 0 and 16383) that is written in the configuration registers of the triac driver and visualise the corresponding value of the period in ms of the pulse. in the same way it is possibl eto directly set the value of pulse width in ms. power line frequency allows to specify the frequency of the mains voltage of the system controlled. the possible choices are 50 hz (european standards) or 60 hz (american standards). modifying such a data, the control period will change. masking time allows to set a minimum delay time between two firing pulses, masking during this period zero crossing signals due to noise. refer to st52x301 data sheet for further information. 21 chapter 3 - initial settings
phase partialization prescaler setting in phase partialization mode this parameter is not required then the check box is disabled. trout impulse width allows to establish the length of the output pulse to drive the triac. it is possible to specify the value that is written in the configuration registers of the triac driver and visualize the corresponding value of the period of the pulse in ms. the minumum value you can specify is 0, while the maximum value depends on the frequency of the clock master: 624 for 5 mhz 1249 for 10 mhz 2499 for 20 mhz (that corresponds to 250 m s) in the same way it is possible to directly set the value of a pulse width in m s. power line frequency allows to specify the the power line frequency. the possible choices are 50 mhz (european standards) or 60 hz (american standards). 22 fuzzystudio ? 3.0 user manual
a/d configuration it is possible to configure the a/d converter by means of the dialog-box shown below: the only information to set is the number of the channels to convert. parallel port configuration it is possible to configure the parallel port through the following dialog box: it is possible to utilize each pin of the parallel port as input or output. it is possible to specify the direction of a single parallel port pin by clicking on the pin button. read arrows mean output pin, blue arrows indicate input pin. 23 chapter 3 - initial settings
serial communication interface (sci) configuration. the sci is a hardware implementation of the standard rs-232 communication protocol. the programming of this peripheral allows to establish the characteristics of the data frame, trans- mission speed and the events that can generate interrupts. it is possible to configure the sci by means of the following dialog-box: baud rate determines the communication protocol speed. the followings are the acceptable values: 600, 1200, 2400, 4800, 9600, 38400 baud. moreover it is possible to specify that the speed is driven by an external clock. data bits determines the data bit length. the possible choices are 8 and 9 bits. it is not possible to choose 9 bits when choosing to use the parity check or 2 stop bits. parity allows to configure the peripheral with or without the parity check. it is possible to choose also the parity type you want to obtain that is to say odd or even. it is not possible to use at the same time the parity check with a number of data bits equal to 9 bits or 2 stop bits. stop bits determines the number of stop bits of the frame: 1 or 2 bits. this last option can be selected only in case the parity check is not used or in case of 8 data bits. 24 fuzzystudio ? 3.0 user manual
interrupt source determines the events generating an interrupt: tx register empty: the transmission buffer has been read by the shift register for the transmission. tx completed: data transmission is complete. rx register full: the data reception has been completed and the reception buffer is full. overrun error: an overrun error occurred. a new data item has been re- ceived before reading the one received previously. line break error: an error due to the interruption of communication has oc- curred. note more than an event can be chosen to generate an interrupt signal. however, this last is unique and to discriminate the event that has generated the interrupt it is possible to use the instruction scistatus with an arithmetic block (see relative paragraph). besides establishing if a specific event has generated the interrupt, allows to manage (in polling) other events that do not generate the in- terrupt: the "frame error", "noise error" and the 9th bit data contents if the peripheral has been set appropriately. for further details refer to related chapters. 25 chapter 3 - initial settings
26 fuzzystudio ? 3.0 user manual
chapter 4 block editor tool the block editor is the tool for the "visual" programming of the chip, that allows to specify the logic flow of the project and the access to the various definition environments of the program. each part of the program (main, interrupt routines and folders) is obtained by inserting logic blocks appositely interconnected that create the routines flow-chart. this operation is performed by the block editor that is activated in the windows related to the main program, interrupt routines and subroutines. the block editor tool this section provides an overview of the major elements of the block editor such as menus, toolbar and status bar. for additional information, refer to the index and on-line help. 27
block editor menus all block editor commands are grouped into a menu hierarchy accessible from the main window menu. menus items are context-sensitive: at each time only relevant commands for the selected objects or for the current project status will be enabled. available menus are: file contains commands to create, open, close,save and print a project and to visualize the projects information. edit provides standard editing commands. view contains commands for toolbar and status bar display or hide. tools contains commands to run debugger, compiler or programmer tools. insert allows to insert the blocks for the creation of a flow-chart. window contains commands related to window management. help contains help commands. 28 fuzzystudio ? 3.0 user manual
block editor toolbar the block editor includes a toolbar to help you perform the most frequently used commands quickly. to execute a task by means of a button, just click the related button on toolbar. the cursor allows to select and move blocks and links within the client area. the blocks you can select from the toolbar are: cursor selects and moves blocks and links within the client area. fuzzy block includes a fuzzy system. arithmetic block inserts arithmetic and logic instructions. assembler block inserts assembler instructions. conditional block determines program jumps according to the specified condi- tions. interrupts mask block enables or disables the processor interrupts. interrupts priority block specifies the interrupt priority level. peripheral block enables or disables the peripherals. wait block stops the processor waiting for an interrupt. restart/return block restarts the main program immediately after the start block or, in a folder returns to the main program. folder block includes a part of the logic flow. link block links the blocks among each other. block editor status bar the status bar displayed at the bottom of the block editor window contains some information about the task you are working on. cursor fuzzy , arithmetic, assembler and conditional blocks interrupt mask and priority, peripheral, send and receive blocks wait and restart/return blocks folder and link blocks 29 chapter 4 - block editor
program starting point when you open the main program, interrupt or folders window the first block in your flow-chart will be the start block. the start block is inserted automatically and is the beginning of the related program. at this point, it is possible to insert the logic blocks and to carry out the actions listed below: how to insert a block 1 from the project window toolbar, you can select the block you want to insert in your project. 2 position the mouse cursor anywhere on the project window. 3 click the left mouse button. the new block is inserted in your project. 4 drag the mouse to the desired position and then release it. how to link two blocks a link is characterized by an arrow indicating the sequence of the program execution. 1 from the project window toolbar, select the link button. in this way you commute to the link insertion modality. 2 position the mouse cursor on the first block to be linked. 3 click the left mouse button 4 drag the mouse on the second block and : if you still havent released the mouse button you can release it now. or click again you can add a link to any block, without necessarily linking the block to another one. to do this, click twice on the clinet area. the links allow to carry out cyclical programs without using restart command simply connecting the last block of the program to the point from which you want to make it proceed. labels a label is associated to each block, i.e a symbolic name. such label is representative of the program address in which the instructions contained in that block start. default names are inserted automatically at the moment of the insertion of the block, but they can be changed anytime by selecting the item rename from the pop up menu that appears when you click on the block with the right mouse button. the labels can be moved around the block by simply click & drag: they can be snapped on the cardinal points or they can be positioned anywhere around the block according to the activation of the item snap on or snap off you can choose from the pop up menu which appears by clicking on the label with the right mouse button. note labels must contain no more than 32 characters. 30 fuzzystudio ? 3.0 user manual
single and multiple selection of a block to select a block, it is necessary to click on it. take note that this operation cannot be performed in link insertion modality. in this case, you will have to make the cursor active before to select the block. in cursor modality, it is possible to simultaneously select more than one block by a click & drag operation. this will open a frame in which the blocks are selected. it is also possible to select more blocks one by one by clicking the mouse on the block and holding down the ctrl button until the end of the selection. the blocks and the links selected can be easily recognized because they change colour: the blocks become grey and the links become green. note you can activate cursor modality by clicking the right mouse button on window client area. when already in cursor modality, ths action will open a pop-up menu. basic commands a block, or a set of items selected at the same time, can be freely moved inside the window by using the mouse. moreover, any block can be: open opens the blocks editing environment. close closes the editing environment if previously opened. rename allows to change the label associated to the block. delete deletes the block and its content (this command can also be perfomed by pressing the delete button on the keyboard). you are asked for confirmation before deleting the block. this command list is a pop up menu obtained by clicking on the selected block with the right mouse button. in case of multiple selection, clicking with the right mouse button on one of the selected blocks (with the exception of the start block since it cannot be deleted), the pop up menu described above will appear. as you can notice, the item delete all selected is added to this list. this command allows to delete all the selected blocks and links. 31 chapter 4 - block editor
how to use links the links interface is similar to the blocks one. a link can be selected,deleted and moved (to move a link involves the moving of the linked blocks at the same time). a link has a pop up menu that can be otained by clicking with the right mouse button over a link to: delete delete the links disconnect from start block disconnect the link from the start block disconnect from end block disconnect the link from the destination block disconnect from both disconnect the link from both blocks moreover, a link can be the target of another link. other commands clicking on the block editor client-area when in cursor modality with the right mouse button a pop up menu appears containing the following items: grid enables or disables the grid line up alignes the block editor objects on the grid 32 fuzzystudio ? 3.0 user manual
chapter 5 fuzzy block the fuzzy block allows to carry out the fuzzy functions to be performed by the program of control implemented in st52x301. the possibility to define more than one fuzzy block allows to use, in the block diagram, the fuzzy system which is more appropriate to the general conditions of the system and then to realize an adaptive fuzzy control system. overview you can insert a fuzzy block in your project by choosing fuzzy block from the insert menu. (or by clicking on the fuzzy block toolbar button from the main program window). the mouse pointer changes its status and allows you to insert one fuzzy block anywhere on the main program window by clicking on the desired position. in this way, you are able to run the fuzzy system editor: the development environment, dedicated to the fuzzy functions, in which it is possible to define the variables and the set of rules associated to the fuzzy function. the fuzzy system editor interface employs a block structure with three different types of blocks: two for the definition of input and output variables and one for the editing of the rules. double-clicking on a variable block, a window pops up allowing you to define the variable properties: name, universe of discourse boundaries and the related mbfs. running the rule editor, it is possible to edit the rules which define a fuzzy function. but before doing this, it is necessary to define at least one input and one output variable. you can run the rule editor by double-clicking on the fuzzy rules block. when you insert a rule containing a new variable, a link between this variable and the relative block of rules automatically appears. 33
the fuzzy system editor window the first time you open a fuzzy block, the fuzzy system editor window shows an empty block named rules block. then it is possible to insert, anywhere on the window, up to 4 input variables and up to 2 output variables. this section provides an overview of the major elements of the fuzzy system editor window, such as menus, toolbar and status bar. for additional information, see the index and online help. fuzzy system editor toolbar the fuzzy system editor includes a toolbar to help you to quickly perform the most frequently used commands. to execute a task by means of a button, just click the related button on the toolbar. cursor input/output var import var fuzzy system editor status bar the status bar displayed at the bottom of the fuzzy system editor window contains information on the fuzzy block you are currently working on and displays a brief description of the selected command. the status bar provides the number of variables (input and output) and and rules in the current fuzzy block. 34 fuzzystudio ? 3.0 user manual
fuzzy system editor menus fuzzy system editor menus are: file provides new, open, save and print file utilities, a list of recently used files and the exit command. edit provides standard editing commands. view contains commands to show or hide block chart toolbar, main toolbar or status bar. tools contains commands to switch to fuzzystudio ? 3.0 tools: debug- ger, compiler and programmer. insert allows to insert input and output variables, link variables from other fuzzy blocks and import fuzzy systems in f.u.l.l. language. window contains commands related to window management allowing to arrange or activate windows. help contains help commands. about fuzzy variables the possibility to define the number of input variables and mbfs, within each block, depends on what has been already defined in the other fuzzy blo cks. this is due to the chip memory area used to store these information, which is limited and common to all the fuzzy blocks (refer to "variable constraints definition in a fuzzy block"). you can open a variable block by double-clicking on it or by activating the menu with the right mouse button. in this way the fuzzy variable editor window will be open. this allows you to enter into the development environment dedicated to the fuzzy variables, in which it is possible to define the universe of discourse and the mbfs. the first step to create a fuzzy project is to define its variables. for each variable you need to define: name universe of discourse (ud) membership function (mbf) default settings are available. during a session an existing variable window could be: open the variable window is open on the fuzzystudio ? 3.0 window. active the variable window is in foreground. all commands working on variable parameters modify it. an open or iconized variable becomes active by clicking on it. iconized the variable window is iconized on the fuzzystudio ? 3.0 window. close the variable window does not appear on the fuzzystudio ? 3.0 window. 35 chapter 5 - fuzzy block
variable constraints definition in a fuzzy block generally, in a fuzzy block it is possible to define up to 4 input and 2 output variables. this possibility is sometimes limited by the presence of other variables defined in other fuzzy blocks. all the input variables defined inside the fuzzy blocks share the same on-chip memory banks. this imposes some constraints in the number of the variables and mbfs to be added in each fuzzy block. the fuzzy system editor automatically prevents to exceed the chip memory limits, according to what has been previously defined in each fuzzy block. in this case, the fuzzy system editor disables the commands which allow to create new variables and mbfs. st52x301 contains 4 memory banks dedicated to the storage of 4 * 16 mbfs each one associated to one input to the fuzzy core. you can define: up to 4 variables, each one may contain up to 16 mbfs up to 3 variables, one of which may contain up to 32 mbfs up to 2 variables may contain up to 32 mbfs 1 variable containing up to 64 mbfs all chip memory is available when you define the first fuzzy block of your project. then, there will be some constraints for the definition of other fuzzy blocks since part of the memory is now busy. in this case, the maximum number of the variables which can be defined is: n = ? i = 1 4 min (1, 16 - m i ) where m i is the number of mbfs defined on each bank of memory from all the variables already present on the previous blocks. if you define n variables, it is possible to associate a maximum number of mbfs 16 - m i (i = 1, ...., n) where i is such that 16 - m i different from 0 n = ? i = 1 n (16 - m i ) where i is such that 16 - m i different from 0 the available mbfs can be used in a different way by defining a number s < n of new variables; in this case it is possible to associate a number greater than 16 m i mbfs. in this case for a single variable it is possible to define a maximum number of mbfs equal to: ? i = 1 n - s + 1 (16 - m i ) where i is such that 16 - m i different from 0 when s=1 all remaining mbfs can be used for the variable in question. 36 fuzzystudio ? 3.0 user manual
how to insert a fuzzy variable block inside the fuzzy block it is necessary to define the variables you need to use in your project. the definition might occur in three different ways: creating a new fuzzy variable, sharing or copying an existing variable. to create a new fuzzy variable : 1 from the insert menu, choose the kind of variable by selecting input varor output var. you can also click the input or output toolbar buttons available on the fuzzy system editor window. after this operation the mouse pointer changes its status. 2 click the mouse button anywhere on the window area in order to insert a new fuzzy variable block. to share an existing fuzzy variable: a variable can be shared among two or more fuzzy blo cks. for more informat ion refer to paragraph " shared and copied variables" in this chapter. to copy an existing fuzzy variable a variable can be copied from another fuzzy block using copy, cut and paste commands. for more information refer to paragraph " shared and copied variables" in this chapter. how to delete a fuzzy variable block you can delete unnecessary or unwanted variables in the following way: 1 from the fuzzy system editor window, select the variable block or the variable blocks you want to delete. in case of multiple selection, you can either use the mouse to create a frame or select each variable block by clicking without releasing the ctrl button. 2 press the delete button on the keyword. you can either choose delete from the edit menu or click the right mouse button to select the item delete or delete all selected from the pop up menu. 3 you are asked for confirmation before deleting. click yes or yes to all to complete the operation; click no to skip current variables deleting. quit to end operations. how to close a variable window an open variable window can be closed via the close active command of the windows menu. this command can only be performed in the current variable window. 37 chapter 5 - fuzzy block
fuzzy variable initialization and storage to assign a value, to be computed, to the fuzzy input variable by using fuzzystudio ? 3.0 it is necessary to associate it to a global variable, or an input register by using a predefined variable (refer to arithmetic block chapter for more information on predefined variables), containing the crisp value . click with the right mouse button on the input variable block you want to initialize. choose initialize from the appearing pop-up menu. a window containing a drop down list box will open. the list-box contains the available global and predefined variables. during the compilation, if the initialization of the variable is omitted, an error message will appear. the same operation can be carried out opening the fuzzy input variable with a double-clicking on the input variable block and choosing var properties from the view menu or from the toolbar. besides the editing fields of the variable name and universe of discourse, you will find a drop down list-box that works in the same way. 38 fuzzystudio ? 3.0 user manual
to store the fuzzy output in a global variable or send it to a peripheral, it is possible to act as for the initialization. click with the right mouse button on the output variable block where you want to store the value. choose "store in ..." from the appearing pop-up menu. a window containing a drop down list-box will be open. the list-box contains the available global or predefined variables (see arithmetic block chapter for explanation about predefined variables). select the one you are interested in. the same operations can be carried out opening the fuzzy output variable double-clicking on the block and choosing var properties from the view menu. besides the editing field of the variable name and universe of discourse, you will find the drop down list-box that works in the same way. after initialization and storage phase, in the fuzzy system editor window, labels linked to the fuzzy variables will appear. such labels will contain the global or predefined variables, or peripherals names, used to initialize and store the fuzzy variables. note the fuzzy outputs can be sent directly to the timer and triac counter automatically by setting the peripherals in the apposite peripherals configuration dialog-boxes (see related chapter). 39 chapter 5 - fuzzy block
the fuzzy variable editor window fuzzy variable editor is the tool devoted to manage with fuzzy variables and their mbfs. this section provides a description of the features of this tool. fuzzy variable editor menu file provides new, open, save, print file utilities, a list of recently used files, the project info and the exit command. mbf allows to choose commands for the creation, modification and deletion of mbfs and the copy on clipboard as bitamap command. view allows to choose commands to show or hide toolbar and status bar; double the size of the window and to open the windows of the variable properties and a mbf report. too ls contains commands to switch to fuzzystudio ? 3.0 tools: compiler, debugger and programmer. options allows to choose commands about the mbfs colours, show/hide of coordinates and hide of printing names. window contains commands related to window management. help contains help commands. 40 fuzzystudio ? 3.0 user manual
fuzzy variable editor toolbar the fuzzy variable editor includes a toolbar to help you to quickly perform the most frequently used commands . to execute a task by means of a button, just click the related button on the toolbar. fuzzy variable editor status bar the status bar displayed at the bottom of the fuzzy variable editor window contains some information about the number of rules you are currently working on and displays a brief description of the selected command. new, delete , auto fill mbfs properties zoom active mbf 41 chapter 5 - fuzzy block
how to open a fuzzy variable block to open a variable block: double-click on the fuzzy variable block. or click on it with the right mouse button and choose open from the pop up menu. the variable window appears allowing you to edit the properties and the mbfs associated. once opened, a variable window can be magnified ( ctrl+z ) via the zoom x 2 command of the view menu. this menu item and the related toolbar button acts as on/off switches, allowing users to magnify and de-magnify a window by repeatedly clicking on it. this command acts only for the active window. note the caption of the variable windos shows the name of the variable and the fuzzy block to which it belongs using the format fuzzyblockname\varname. 42 fuzzystudio ? 3.0 user manual
how to modify the fuzzy variable properties the variable properites are: name universe of discourse boundaries intialize / store in variables once the variable has been created, you can modify its properties so as to associate a more explicative name and to set the lower and upper bound of its universe of discourse according to the range of the physical value. to modify the fuzzy variable properties: 1 open the variable window. 2 from the view menu, choose var properties (or simply click on the apposite fuzzy variable editor toolbar button). 3 modify the name, the lower and upper bound of the universe of discourse by inserting the appropriate information on the dialog box. 4 choose ok. by default the variable name is set to "var x ", where x is a progressive integer value starting from 1, and the universe of discourse is set to [0, 255]. variable names may contain only alphabetical characters, numerical digits and the underscore symbol (_). the first character must be an alphabetical one or the underscore. (names must contain no more than 32 characters). due to its internal resolution, st52x301 takes into account only 256 points in the universe of discourse. since each point is represented with 9 digits and results from the division of the universe width by 256, then the minimum universe width must be 0-255*10 -6 . note you must be aware that, in general, all the existing mbfs, both for input and output variables, are automatically stretched or shrunk to the new universe dimension. only in case the output vari- able mbfs have been defined directly in fuzzy rule editor (see "creating and managing membership functions"), the universe resizing does not modify the mbf crisp value and may cut off the mbf and its related rules, if the mbf value is outside the new universe boundaries. refer to "fuzzy variable initialization and storing" paragraph for the initialization and storing proper- ties. 43 chapter 5 - fuzzy block
creating and managing membership functions as stated earlier, a fuzzy variable is characterized by the name, the universe of discourse and the term set, that is the set of all related mbfs. the mbf related commands are grouped into the edit > mbf menu. these commands allow you to manage the term set of the active variable, so the edit > mbf menu is available only if the window is active. to select one of the existing mbfs you may click on it, in the drawing area, or use the toolbar drop-down list containing all the names of the mbfs defined for the active variable. when a mbfs is selected, its vertices are contained in a little square. when the mouse pointer is into the drawing area, its position coordinates are shown both on top of the drawing area, as x and y values and on the status bar, as value and belief. due to mbf vertical resolution, the y values are given as a x/15, showing mouse pointer position when into variable window drawing area. you can enable/disable x and y values display for the active variable by using the xy on the screen command from the options menu. clicking the right mouse button into the drawing area of a variable window, a pop up menu with the main mbf commands appears. by default, membership shapes are filled up with random coloured patterns. user can enable/dis- able this feature via the hide colors command from the options menu. this menu item acts as an on/off global switch, whose state can be modified. the changes will apply to all the defined variables. after opening a variable window, you can create its mbfs by using: the command new mbf from edit menu (or pop up menu) the autofill utility the rule editor (only in case of output variables) 44 fuzzystudio ? 3.0 user manual
creating a new mbf to create a new mbf, the variable window to which it relates must be open. choose new mbf from edit > mbf menu (ins) or click the toolbar button or click the right mouse button. the mbf position into the variable universe of discourse is set as follows: in the centre of the universe of discourse, if mbf is the first to be defined. coinciding with the current cursor position in the drawing area, if using the right mouse button a menu pops up and if this position does not coincide with an existing mbf. shifted of the autoshift value with respect to the previously defined mbf. for more information see paragraph "autoshift and semibase" chapter for further information. creating a new mbf using the rule editor (only in case of output variables) the definition of mbfs for output variables is also possible by using the rule editor. in this way you can set the output crisp value of the mbf, by writing directly in a rule in editing. however, this mbf does not appear either in the drawing area of the relative output variable nor in the mbf report and cannot be managed through variable editor related commands. the universe of discourse resizing does not modify this mbf crisp value but may cut off the mbf itself and its related rules, if the mbf value is outside the new universe of discourse boundaries. for further information about the definition of a mbf by using the rule editor, see the "rule editor" paragraph. how to customize a mbf to customize a mbf you can change its name, position and shape. membership name is set by default to mbf x , were x is an integer value starting from 1 and it is incremented each time a new membership is created. to change name: 1 select the mbf clicking on it on the drawing area or selecting its name on the drop down list. 2 choose rename mbf from edit > mbf menu or from right mouse button pop up menu. 3 put the new name in the dialog box . 4 choose ok. to change position: 1 select the mbf clicking on it on the drawing area or selecting its name on the drop down list. 2 click into the membership area and drag it to the desired position by moving mouse cursor without releasing mouse button or using the key arrows without releasing the mouse button 3 release the left button. due to variable editor internal organization, a mbf cannot be positioned into the same position of another membership with equal properties (i.e. shape and dimensions). to change shape: 1 select the mbf vertex to be moved, clicking on it with the left mouse button. 2 move the vertex to the desired position dragging it or using the key arrows while retaining the left mouse button. release the left button. if the vertex is forced to go outside the variable domain, mouse cursor leaves x axis to run on the domain boundary, pointing to the intersection between the related shape side and this boundary. 45 chapter 5 - fuzzy block
using autofill mbf (only for input variables) to define a set of mbfs equally spaced, the autofill command can be used. a dialog box allows to specify the desired options. to draw the mbfs set: 1 select the variable, clicking on its window or opening it. 2 choose autofill from edit > mbf menu. 3 enter the desired number of fuzzy sets (num mbf). 4 press the desired filling mode button. the autofill mode defines at least two mbfs. therefore it is active only if less than maxrules-1 mbf have already been defined. max_rules being the maximum allowed number of rules. the max_rules depends on the number and allocation of membership functions already defined inside the same and the other fuzzy blocks. anyway, no more than 16 mbfs per time can be defined. the filling modes work as follows: draws n isosceles triangular mbfs. the semibase of new mbfs is calculated splitting the universe in n+1 equal intervals. since x-values must be integers, the remainder of the integer division of the domain width by n+1 is added to the centrail interval (or is shared out between the two central ones, if n=1 is even). 46 fuzzystudio ? 3.0 user manual
draws two external rectangle trapeziodal mbfs. all other mbfs are triangular. the semibase of new mbfs is calculated splitting the universe in n+1 equal intervals. since x-values must be integers, the remainder of the integer division of the domain width by n+1, if any, is added to the central interval (or is shared out between the two central ones, if n is even). draws two external rectangle triangular mbfs. all other memberships are triangular. the semibase of new mbfs is calculated by splitting the universe in n-1 equal intervals. since x-values must be integers, the remainder of the integer division of the domain width by n-1, if any, is added to the central interval (or is shared out between the two central ones, if n is even). 47 chapter 5 - fuzzy block
how to delete a mbf to delete a mbf: 1 select the mbf clicking on it on the drawing area or selecting its name on the drop down list 2 choose delete mbf from edit > mbf menu or from the right mouse button popup menu or press delete key. when deleting a membership used by existing fuzzy rules you are asked for confirmation. by erasing such a membership these rules are deleted too. the number of fuzzy rules involved into the membership deletion is provided with the confirmation request. note deleting a mbf belonging to a shared variable will cause the elimination of the mbf in each fuzzy system when the variable is used (see shared and copied variables paragraph). autoshift & semibase when a new mbf is generated by means of the mbf new command, the base width and the distance of each mbf is set by default to the semibase and autoshift values. to change these values: 1 choose set autoshift & semibase from edit menu. 2 change values. 3 press ok. the autoshift and semibase options are related to the creation of a new mbf. when a new mbf is generated by means of mbf new command, its centroid will be placed: on the cursor position, if a mbf didnt already defined in the same position. at a distance equal to the autoshift value from the closest mbf, otherwise. triangular mbfs have by default base half-width equal to the semibase value. different bases can be obtained changing semibase option or customizing each mbf. you can modify default values for autoshift and semibase values via the set autoshift & semibase command from the edit menu. on this command a dialog box pops up, showing current default values and allowing users to modify them. these values are set using a st52x301 internal measurement unit, and are independent from the chosen dimension of the variable domain. due to hardware constraints of the st52x301 processor family, the autoshift and semibase values must belong to the [1,255] integer interval. 48 fuzzystudio ? 3.0 user manual
mbf report variable editor gives a textual description of variable term set. to visualize a variable report: 1 select the variable clicking on its windows or opening it. 2 choose mbf report from view menu report window content is organized by rows, each row containing: mbf name and its vertices coordinates, in case of input variable; mbf name and its crisp value, in case of output variable; report window rows are scrollable and mouse selectable. you can run membership related commands either from a variable window or from the related report one. membership pop-up menu can be activated pressing the right mouse command while on the report window. the active report window can be closed by using again the mbf report command from the view menu (this command acts as an on/off local switch, related to the active variable window only) or via the close command from system menu (accessible using the button on the window left upper corner). closing a report window not affects the related variable window, while closing a variable window closes the related report too. when a report window is open, its fonts may be changed, performing the following operations: click the right mouse button and select choose report font from view menu. or when the report window is in foreground select the "choose report font" command from the view menu. 49 chapter 5 - fuzzy block
shared and copied variables besides the creation of a new variable, within a fuzzy block, it is possible to share or copy existing variables within other fuzzy blo cks. shared variables a shared variable is a variable used in several different fuzzy blocks, with the same characteristics, and will therefore use the same memory locations to store the membership functions, this means that the variable is the same. then, each change performed on one of the shared variables will have effect on all of them. to insert a shared variable: select share var from the insert menu in the fuzzy system editor window or click the apposite toolbar button of this window. a selection window is open, where on one side you will find the list of fuzzy systems defined and on the other one there will be the variables defined inside the selected block. choose the fuzzy system to which belongs the variable to share and select it. note the selection of a variable belonging to the current fuzzy block will not produce any effect. the window disappears and the mouse pointer is enabled to insert the variable on the fuzzy system. in both fuzzy systems that share the variable, the icon that represents it change its shape indicating that such a variable is shared by several blo cks. the name of the shared variable is the same in all the blocks in which it is used: a rename of one of them will determine the change in the other fuzzy systems in which it is shared. note it is not possible to insert a shared variable in a fuzzy system that has the same name of an already existing fuzzy variable. in this case, rename this last variable and try again to insert the shared variable. moreover, consider that it might not be possible to insert a shared variable when new variables, using the same address space of the variable to share, have been defined. 50 fuzzystudio ? 3.0 user manual
copied variables the copied variables are variables already defined in a fuzzy system. this means that their characteristics can be copied in other fuzzy systems. the substantial difference between shared and copied variables is that a copied variable is an other variable different from the original one. a copied variable can be inserted provided that a memory space is available (refer to the chapter "variable constraints definition in a fuzzy block). the editing environment of a copied variable is distinct from the variable of origin. if a variable having the same name already exists in the fuzzy system, the name of the variable to be copied is modified adding a progressive number to its name. finally, each change performed on the original variable or on the copied variable is not reflected since, as stated earlier, these are distinct variables. this can be useful whenever you want to define a variable with similar characteristics but not coincident with another: first copy the variable and then make the necessary changes. it is possible to copy, cut and paste a fuzzy variables block with its content as a normal block: select the variable(s) to copy/cut selecting the command in the edit menu or clicking the related toolbar button. open the destination fuzzy block. select paste command from the edit menu or click the related toolbar button. the window disappear and the pointer is enabled to insert the variable in the fuzzy system. how to export data to clipboard the variable editor allows to export data to the system clipboard. both membership drawings and mbf reports can be exported. perform the following commands: 1 select the variable window to export. 2 choose copy on clipboard from edit menu. the copy on clipboard command, invoked by the ctrl+c short key too, acts on the active variable and is available only if at least one variable or a report window are opened or iconized. this is a sensitive command. its label is copy on clipboard as "bitmap", when you are working on bitmap images, or copy on clipboard as "text", when you are working on a text editor. you can then manage these data as any other clipboard content: as the clipboard is a global windows object, shared among all the currently running applications, users can paste these data into documents of other applications such as windows write or microsoft word for windows (e.g., to produce a detailed project documentation), or can put these data in the windows clipboard application to store them for later use. at the same time you must be aware that any copy operation, from any running application, replace the clipboard content with new data. 51 chapter 5 - fuzzy block
fu.l.l. importer fu.l.l. (fuzzy logic language) importer is a tool that allows to import, in a fuzzy block, fuzzy systems generated by the fuzzy software tools produced by stmicroelectronics : a.f.m.1 & 2 (adaptive fuzzy modeller) for the automatic generation of the fuzzy models by starting from the input/output patterns and fuzzystudio ? 2.0, the development system for the programming of w.a.r.p. 2.0 processor. fu.l.l. (fuzzy logic language) is a description language of the fuzzy systems allowing to exchange data between the various fuzzy logic software tools. to import a fuzzy system in the project: 1 insert a fuzzy block, by using the blocks editor. 2 open the block keeping the fuzzy system window in foreground. 3 select the item import fu.l.l. from insert menu. 4 an open file dialog box is open. 5 search and select the file .ful you are interested in. 6 press ok button or double click on the file name. a fuzzy system in fu.l.l., besides being generated automatically by above tools, can also be generated by using a normal text editor. for further information on the f.u.l.l. syntax and semantic refer to appendix e. - f.u.l.l. - fuzzy logic language. 52 fuzzystudio ? 3.0 user manual
rule editor rule editor is the tool devoted to manage with fuzzy rules. to run rule editor, double-click on the rules block from the fuzzy system editor window. the rule editor environment is opened showing, if already defined, the list of the rules. in order to define fuzzy rules, using rule editor, it is necessary to define at least one input and one output variable with associated membership functions. rule editor cannot be activated until these minimal definitions have not been done. 53 chapter 5 - fuzzy block
defining fuzzy rules with rule editor the rules related commands are grouped into the rules menu. there are two ways to write rules: by using guided editing or manual editing. in guided editing a paddle containing keywords, if-then operators, variables and membership functions is used for quick definition. this editing mode allows you to select automatically only syntactically correct objects. in manual editing, rules must be defined manually using the keyboard as a normal text editor. before being inserted on the list, the rule is syntactically checked to guarantee its correctness: if an error occurs, its description is given in the output window. manual editing allows to delete or to modify already defined rule. after being modified, a rule can replace its previous version or be added to the list. multiple deleting is possible if a multiple selection is done. it is possible to go to a precise rule by using edit -> go to command o pressing f5. a dialog is shown allowing the user to choose the rule number. to copy one or more rules onto the clipboard, select them from the rule list using the mouse, then choose copy from edit menu or use ctrl + c. you can also perform the cut commands choosing it from the edit menu or using ctrl + x. you can also print all rules information about the current project by using the print command or ctrl+p . the rule editor window this section provides an overview of the major elements of the rule editor window, such as menus, toolbar and status bar. for additional information, see the index and online help. rule editor menus all rule editor commands are grouped into a menu hierarchy accessible from the main window menu. menus and items are context-sensitive: at each time only relevant commands for the selected object or for the current project status will be enabled. available menus are: file provides save and print utilities, a list of recently used files and the exit command. edit provides standard editing and go to commands. view contains commands for control bars display/hide, font selection and move through the error list. tools contains commands for switching to fuzzystudio ? 3.0 tools: com- piler, debugger and programmer. rules contains rule related commands, for manual and guided editing. window contains commands related to window management. help contains commands for help on topics and information on fuzzystu- dio ? 3.0. 54 fuzzystudio ? 3.0 user manual
rule editor toolbar for convenience, the most frequently used commands of rule editor can be executed by choosing the corresponding buttons on the toolbar. toolbar buttons are context-sensitive: only the commands in relation with current project status are enabled. toolbar is a user selectable item: you can choose to hide or show it by using the related commands of view menu. rule editor status bar a status bar is available at the bottom of the application main window. this bar displays a brief description of the selected command, the number of rules defined by the user, the number of the selected rule in the list, the status of the capslock and numlock keys. to get a quick help on a command item (i.e., a menu command or a toolbar button), just position the mouse pointer on the toolbar without clicking, a brief command description will be shown on the leftmost field of the status bar, in addition to the type shown near the button. 55 chapter 5 - fuzzy block
how to write a rule using guided editor guided editor uses the editing paddle that can be activated choosing rules guided or pressing crtl+g or the toolbar button. select keywords, operators and others by clicking on paddle buttons. note that during guided editing: keywords if and is are automatically included when necessary, that is, respectively, at the start of the rule and after selecting a variable name. the rule is shown in the upper side of the edit box. it is not possible to write in this edit-box during guided editing. it is possible to correct manually the rule switching to manual editing. if a mistake occurs it is possible to undo the previous operations, or abort the rule editing. notice that undo could not be possible after modification of variables or membership functions names using the variable editor. to include comments inside the rule, click the comment button in the paddle to edit the comment text. comments can be included anywhere in the rule. 56 fuzzystudio ? 3.0 user manual
editing the antecedent notice that in this list-box, variables or membership functions are shown according to the syntactical correctness of the rule; in addition, the membership function list is always related with the selected variable. 1 click new button in the paddle: the if keyword is shown on the edit-box. 2 choose one of the input variables listed on the left side of the paddle, double clicking on it. the input variable name will be shown in the edit-box followed by the keyword is, whereas in the list-box the related mbf list appears. note that only variables having at least one membership function are listed. 3 add not modifier, if necessary, clicking on the apposite button. 4 select mbf, double-clicking on its name on the list-box. 5 click and or or button if rule has more antecedent terms and go back to point 2, for further insertion of input variables, otherwise go to the following section editing the consequent. note: and operator has higher priority than or operator. editing the consequent 1 click then on the paddle. 2 select output variable double clicking on the variable name in the list-box. 3 select the variable crisp value, double clicking over the associated label. you can also click over the mbf label or write the crisp value and push enter button or click over accept button. 4 click and if the rule has more consequents and repeat the selection of an output variable and the association of its crisp value. 5 click done: the rule will be added in the rule list and the status bar is updated. note: if the crisp value is written directly in the dialog-box, this operation does not determine its graphical representation in the mbf drawing window because the value is directly translated by com- piler machine code, without the need of a point-by-point graphical definition of the related membership function. 57 chapter 5 - fuzzy block
using manual editor manual editing mode can be activated choosing manual > activate from rules menu or pressing ctrl+m or the toolbar button. an edit box will appear in the upper side of the window. manual editor allows you to edit more than one rule at the same time. these rules might be syntactically checked and/or inserted in the list. by means of the manual editor it is possible to manually edit a new rule or to modify already existing ones. how to write a rule to use manual editor for the definition of fuzzy rules follow these steps: 1 write the rule in the edit-box above the rule. 2 you can now check the rule syntactic correctness, pressing manual check from rules menu or using f3 or clicking the toolbar button. 3 write, if necessary, comments including the text between these characters: /**/ the string between two sequences of characters is excluded by syntactical check .// the string after two sequences of characters is excluded by syntactical check you can write more than one rule at the same time either by writing them on one row and separating each rule by inserting a semicolon or by using one row for each rule. you can also write one or more rules by modifying the existing ones. in this way the rule editing is performed quickly because the selected rule(s) is copied in the edit-box and it wont be necessary to write the entire rule(s) again: 1 if you want to change only one rule: select the one you want to use as a model by double-clicking on it. if you need to modify more than one rule: copy the selected rules in the clipboard and then past them in the manual editor windows. 2 modify the parts of the rule(s) you need to change. 3 you can now check the syntactic correctness, pressing manual check from rules menu or using f3 or clicking on the toolbar button. 58 fuzzystudio ? 3.0 user manual
list updating when the rule(s) definition has been completed, the rule(s) can be inserted in the rule list by means of the following manual commands in the rules manual menu: how to add rule(s) choose rules manual add or click the toolbar button. the current rule is syntactically checked and inserted at the end of the rule list. how to insert rule(s) rule inserting is possible in manual editing mode. it consists in the insertion of the edited rule before the selected ones: 1 select the rule by clicking on it. 2 choose insert from rules manual or use ins or the toolbar button. the current rule is syntactically checked and inserted just before the selected rule(s). how to replace rule(s) rule replacing is possible only in manual editing. 1 select the rules that must be replaced, clicking on it in the rule list. 2 choose rules manual replace or press ctrl+r or the toolbar button. how to delete rules 1 select one or more rules. 2 choose delete from edit menu or use del or click the toolbar button. 3 press yes, on the rule editor confirmation box. to select multiple sequential rules in the list, click the first one and then drag the cursor to the liast item, or click the first rule you want to select, press and hold down shift, and then the last rule ( or via keyboard by pressing shift + arrow keys). to select multiple nonsequential rules in the list, press and hold down ctrl, and click each item you want to select. to cancel the selection, release shift, and then click any item. how to print the rules list 1 check the correctness of the printing options for the printer, choosing file print setup 2 choose print or press ctrl+p or the toolbar button before printing, the user can view the document choosing print preview in the file menu. 59 chapter 5 - fuzzy block
rule editor view options the view menu allows you to customize the rule editor window. you can display or hide the toolbar and the status bar choosing the related command from the view menu. you can set the font used to show the rules by means of the font view command. performing this task a standard ms-windows dialog box will pop up and you can change font type and size. rule editor constraints rule editor allows to write rules having a maximum of 8 antecedents and 2 consequents. however, rules with more than 4 antecedents or more than 1 consequent are splitted, during compilation, into equivalent simpler rules having up to 4 antecedents and one consequent. st52x301 executes partial computations and then evaluates the total antecedent part of the rule. a maximum of 256 rules can be defined. rule grammar ::= if then . ::= and | . ::= is . ::= | . ::= or | . ::= and | . ::= () | . ::= is . ::= not | . ::= | . ::= | | | . ::= | 60 fuzzystudio ? 3.0 user manual
_ . ::= | . ::= | . ::= +| - . ::= | . ::= | . ::= | . ::= e | e . 61 chapter 5 - fuzzy block
error messages using fuzzystudio ? 3.0 rule editor the following messages and warnings can occur: "char" not allowed character the character "char" is not allowed in the context. generic check error internal error: contact stmicroelectronics, fuzzy logic b.u. incomplete rule: a membership function name was expected. a membership function term is missing in the rule. complete the rule with the appropriate term. incomplete rule: an input variable name was expected a variable name is missing before a "is" keyword in the entered rule. add the keyword in the appropriate place or check for sintax errors. incomplete rule: an output variable name was expected an output variable term is missing in the rule. complete the rule with the appropriate term. incomplete rule: "is" keyword was expected the keyword "is" has not been written after a variable name to specify the membership function. add the keyword where it is missing. incomplete rule:not closed comment the comment statement in the rule was not closed with the */ character. add the character */ at the end of the comment. incomplete rule or empty rule the rule in editing has not been completed before entering it or a empty row has been entered. complete the rule with the correct syntax. incomplete rule: rule without "if" the keyword " if " is missing at the start of the entered rule. add the keyword in the appropriate place or check for syntax errors. incomplete rule: rule without "then" the keyword "then" is missing at the start of the consequent part of the entered rule. add the keyword in the appropriate place or check for syntax errors. "name" is an invalid keyword the specified keyword "name" is not allowed in the context. check for syntax errors. "name" is not an input variable the specified name for antecedent term does not belong to the list of input variables. check for syntax errors. 62 fuzzystudio ? 3.0 user manual
"name" is not an output variable the specified name for consequent term does not belong to the list of output variables. check for syntax errors. "name" is not a valid membership function name the specified name does not belong to the list of membership functions associated to the variable. check for syntax errors. not enough memory the available memory is not enough to perform the operation. try again after closing some application in your computer. too many terms in antecedent; 8 at most more than 8 antecedent terms have been specified in the rule. try to split the rule in two or more equivalent rules. too many terms in consequent; 2 at most more than 2 consequent terms have been specified in the rule. try to split the rule in two or more equivalent rules. unexpected string at the end of the rule a not allowed string of characters has been found at the end of rule. check for syntax errors or if the /* character for starting a comment is missing. "value" is out of defined universe of discourse the specified value for consequent is not in the specified range of the output variable. 63 chapter 5 - fuzzy block
64 fuzzystudio ? 3.0 user manual
chapter 6 arithmetic block the arithmetic block allows to carry out the arithmetic and logic operations that st52x301 is able to perform. to run the arithmetic block, double-click on the apposite icon in your flow-chart. the arithmetic block window this section provides an overview of the major elements of the arithmetic block window, such as menus, toolbar and status bar. for additional information see the index and online help. arithmetic block menus the arithmetic block menus are: file contains commands to create, open, close and print. edit provides standard editing and check commands. view contains commands to show or hide toolbar, status bar, go to previous or next error and font selection. tools contains commands for switching to debugger, compiler and pro- grammer. window contains commands related to windows management. help provides help on topics and information on the arithmetic block. 65
arithmetic block toolbar the arithmetic block includes a toolbar to help you to perform the most frequently used commands quickly. arithmetic block status bar the status bar displayed at the bottom of the arithmetic block window contains some information about the task you are working on and the position of the cursor. check previous error next error undo 66 fuzzystudio ? 3.0 user manual
using the arithmetic block the arithmetic block is a free text editor that performs the following operations: undo (ctrl+z) is a multilevel option that allows you to undo most of the text editing and formatting operations accomplished using items of the edit menu: cut (ctrl+x), copy (ctrl+c) and paste (ctrl+v) to delete, move and copy text onto the clipboard. find locates a specified part of the text and find next (f3) looks for the next one. replace is a function that allows to replace the specified text. select all to select the whole text. moreover, it is also possible to change the font settings: select font from view menu. select the characters setting and color from the font dialog box. instructions the instructions allowed in the arithmetic block can be grouped as follows: mathematical instructions: assignment, sum and subtraction that use the following operators: =, +=, -=, +, - conditional instructions instructions that use the following keywords: if, then, else, endif. while else is optional, endif is compulsory to close each if statement since there can be many different if levels. the following comparison operators are allowed: ==, >=, >, <=, <, != some logical functions can be used in a conditional expression: isbitset, isbitreset, isoverflow, isunderflow, isoutofrange, timerstatus, scistatus. logic instructions they use the following operators & (and), | (or), ~ (not), ^ (xor). the following functions are accepted for bit manipulation: bitset, bitreset, bitnot. & has higher priority than |. instructions must end with a semi-colon. expressions must have no more than one operator (two operands). no brackets are accepted. the comment lines are allowed and preceded by //. it is possible to insert a comment text in several lines starting the comment block with /* characters and ending it with */. operands allowed are the global variables and the local variables defined within the block and the predefined variables representing some peripherals registers (see later). it is not possible to use the fuzzy variables within an arithmetic block since they can only be used in a fuzzy block. 67 chapter 6 - arithmetic block
instructions grammar the arithmetic block instructions operate on the global and local variables declared in the same block by means of the apposite instructions of declaration. the following is a description of the instructions syntax in which the objects between "[...]" indicate objects that can be omitted if not necessary while the ones between "{..." contain alternative objects separated by the symbol "|" . the objects that are not inserted between brackets cannot be omitted and must necessarily be present. expressions the expressions must have the following syntax: var assignment_operator [unary_operator] {var | constant} [operator {var | constant} ] ; where: var is a global variable, a local variable with an apposite instruction of declaration at the beginning of the block or a predefined variable. 68 fuzzystudio ? 3.0 user manual
the list of the predefined variables is the following: read-only variables: c han 0 identifies the variable in which the value of the a/d 0 channel is set. c han 1 identifies the variable in which the value of the a/d 1 channel is set. c han 2 identifies the variable in which the value of the a/d 2 channel is set. c han 3 identifies the variable in which the value of the a/d 3 channel is set. t i me r_ stat us identifies the variable in which the timer status is set. s ci _ stat us identifies the variable in which the sci status is set. f uz zy 0 identifies the first fuzzy output. f uz zy 1 identifies the second fuzzy output. a dc_ s tatus identifies the variable in which the value of the a/d converter status is set. write-only variable t ri ac _co unt identifies the variable in which the triac counter value is set. read/write variables t i me r_ coun t identifies the variable in which the timer counter value is set. p ort identifies the variable with the values written/read in the paral- lel port. s ci _ buf fe r identifies the variable with the values written/read in the serial. operator is one of the following: +sum - subtraction & logic and | logic or ^ logic xor assignment_operator is one of the following: = simple assignment a = b b -> a += assignment with sum a += b a = a + b -= assignment with subtraction a -= b a = a - b unary_operator - negation ~ logic not constant : a constant value in the range [-128, 127] (signed byte) or [0, 255] (byte) the expressions can contain at most one operator among operator and unary_operator . the expressions must always end with the character ";". note due to the fact that values are stored in 8 bit registers, they can easily go out of the range [0, 255], giving a result equal to -256 in case of overflow and 256 -|result| in case of underflow. the user can manage this situation by means of the functions isoutofrange, isoverflow, isunderflow, de- scribed later in this chapter. 69 chapter 6 - arithmetic block
examples: a = b + c; a += c; b = 30; b = a |; c c = - a; b = ~ c; declarations declaration instructions allow to create temporary variables that are visible locally only within the arithmetic block in which they are declared. they have to be placed at the beginning of the block before any other instruction. an assignment can be associated to the declaration by means of a value or expression. this is the grammar: {byte | signed |signed byte } { var | expression }; where: byte byte type local variable declarator. signed signed byte type local variable declarator. signed byte it is equivalent to signed. var a variable symbolic name. expression an arithmetic expression. the instruction declaration must always end with the character ";". examples: byte a; signed b = 30; 70 fuzzystudio ? 3.0 user manual
conditional instructions the conditional instructions allow to modify the logic flow of the program within an arithmetic block. the grammar of these instructions is the following one: if {var [relational_operator {var|cost}]| condit_function} instruction_list [else] instruction_list . endif ; where relational_operator can be one of the following: == equality != disequality > greater than < less than >= greater equal to <= less equal to condit_function is one of the following functions of the language standard library: isbitset ( index_bit, variable_name) verifies if the variable bit value is 1. the parameter bit varies from 0 to 7, while the parameter variable can indicate any variable visible within the procedure that contains the conditional expression. isbitreset ( bit, variable); verifies if the value of a variable bit is 0. the parameter bit varies from 0 to 7, while the parameter variable can indicate any variable visible within the procedure that contains the conditional expression . isoverflow(); verifies if the last logic-arithmetic instruction performed has generated an eventual overflow. isunderflow() ; verifies if the last logic-arithmetic instruction performed has generated an eventual underflow. isoutofrange(); verifies if the last logic-arithmetic instruction performed has generated an eventual overflow or underflow. timerstatus(param); verifies thetimer status; the parameter indicates what to inspect about the peripheral status. the possible parameters available for this function are the following: set the function returns true if the timer is in set status, false if in reset status. start the function returns true if the timer is in start status, flase if in stop status. scistatus(param); verifies the sci status; the parameter param indicates what to inspect about the peripheral status. 71 chapter 6 - arithmetic block
the possible available parameters for this function are the following: tx_end verifies the end of transmission tx_empty verifies if the transmission buffer has been emptied. ninth_bit returns true if the ninth bit of the frame is 1. overrun verifies if an overrun error has occurred. rx_full verifies if the reception buffer is full. frame_error verifies if a frame error has occurred. noise_error verifies if an error due to a noise has occurred. these library functions can be used instead of one of the generic conditional expression operands. their result will be true in case of positive verification, false otherwise. instruction_list is a list of arithmetic instructions. in case a constant or a variable is specified as conditional expression, then this will be false if the constant or the variable is 0, it will be true for all the other values. for example: if 0 then a = b; else a = c; endif; note the instruction a = c is always performed if a<=60 then a-=b; endif; if a != b then a = b + c; c = 0; b = a + 10; else a = 0; b += c; endif if a>=10 then c=30; else c=80; endif; if a=b then c=b; else c=a; endif; 72 fuzzystudio ? 3.0 user manual
if timerstatus (start) then c = 0; else c=128; endif; how to check the instructions the syntactic check of the text is carried out only under a user request. to start the check of the arithmetic instrunctions set: select the item check from the menu edit or click on the apposite toolbar button the text can be saved inside a project even if not correct. when you request a check an output window will open displaying either eventual error messages and warnings or simply the message of successful check. double-clicking on an explanation error row in the output window , the editor is automatically displayed in foreground and the row in which the error has been detected is highlighted allowing you to easily identify the errors. to go to next error message line, you can do one of the following: select next error from the menu view. click the apposite toolbar button. press the short-cut key f4. to go to the previous error message line do the one of the following: select previous error from the menu view. click the apposite toolbar button. press the short-cut key shift + f4. 73 chapter 6 - arithmetic block
74 fuzzystudio ? 3.0 user manual
chapter 7 peripherals block the peripherals block is used to enable or disable the peripherals functionalities except for the parallel port, of which the peripherals block allows to write the 9th bit. it is important to notice that each peripheral block can act on a single peripheral. double-clicking on the icon representing the peripherals block, the peripheral settings dialog-box will appear. this consists of two main parts: a drop down list that allows to select the peripheral to be set and the relative selection check boxes that vary according to the peripheral you choose. the peripherals you can choose are the following ones: a/d (analog to digital converter) sci (serial communication interface) timer triac (triac driver) port output pin note by default, when you open the peripherals block for the first time, no peripheral is selected and the label none appears in the drop-down list box. notice that no selection tool is available. other- wise, the last settings performed on that block are displayed. 75
a/d when choosing a/d, the following dialog box is displayed on the screen: the available settings are a/d set and a/d reset. note when the program encounters a block that performs the conversion stop, the peripheral stops reducing the current consumption and all its registers are reset, including the registers containing the converted data. sci when choosing sci, the dialog box will be the following one and the available command are: start / stop tx: enables/disables serial transmission start / stop rx: enables / disables serial reception 9th bit: specifies the 9th bit data value to be transmitted if this mode is activated by the peripheral setting. 76 fuzzystudio ? 3.0 user manual
timer the dialog box relative to the timer will be the following: it is possible to manage the following commands: set the peripheral is ready to start count. reset turns the peripheral off decreasing current consumption. start/stop starts/stops timer count without resetting the counter, this means that a start after the stop resumes the count where it stopped. this section is enabled only if the peripheral is in set status. 77 chapter 7 - peripherals block
triac choosing the triac, the dialog box will be the following one: it is possible to manage the following commands: set sets the peripheral in wait status for the count start. reset turns the peripheral off decreasing current consumption and stopping it immediately. start / stop starts / stops the triac functionment. this section is enabled only if the peripheral is in set status. note when the triac driver is stopped, it will stop at the finish of the counting in progress to avoid noise and control problems. trout pin allows to set the triac driver signal output pin in tristate status to avoid eventual conflicts or in output status to carry out the normal functionality. notice that at the device start-up, this pin is in tristate, then to drive the system it is necessary to put, by means of these controls, the trout pin in output. 78 fuzzystudio ? 3.0 user manual
port output pin when choosing port output pin, the dialog box will be the following one: it is possible to set the output data to the port pin, that can take the value "high" (logic 1) or "low (0 logic). 79 chapter 7 - peripherals block
80 fuzzystudio ? 3.0 user manual
chapter 8 interrupts service routines the interrupts signals determine, if enabled (not masked), a jump from the main program to the relative service routine. the interrupts routines have the same characteristics of the main program and use a similar interface. the only difference, regarding the main programs routines, is that the routine ends with return from the interrupts command (reti instruction) that determines the return to the main program where interrupted. to write an interrupt service routine use the same technique of the main program, but in the window dedicated to it. do as follows: 1 double click on the icon in the project window representing the interrupt you are interested in. 2 the interrupt routine editing window opens. 3 in this window, the irq block is automatically inserted. this represents the entry point of the editing routine: the first block has to be linked to this one. 4 write the program using the blocks, as you do with the main program. 5 end the flow-chart with a reti block. if this block has not been inserted, the compiler generates an error message. more reti blocks can be inserted when neccessary. 6 do the same for the service routines of the other interrupts in use. note: the interrupt routine windows can be open also by means of the commands in windows in- terrupts menu. a vector is associated to each interrupt. this is the address in which the service routine starts. this vector is automatically fixed by the compiler in a transparent way for the user. 81
interrupts configuration there are two blocks for the interrupt configuration: one block allows to enable/disable an interrupt and another one allows to change the interrupt priority. interrupts mask block the interrupts mask block allows to enable / disable the interrupts and to fix the external interrupt trigger, if this is enabled. the dialog-box associated to this block is the one shown below: all interrupts can be enabled or disabled. however they are all disabled as default. in case the external interrupt is enabled, it is necessary to establish in the apposite external interrupt trigger event" if this has to be determined by a rising edge (default) or falling edge. 82 fuzzystudio ? 3.0 user manual
priority configuration block this block allows to fix the interrupt priority, by using the following dialog-box: the list shows the current priority order of the interrupts: the higher the interrupt is in the list, the higher the priority will be: to change the priority: 1 select the interrupt from the list. 2 click the up button to raise up the interrupts priority and down button to lower it. 3 do the same with all the interrupts until you reach the desired order. note: the dialog window summarizes the priority of all the interrupts that will take the order fixed in the list after you click ok button. 83 chapter 8 - interrupts service routines
84 fuzzystudio ? 3.0 user manual
chapter 9 wait for interrupt block the insertion of the wait for interrupt block in the flow-chart makes the processor stops to wait for an interrupt signal when the instruction relative to this block is performed. during the wait, no instruction is performed and the core of the processor is stopped, while the peripherals continue to work regularly. when you have a request of interrupt, this is served performing the relative service routine. after the interrupt routine, the program restarts from the next block. the wait for interrupt block has not an editing environment associated because no specifics or settings are required. it is useful to insert this block if you want to synchronize the program with events that can generate interrupt signals. note: if there are no interrupt enabled or no interrupt signals is generated, the insertion of a wait block determines the processor stopping, that can be unlocked only through an external reset. 85
86 fuzzystudio ? 3.0 user manual
chapter 10 assembler block the assembler block has been designed to allow the expert user to use the processor in all its potentialities, including the masked ones or the ones that are not allowed at a high level, writing directly in assembler language. a double-click on the assembler block icon, opens the editing environment allowing to specify the programs instructions directly in st52x301 assembler. the assembler block window this section provides an overview of the major elements of the assembler block window, such as menus, toolbar and status bar. assembler block menus the assembler block menus are: file contains commands to create, open, close and print. edit provides standard editing and check commands. view contains commands to show or hide toolbar, status bar, go to previous or next error and font selection. tools contains commands for switching to debugger, compiler or pro- grammer tool. window contains commands related to windows management. help provides help on topics and information on the assembler block. 87
assembler block toolbar the assembler block includes a toolbar to help you to quickly perform the most frequently used commands. assembler block status bar the status bar displayed at the bottom of the assembler block window supplies information about the task you are working on and the position of the cursor. the bar also displays the status of the caps, num and scroll lock keys. command description caps, num and scroll lock keys coordinates of the insertion point next error undo previous check 88 fuzzystudio ? 3.0 user manual
using the assembler block the assembler block is a free text editor. undo ( ctrl+z ) is a multilevel option that allows you to undo most of the text editing and formatting operations performed using items of the edit menu: cut ( ctrl+x ), copy ( ctrl+c ) and paste ( ctrl+v ) functions let you delete, move and copy text onto the clipboard. find locates a specified part of the text and find next ( f3 ) looks for the next one. replace is a function that allows to replace the specified text. select all allows to select the whole text. note: using windows 95 you can access to the desired options by clicking the right mouse button over the client area. moreover, it is also possible to change the font settings. select font from the view menu. select the characters setting and color from the font dialog box. how to check instructions the syntactic check of the text is carried out at the user request. to start the check of the instructions: select check from the edit menu. or click on the apposite toolbar button. the text can be saved in a project even if not correct. when you request a check, an output window will open displaying either error messages and warnings or the message of successful check. double-clicking on an explanation error row in the output window, the editor is automatically displayed in foreground and the row in which the error has been detected is highlighted, allowing to easily identify the error. to go to the next error message line, you can do one of the following: select next error from the view menu. click the button on the local toolbar. press the short-cut key f4 . to go to the previous error message line you can do the following: select previous error from the view menu . click the button on the local toolbar. press the short-cut key shift + f4 . 89 chapter 10 - assembler block
assembler block instruction syntax the assembler instructions written by means of the assembler block follow a higher level syntax that allows to use the global variables and predefined variables. this leads to some constraints and the main ones are: it is not possible to insert assembler instructions relative to fuzzy functionalities. it is not possible to jump to labels external to the assembler block, in editing phase. in order to optimise the use of the assembler it is possible to use the fs3asm.exe tool, supplied with fuzzystudio ? 3.0 (appendix d). these are the instructions and relative syntax used in the assembler block: ldcf reg_confxx nn es: ldcf reg_conf2 45 ldpr pred var es: ldpr port var1 ldrc var nn es: ldcr var2 230 ldri var pred es: ldri var0 chan0 ldrr var var es: ldrr var1 var2 add var var es: add var1 var2 and var var es: and var1 var2 sub var var es: sub var1 var2 subo var var es: subo var1 var2 srx var es: srx var3 stx var es: rtx var2 jp label es: jp proc1 jpns label es: jpns proc0 jpnz label es: jpnz proc2 jps label es: jps proc5 jpz label es: jpz proc3 rint n es: rint 2 udgi uegi mdgi megi where reg_confxx = a predefined variable, suitable for the registers configuration and xx a number between 0 and 15. nn an integer decimal number included between 0 and 255. pred a predefined variable var a global variable. label a label defined inside the block. n an integer decimal number included between 0 and 3. for further details refer to appendix c and st52x301 data sheet. 90 fuzzystudio ? 3.0 user manual
chapter 11 conditional block a conditional block is inserted to modify the logic flow of the program according to a specified condition operated on the global variables defined by the user. from a semantic point of view, the conditional block is connected to a link in input and two in outputs, named yes and no. the output links determine the logic flow of the program according to the condition contained in the block. how to insert a conditional block 1 choose conditional block from insert menu or click the relative toolbar button. 2 mouse pointer changes its status. 3 click on the client area. 4 connect the conditional block with the other blocks by using the links in the following way: at first, connect to the block to be performed if the condition is true; the first output link is yes by default. to define the conditional expression: 1 double-click on the conditional block or choose open from the pop up menu that appears by clicking on the block with the right mouse button. 2 in the appearing edit-box, edit the conditional expression following the syntax and semantic described in the next paragraph. 3 press check button to test the correctness of the statement: the output window opens showing the errors if any. 4 press ok button to confirm and close the window. note the keyword if and then are considered as already inserted so you must omit them in the conditional statement, writing only the condition. see next paragraph. 91
conditional block grammar the instructions of the conditional block operate on the global variables and predefined variables determine the logic flow of the program according to the condition specified; if this is true, the program will perform the part of the program relative to the blocks connected to the yes link otherwise it will perform the program connected to the no link. the objects between "[...]" can be omitted if not necessary while those between "{... }" are alternative objects and are separated by the symbol " |". the objects that are not inserted between brackets cannot be omitted. the instructions have to be inserted in the conditional block edit box and express the conditional expression that has to ve evaluated. this is the syntax: { var | const } [relational_operator { var | const } ] where the relational_operator can be one of the following: == equal to != unequal to > greater than < less than >= greater equal to <= less equal to var is a global variable or a predefined variable const is a constant value in the range [-128, 127] (signed byte) or [0, 255] (byte). if only a constant or a variable is specified as conditional expression, then this will be false if the constant or the variable is 0 and it will be true for all the other values. the conditional expressions must not end with the character ";". for example: a <= b a == b a 0 (always false) 1 (always true) a ! = b a > 20 a >=10 a=b 92 fuzzystudio ? 3.0 user manual
chapter 12 send - receive blocks the send and receive blocks let the program interact with the peripherals registers. in particular, the send block allows to load the value of a global variable in a peripherals register while the receive block allows to load the value of a peripherals register into a global variable. to insert a block of this kind, choose the relative toolbar button or select send block or receive block from the insert menu. the icon of the send and receive blocks is context-sensitive, for instance it changes according to the blocks settings and indicates the peripheral it interacts with. the icon that is inserted at the moment of the creation of the block is named none and this shows that no peripheral has been considered yet. the label contained in the block representing the peripheral, changes contextually to the settings performed. note: predefined variables can also be used to interact with peripherals having send-receive blocks. how to use the send and receive blocks double-clicking on the block, you can open the command setting environment, that consists in two drop-down lists (see relative figures) from which you can select the global variables defined and the peripherals enabled according to the definitions in the peripheral configuration. then, for example, if the a/d is set so as to convert only two channels, in the devices list you will find only a/d channel 0 and a/d channel 1. at this point, you will have to select the source variable (or the destination one) and the peripheral to which it is destinated. in addition you can specify a constant value to be sent to the peripheral. the constant must be in the [0, 255] range, with the exception of the triac and timer prescaler where you can specify a 16 bit value (i.e. in the range [0, 65535]. send block receive block 93
the peripherals that can interact with the global variables are described below: send block serial port copies the value of the variable in the transmission register of the sci. parallel port: copies the value of the variable on the output register of the parallel port. triac counter sets the value of the triac driver counter with the value of the variable. timer counter sets the value of the timer counter with the value of the variable. triac prescaler sets the value of the triac driver counter prescaler. only a constant value between 0 and 65535 can be specified. timer prescaler sets the value of the timer counter prescaler. only a constant value between 0 and 65535 can be specified. receive block parallel port reads from the parallel port and assigns the value to the specified variable. timer status: reads the timer status register and assigns it to the specified variable. only the first 2 bits are significative ones: bit 0 indicates if the status of the timer is start (1) or stop (0) and bit 1 indicates if the status is set (1) or reset (0). serial port read from the receive register of the sci timer counter: reads the timer counter and assigns it to the specified variable. 94 fuzzystudio ? 3.0 user manual
sci status reads the status of the sci. each bit of this byte has a particular meaning: bit 0 sets if transmission ended, resets otherwise. bit 1 sets if transmission register is empty, reset otherwise. bit 2 ninth bit value when the data frame is nine bit. bit 3 not used. bit 4 sets in case of overrun error. bit 5 sets if a data has been received. bit 6 sets in case of frame error. bit 7 sets in case of noise error for further details about sci functionalities see st52x301 data sheet. fuzzy output 0 reads the first output calculated by the fuzzy unit and assigns to the variable. fuzzy output 1 reads the second output calculated by the fuzzy unit and assigns it to the variable. a/d channel 0 reads the converted value of the a/d channel 0 of the and assigns it to the variable. a/d channel 1 reads the converted value of the a/d channel 1 of the and assigns it to the variable. a/d channel 2 reads the converted value of the a/d channel 2 of the and assigns it to the variable. a/d channel 3 reads the converted value of the a/d channel 3 of the and assigns it to the variable. when the settings have not been performed yet, in the two list boxes the writing none appears. clicking ok you confirm the settings carried out. note the change of the peripherals settings initialization may invalidate the settings previously car- ried out in the send or receive block. in this case, the settings of the block are reset to none. if you carry out a compilation without opening the send or receive block, the corresponding code is not generated and the compilation is carried out all the same. deleting or changing the name of a glo- bal variable involves the automatic erasing of the send or receive blocks that involve it, leaving an open node on the flow-chart. 95 chapter 13 - send - receive blocks
96 fuzzystudio ? 3.0 user manual
chapter 13 restart block the restart block can be inserted either from the menu insert or by the appropriate toolbar icon. the insertion of a restart block in the flow-chart, determines a jump of the program to its start; this is equivalent to a link connected under the start block. it allows the iterated performing of the program set. being this the only function of the restart block, it has no editing environment associated. then, a double-click on this block causes no effect. it is not compulsory to insert a restart block since a link to any part of the program can be used to iterate the program. take note that the last block of the flow-chart has to be linked to another part of the program because the program has to be cyclic. on the contrary an error message appears during compilation. 97
98 fuzzystudio ? 3.0 user manual
chapter 14 compiler after the definition of the main projects features, it is possible to compile the code to be loaded in the devices memories, by means of the programming functions and the programming board provided with fuzzystudio ? 3.0. to launch the compilation of the project, select the item compiler > run from the tool menu or click on the appropriate toolbar button. the output window will open (or is put in foreground) showing the behaviour of the compilation and the eventual error messages and warnings. the compilation is divided in three steps: script file generation in wcl language (.wcl), assembler file generation (.asm), machine code generation (.bin). between the first and the second phase, the debugging code is generated to use the fuzzystudio ? 3.0 debugger tool. the generation of the assembler file and code can vary according to the choices taken in the compiler option window. compiler options the dialog box of the compilation options allow to choose the compilation modes. to open this dialog-box select the item compiler > options ... from the tools menu. disabling of the .bin generation file containing the machine code: uncheck the check-box "binary". warning: disabling this option it will not be possible to program the device. disabling of the debugging code file: deselect the check box "debug". warning: disabling this option it will not be possible to use the debugger. in order to choose the generation mode of the assembler files; select one of the following: 1 . over/underflow control: allows to generate the code to detect, by using the instructions isoverflow() and isunderflow(), when an arithmetic instruction generates a value out of range allowing to discriminate the overflow from the underflow. the generated code is the least optimized. compiler button 99
2. with out of range control: allows to generate the code to detect, by using the instruction isoutofrange, when an arithmetic instruction generates a value of the allowed range, without discriminating the overflow from the underflow. the generated code is more optimized than the previous one. 3. standard code: generates a code that is more optimised than the previous ones, but it does not allow the use of the control instructions previously described. we recom- mend the use of this compiling option if you do not intend to carry out control on the results of the arithmetic instructions. possibility to limit the number of error messages: selecting the check box "limit messages" and specifying the maximum number of warning and error messages. compiler messages the following error messages can occur during wcl code generation: initialisation required for "name" the fuzzy variable "name" has not been initialised. use initialise command to initialise the fuzzy variable with a global or predefined variable. pending branch in block "name" after the block called "name" there is no other block or link connected. pending "yes" branch in block "name" the "yes" link of the conditional block called "name" is not connected to any block or link. pending "no" branch in block "name" the "no" link of the conditional block called "name" is not connected to any block or link. output link in loop in block "name" the link in output from the block called "name" is connected to itself: connect this link to a block or to another link. 100 fuzzystudio ? 3.0 user manual
warning default store in initialisation used for "name" the fuzzy output variables called "name" has not been associated to any global or predefined variable, so the current value is stored in default fuzzy0 and fuzzy1 variables. loop in block "name" the block called "name" is connected to itself generating a loop. prescaler value not supported the specified value for triac prescaler is not supported in st52x301 device. the use of this value may cause undesired behaviour. it is suggested to specify a value higher than 1. receive block "name" with no data the specified receive block has no data due to missing users specification or automatic deleting. send block "name" with no data the specified send block has no data due to missing users specification or automatic deleting. unreachable code in block "name" the block called "name" is not connected to the program flow and it is not compiled. fatal er rors the following messages can occur during assembler code generation: cannot access output file "name" the file called "name" containing the data generated by the compiler cannot be accessed. it may be caused by a disk full error or because the target directory is not accessible for writing operations or due to an internal error. try rebooting the computer. cannot copy from temporary file the temporary file containing the data generated by the compiler cannot be copied on the .asm file. it may be caused by a disk full error or because the target directory is not accessible for writing operations or due to an internal error. try rebooting the computer. cannot create temporary file a temporary file generated by the compiler during compilation cannot be created. it may be caused by a disk full error or because the target directory is not accessible for write operations or due to an internal error. try rebooting the computer. cannot open input file "name" the wcl file called "name" containing the wcl generated by the compiler cannot be open. the file may be corrupted or an internal error occurred. try rebooting the computer. cannot open output file "name" the assembler file called "name" containing the assembler code generated by the compiler cannot be open. the file may be corrupted or an internal error occurred. try rebooting the computer. 101 chapter 14 - compiler tool
cannot read dbi file the temporary file containing the data for the debugger cannot be read to be copied in .dbi file. the file may be corrupted or an internal error occurred. try rebooting the computer. cannot write on temporary file a temporary file generated by the compiler during compilation cannot be written. it may be caused by a disk full error or because the target directory is not accessible for writing operations or due to an internal error. try rebooting the computer. cannot write dbi file the debugger information file generated by the compiler during compilation cannot be written. it may be caused by a disk full error or because the target directory is not accessible for write operations or due to an internal error. try rebooting the computer. input stream error the wcl source file is corrupted or an internal error occurred. try rebooting the compute. no more available memory there is no enough memory to perform the operation. try again after closing some programs. unexpected end of source the wcl source file is corrupted or an internal error occurred. try rebooting the computer. wrong chip identifier "name" the chip name specified as target by the "#define chip_name" instruction is incorrect. errors argument is out of range the argument or operand is out of the range allowed for that function or type. byte value expected instead of "name" the item "name" has been found instead of a byte value. check the syntax of the expression. cannot define the mbf the membership function cannot be defined because there is no room for the related variable in antecedent memory. cannot use library function the specified function cannot be used in that context. cannot use relational operator in condition the conditional expression contains a relational operator that cannot be used. conditional expression too long the conditional operation contains more than one relational operation or operator. 102 fuzzystudio ? 3.0 user manual
constant "value" is out of range a specified constant or operation between constant is out of allowed values for destinatio n variable. function "name" not allowed the function "name" cannot be used in that context or a syntax error occurred. identifier %s too long the specified identifier is more than 32 characters. illegal operation the specified operation is not valid in context. impossible to add "name" variable the number of global variables exceeds the allowed number according to the defined fuzzy variables. integer value "value" is too high an integer value higher than 32767 has been found. check for syntax errors. invalid function name "name" the specified function "name" does not exist. check for syntax errors. invalid input register "name" the input register "name" specified in ldri instruction in assembler block is not valid. check for syntax error or if the predefined variables do not address an input register. invalid library function "name" parameters the parameters specified in function "name" are not correct: check for the number or position of parameters or for syntax errors. invalid operator "name" in expression the operator "name" in the expression is not allowed: check for semantic or syntax errors. label "name" is redefined the label "name" has been already defined before in the same or other assembler blo cks. label "name" is undefined in procedure "name_blk" the label "name" used in block "name_blk" has not been defined yet. check for syntax error or define the label. missing byte value in an assembler instruction a necessary byte value has not been specified. missing closing comment sequence the number of open parenthesis is higher than the closed ones. 103 chapter 14 - compiler tool
missing input register an input register name expected in ldri instruction in assembler block is not present. specify a correct input register in instruction. missing jump label in assembler block a jump instruction is not followed by a label. missing operand in expression the expression does not contain an expected operand. missing token the expression does not contain an expected operand or statement. this message may occur after previously detected error even if there is not an effective error in the specified place. missing user defined variable the expression does not contain an expected variable. "name" function not allowed with current compiler options the function "name" cannot be compiled with the currently used compilation modality. change this in compiler option dialog box. not allowed function "name" in context the specified function "name" is not a valid name. check for syntax error. not readable predefined variable "name" the write-only predefined variable "name" has been used in read operation. not writable predefined variable "name" the read-only predefined variable "name" has been used in write operation. orphan operand in expression an expected operator is missing before the operand. predefined variable "name" is read only the read-only predefined variable "name" has been used in writing operation. predefined variable "name" is write only the write-only predefined variable "name" has been used in reading operation. real value "value" not allowed the specified real value is not in the range of the allowed values. redefinition for name "name" the local variable "name" has been redefined inside the same block. signed value "value" is out of range in a conditional expression, a constant higher than 127 or lower than -128 has been specified. 104 fuzzystudio ? 3.0 user manual
too few parameters in "name" function one or more parameters are missing in the specified function "name". too many operators in expression the expression contain more than one operator. spilt the expression in equivalents containing only one operator. undefined variable "name" the variable "name" has not been defined yet. define the variable or check for syntax errors. underflow in constant operation an assignation expression with the difference of two constants have been specified and the result gives a value out of the allowed range of the destination variable. unexpected binary operator in expression a unary operator was expected in expression and a binary one was found. unexpected token "name" the item "name" is not allowed in that position or is not an allowed identifier. this message may occur after previously detected error even if there is not an effective error in the specified place. unexpected unary operator in expression a binary operator was expected in the expression and a unary one was found. unsupported expression the specified expression is not supported by the compiler. check for syntax errors. user defined variable expected instead of "name" the item "name" was found instead of a user defined variable in assembler block instruction. unrecognised symbol "char" the not allowed character "char" has been found in the program. check for syntax errors. internal errors the messages included in the following list normally should not occur. if one of this messages occurs it must be considered as an internal error: contact stmicroelectronics - fuzzy logic b.u. cannot define a procedure outside level empty antecedent list in fuzzy rule first parameter "name" is not unsigned byte value first parameter "name" is not constant invalid configuration register "name" 105 chapter 14 - compiler tool
invalid define keyword "name" invalid define keyword value invalid device register "name" invalid first parameter invalid fuzzy output mapping "name" invalid fuzzy output "name" invalid interrupt number invalid left vertex distance "value" , assuming 0 invalid mbfxxx index "value" invalid mbfxxx string "name" invalid procedure name "name" invalid right vertex distance "value" , assuming 0 invalid second parameter invalid type for fuzzy output variable "name" invalid variable name "name" invalid vertex "value" , assuming 0 missing chip definition missing configuration register missing define keyword missing define keyword value missing device register missing fuzzy membership missing fuzzy variable 106 fuzzystudio ? 3.0 user manual
missing interrupt number missing left vertex distance, assuming 0 missing procedure name missing procedure type missing right vertex distance, assuming 0 missing variable name missing vertex assuming 0 not existing fuzzy variable "name" not existing membership function "name" in variable "name" out of permitted range value redefined procedure "name" redefinition for variable too many antecedents in fuzzy rule undefined membership "name" for variable "name" unexpected fuzzy var name for end statement wrong procedure name "name" (expected "name") 107 chapter 14 - compiler tool
warnings decimal part rounded to "value" the decimal part specified is not supported by the program precision. the number is rounded to the value "value". no fuzzy rule defined in fuzzy block "name" the fuzzy block "name" does not contain any rule. write rules or delete the block. type mismatch assuming default type a local signed byte variables has been defined in the assembler block and it will be considered as byte. messages that can occur during machine code generation the only message that may occurs during this compilation phase is the following: out of chip code space the generated program is longer than the available chip memory space. try optimising the program. other messages that may occur have to be considered as internal errors: contact stmicroelec- tronics - fuzzy logic b.u. 108 fuzzystudio ? 3.0 user manual
chapter 15 debugger the debugger tool allows to test the developed program by means of the chips simulation. the debugger graphical environment allows to choose and visualize, through the plotting window, the signals to be observed in their time evolution. then, you can test your program before implementing the application. using the debugger tool the following functionalities are available: simulation of the chip for a user-defined time interval. visualization of the results in a graphical plotting window and in decimal, hexadecimal and binary numeric value. wcl tracing program with step-by-step debugging executing a wcl program line for each step. visualization of the generated assembler with the indication of current line. visualization of the chips internal registers in decimal, hexadecimal and binary format. trace sequence of the program block in execution. status report of the debugger. to execute the debugger you need to select the item debugger from the menu tool. this operation will activate the debugger by opening a window named wcl source from which you can open or recall all the windows related with the debugger. note: if the project has not been compiled after the last change, the debugger cannot be run and a message inviting you to compile before opening the debugging session is generated. general description this section provides an overview of the major elements of the debugger environment such as menus, toolbar and status bar. for additional information refer to index and on-line help. these are the main functionalities of the debugger: opening or switching to the other windows of the debugger view. setting of the time interval you want to simulate, indicating the time unit. starting of the simulation either in a continuous or step-by-step way. stop or reset the simulation. opening of the watch edit dialog box to select the variables to observe. the same operations can be performed selecting the relative item from the menu debugger, while the menu option allows to change the fonts. debugger button 109
debugger menus the debugger main menu is context-sensitive:when launching the debugger, the item tool disappears and the items debugger and options appear. file contains commands to create, open, close, save and print a project; project info and list of recent files. edit provides standard editing commands. view allows to toggle on/off toolbar, main toolbar and status bar. debugger allows to open the following windows: watch view, locals view, block trace, asm view, register view, status, input editor and watch edit. moreover it allows to run or reset the debugger. options allows to open the font selection dialog-box. window contains commands related to the windows management. help contains help commands. debugger toolbar the window toolbar is common to all the windows related to the debugger environment. wcl source window the wcl source window appears when executing the debugger. it shows the listing of the program in wcl format so as to allow the tracing of the program during the simulation. an arrow indicates the current line to be executed. watch view watch edit input manager simulation time time unit run stop step restart asm view register view locals block trace status fonts 110 fuzzystudio ? 3.0 user manual
clicking with the right mouse button over a wcl program line, a breakpoint is inserted ( this is preceded by a bullet at the beginning of the line); in this way, during the programs execution the program stops when encountering the breakpoint line. to remove the breakpoint, click with the right mouse button over the programs line again. watch view window the watch view window displays in numeric format the values of the signals and of the selected variables. these are then plotted in the graphic window in their time behaviour. the selection is carried out by means of the dialog box watch edit that allows to add or remove the signals and the variables to be watched. a watch can be displayed as follows: global variables: name [ regi ste r, typ e] udec [dec hex bin] fuzzy variables: block : na me [ re gis te r] udec[dec hex bin] mbf udec[dec hex bin] ... mbf udec[dec hex bin] signals name [re gis ter( bit :bit )] udec [dec hex bin] 111 chapter 15 - debugger
where the following indicate: name signal or variable name register register address corresponding to the variable type variable type: byte or signed byte udec current value in users coordinates dec current value in decimal format hex current value in hexadecimal format bin current value in binary format block fuzzy block to which the fuzzy variable belongs mbf membership function name register(bit:bit) registers address with the bit part considered. watch edit dialog box allows to add and remove signals and variables from the watch and plot windows. to open this dialog-box, select the item watch edit from the debugger menu or click on the apposite toolbar button. the watch edit dialog-box consists of three list boxes respectively named topics, watch items and plot items. 112 fuzzystudio ? 3.0 user manual
1. topics the topics list box contains the names of the topics to which variables and signals are associated: peripherals: double clicking on peripherals, the list of the peripherals available is displayed. then, double clicking on one of these topics, the items lists display the signals and the variables that refer to that peripheral. globals a double click on this topic shows the list of the global variables on the watch items list and the list of the corresponding registers on the plot items list. fuzzy with a double click on the topic fuzzy, the list of the defined fuzzy blocks is shown. double clicking on one of these, the list of the variables defined in such a block appears in the watch items and plot items lists. 2. watch items when one or more items from the watch items list have been selected, click on the add watch button to add these items to the watch view items list or click remove watch to delete them from the list. single or multiple selection are available. double-clicking on one item in the list you can add or remove it from the watch view. 3. plot items after you have selected one or more items from the plot itemss list, click on add plot to add the plot items to the list of signals to be plotted graphically, or click remove plot to delete them from the list. single or multiple selection are available. double-clicking on one item in the list you can add or remove it from the watch view. in the items lists an arrow next to the item indicates if this has already been inserted (-->) or not inserted (<--) in the watch view or in the plot signals list (if not inserted, it can be selected and added to the list). note in signed byte variables, the value of the signed variable is indicated in decimal format and between brackets is indicated the corresponding value of the register in decimal, hexadecimal and binary formats. the value of the register differs of 128 as compared to the variable, according to the convention for the representation of signed byte variables. in the graphical plot window only the sig- nals can be found, then only the value corresponding to the associated register is indicated. 113 chapter 15 - debugger
watch edit signals the peripherals items names used in the watch edit list boxes, correspond to the signals and event of the chip. a detailed explanation of the meaning of this names is given in the following. a/d chan0 a/d channel 0 converted value (adc_out_0 register) chan1 a/d channel 1 converted value (adc_out_1 register) chan2 a/d channel 2 converted value (adc_out_2 register) chan3 a/d channel 3 converted value (adc_out_3 register) adc_irq_set a/d converter interrupt mask bit (mskad bit reg_conf14) adc_irq_prior a/d converter interrupt priority level (reg_conf15) adc_set a/d converter set/reset status (adtst reg_conf2) pa r a l l e l px parallel port pin no. x (x= 0-8) par_input parallel port register when read (inp_port register) par_output parallel port register when written (periph_reg_2) par_pin_set parallel port pin no. 8 bit (out bit reg_conf1) sci txd serial port transmission pin rxd serial port reception pin sci_input serial port receive register (scdr_rx register) sci_output serial port transmitter register (scrd_tx register) sci_irq_set serial port interrupt mask bit (msksci bit reg_conf14) sci-irq_prior serial port interrupt priority level (reg_conf15) sci_txstart serial transmission start/stop bit (te bit reg_conf3) sci_rxstart serial reception start/stop bit (re bit reg_conf3) sci_9bit serial transmission 9th bit data (t8 bit reg_conf3) timer timerout timer output pin tclk timer external clock pin tres timer external set/reset pin tctrl timer external start/stop pin timer_count_input timer counter current value (tmr_out register) timer_status timer status register (tmr_st register) timer_count_output timer counter buffer (periph_reg_0) timer_irq_set timer interrupt mask bit (msktm bit reg_conf14) timer_irq_prior timer interrupt priority level (reg_conf15) timer_set timer set/reset bit (tmrst bit reg_conf6) timer_start timer start/stop bit (tmst bit reg_conf6) 114 fuzzystudio ? 3.0 user manual
triac triacout triac output pin main1 triac zero crossing input pin main2 triac zero crossing input pin / prescaler output pin triac_count triac counter buffer (periph_reg_1) triac_irq_set ttriac interrupt mask bit (msktc bit reg_conf14) triac_irq_prior triac interrupt priority level (reg_conf15) triac_set triac set/reset bit (tcrst bit reg_conf10) triac_start triac start/stop bit (tcst bit reg_conf10) triac_trout_pin triac output enable/tristate bit (tctrs bit reg_conf11 external int external interrupt pin ext_irq_set external interrupt mask bit (mske bit reg_conf14) ext_irq_trigger falling/rising edge selection bit (exti bit reg_conf14) 115 chapter 15 - debugger
locals window the locals window is similar to the watch view window. the difference is due to the fact that only local variables block or the fuzzy variables and the internal registers of the fuzzy computational unit (see appendix c) of the current fuzzy block are listed. the local items are not plotted in the plot graphic window. note the local items values are displayed only when the block they belong to is in currently being simulated. trace window in this window is provided the sequence of the blocks as these are simulated. the first in the list is the last to be executes. together with the list of the blocks executed, the execution time of the same block is supplied once processed. 116 fuzzystudio ? 3.0 user manual
registers window in this window, the list of the internal registers of the chip is given with the decimal, hexadecimal and binary value. the registers can be of different type: reg_filexx register file registers generally associated to the variables; xx indi- cates the physical address of the register involved. reg_inputxx read-only registers of the peripherals, generally associated to the predefined variables; xx indicates the physical address of the register involved. reg_outputxx write-only registers of the peripherals, generally associated to the predefined variables; xx indicates the physical address of the register involved. reg_confxx chips configuration registers generally associated to the predefined variables having the same name; xx indicates the physical address of the register involved. reg_stx serial transmission register of the sci, associated to the predefined variable sci_buffer. reg_srx serial reception register of the sci, associated to the predefined variable sci_buffer. 117 chapter 15 - debugger
asm view window this window displays the assembler list generated by the compiler. an arrow indicates the assembler line in execution in the debugger. 118 fuzzystudio ? 3.0 user manual
status window it offers general information on the project and on the status of the current simulation. the information given are the following: project name of the project device target chip of the project freq frequency used simulation time simulation time carried out status status of the simulation reset reset status of simulation running simulation in progress done simulation interval performed break simulation stopped by means of the apposite button internal error contact stmicroelectronics. interrupt status enabled and disabled interrupt and priority levels mask interrupt mask and external interrupt trigger edge priority priority levels list input editor window before running the debugger it is necessary to define the value of the inputs of the chip. this is carried out by means of the input editor window. this window is made up of a chips schematic with its inputs. the inputs can be of two types: signal or analog input. an input of signal type can take only two logical states 0 and 1. to change the input status of a signal, click on the correspoinding pin. 119 chapter 15 - debugger
an analog input can take a value (in the range of real numbers) included between 0.0 and 2.5 volt: it represents the voltage of the signal put in input to an a/d convertion channel. to change this value, click on the corresponding pin: a dialog-box opens allowing to set the value; this is displayed in the pin schematics. how to use debugger to use the debugger the following steps have to ben performed: 1 after a successful compilation of the project select debugger from tools menu. warning: be sure you have checked the option debug in the compiler options dialog-box otherwise the debugger code file cannot be generated (refer to chapter 15 for more information). 2 open the watch view window by clicking on the apposite wcl source toolbar button or by choosing watch view from debugger menu. 3 open the watch-edit dialog box by means of the toolbar or from the debugger menu and select the variables and signals to be observed and/or plotted in a graphic way. 4 open the windows containing additional information on the current simulation to observe (asm view, register view, locals view, block trace, status view), if you are interested in them. 5 set the value of the inputs by means of the input editor window. 120 fuzzystudio ? 3.0 user manual
6 run the step-by-step simulation clicking on the step toolbar button: the current wcl instruction will be carried out; consequently the items modified are updated in the various views and the selected signals are plotted in the plot window. the arrow that indicates the current wcl instruction goes to the next one. 7 repeat to execute the next lines. if you want to perform a free running simulation for a certain period of time: 1 insert in the simulation time in the apposite edit box, indicating the time unit (ns, m s, ms, s). 2 select run from debugger menu or click on the apposite toolbar button. 3 the simulation can be stopped by inserting a breakpoint or clicking on the stop button. 4 the data are updated in the views and the signals can be observed in the plot window. plot view window the simulation results are represented in their time evolution, in a graphic way in the plot view window. the signals and buses selected in the watch-edit dialog box are traced here. the signal is a function with two possible values that are the logic states 0 and 1 and is represented with a continuous broken line; the term bus indicates the content of a register or a set of signals that is inserted in a continuous stripe, broken in the points where the value changes. during the execution of the instructions the plot window is updated with the values produced by the chips simulator. at the end of the simulation of the time interval defined by the user or after a stop command of the same emulation, the signals can be carefully examined by means of the commands provided by the plot window. 121 chapter 15 - debugger
plot view menus available menus are: chart contains commands to copy the graphic in the clipboard as bitmap or metafile and change the settings of the printer and printing options. too ls select the function and toogle the command to move along the selected function. zoom these commands give you options for reducing or enlarging the chart display. options select the time scale and the values numeric format. view these commands allow you to change the color settings of the background and foreground, show/hide grid, legenda, toolbar, zoom bar and status bar. help contains help commands. plot view window toolbar the plot view window includes a toolbar to help you perform the most frequently used commands quickly. to execute a task by means of a button, just click the related button on the toolbar. print and copy the graphic on the clipboard the graphic obtained by the simulation can be printed selecting the command print (ctrl+p) from the menu chart or use the apposite toolbar button. before printing, verify the printers settings are correct by selecting the command print setup from the chart menu. to copy the graphic on the clipboard select the command copy from the chart menu. this command offers two options: copy as bitmap (ctrl+c) or copy as metafile (ctrl+m) allowing to export on clipbard the graphic in the most suitable format. zoom the plot view window gives you option to change the screen display in order to better examine the results. to horizontally enlarge a portion of the selected signal in order to observe a shorter time interval simulation, you can do one of the followings: - select the command zoom in from the zoom menu: this command will expand the graphic starting from the left extreme currently displayed. - use the apposite toolbar button. - click with the left-mouse button on the point you want to enlarge; in this case the new interval will be centred in the point indicated. this option is available only if activated by the zoom enable toolbar button. zoom bar copy bitmap, metafile, print, save and open select, gravity show/hide legenda, grid colors about 122 fuzzystudio ? 3.0 user manual
- click on a specific area and drag a rectangle to define the area you want to zoom: the new extremes will coincide with the extremes of the window. this option is available only if activated by the zoom enable toolbar button. to horizontally shrink the selected signal and observe a longer time interval simulation: - select the command zoom out from the zoom menu; this command will determine the shrinking of the graphic starting from the left extreme currently displayed. - use the apposite toolbar button. - click with the right-mouse button on the point you want to reduce; in this case the new interval will be centred in the point indicated. this option is available only if activated by the zoom enable toolbar button. note using the mouse buttons it might occur that one of the extremes goes outside the defined range. in this case, the extreme is calculated again and located at the extreme of your definition range. however, the centre will be shifted as regards to the point in which you clicked with the mouse. to perform the zoom out, you should have used the zoom in command at least once. to restore the standard size select restore from zoom menu or click on the apposite toolbar button. the zooming factor ca be set specifying an integer number by means of the command custom... from the zoom menu or from the apposite toolbar drop-down list-box. note it is not possible to perform zooming operations while the debugger is running. signals and bus selection to highlight a signal or a bus you want to examine, it is possible to operate in the following modes: - select the signal/bus by choosing tools > select function - select signal/bus from the drop-down list box available in the toolbar. - select the signal/bus from the legend, if activated. to activate the legenda select the item legenda from the view menu or click on the apposite toolbar button. in the same way it is possible to enable/disable the grid by choosing grid from the menu view. once a signal/bus is highlighted it is shown with thicker lines and can be examined with the function gravity. this consists of a vertical bar moving along the graphic highlighting the time value (x) and the corresponding value of the signal/bus in that point (y). these values are displayed in the status bar. to activate the function gravity work do the following: - select the item gravity from the tools menu. or - click on the apposite toolbar button. 123 chapter 15 - debugger
changing time base the time base is by default expressed in nanoseconds. this time base can be changed selecting the desired base (from nanoseconds to seconds) from the menu options> time. the bus numeric values can have three types of representation: decimal, hexadecimal and binary. the representation of the numeric values can be modified by the menu options > format. changing colors it is possible to change the color of the background, of any signal or bus traced. select the command colors ... from the view menu. a dialog-box appears allowing to select the color of background, foreground and the commands to select each signal/bus and change the color. 124 fuzzystudio ? 3.0 user manual
chapter 16 how to program st52x301 once the editing of the project has been completed and after a successful compilation, it is possible to program the device by using the programming board supplied with fuzzystudio ? 3.0. to program st52x301: 1 connect the programming board to the parallel port lpt1 or click on apposite toolbar menu. 2 insert a blank st52x301 device in the apposite socket. 3 feed the board by means of a 17v dc power supply. note: if you use a different power source, it is suggested to use a power supply from 15 dcv up to 18 dcv. 4 choose programmer from tools menu or click on the apposite toolbar button. programmer main features the st52x301 basic programmer has been designed to allow a fast programming of the eprom or otp version of the fuzzy microcontroller. programs eprom and otp versions pc driven fast parallel code transfer leds programming monitoring memory blank-check its control software runs under windows? environment. it can be started by clicking on the apposite toolbar button or menu from fuzzystudio ? 3.0 software and drives the programmer board through the parallel port lpt1. after a memory blank-check, the binary program code is loaded into st52x301 eprom directly from fuzzystudio ? 3.0 main environment. the programmer package is composed of: 1 programming board 1 communication 25 wire flat cable 1 sample of st52x301 125
hardware installation to install the st52x301 programmer, you have to: turn off the pc connect the 25 wires cable connector to the pc lpt1 parallel interface turn on the pc run fuzzystudio ? 3.0 insert the device before swtiching on the programmer switch on the st52x301 programmer board (15vdc to 18vdc). chip insertion when inserting the st52x301 device into the plcc socket, it is important to take care of the correct orientation in order to avoid a possible damage to both the board and the device. pin 1 of chip must to be oriented towards the center of the board the red led (power on led) will have a weak light if the device is wrongly fitted into the socket. moreover, it is mandatory to switch off the board during the chip insertion and switch it on after the operation in order to have a correct power-on reset of the internal eproms chip. 126 fuzzystudio ? 3.0 user manual
hardware description the programmer board is a simple interface between the pc and st52x301 memory banks. this architecture allows a direct control of tfl31 memory signals by means of a pc. because of data bus unidirectionality in several parallel ports, the in-board standard logic supplies an hardware comparison between the data word to be write and the written data word. this solution allows an immediate verifying of the programmed code. the board is designed to work with a wide range of power suppliers (15vdc to 30vdc unstabilized) and to work with a low cost 25 wires flat cable (unshielded cable). a red led is used to monitor the power and the short circuits during a possible wrong insertion of device. a green led is used to monitor the programming phase. a button allows the eproms address counter reset. it is suggested to push the button before programming although a power-on reset network is present on reset pin. programming phase after the compilation phase the main software will generate a binary file with the same fuzzy project name. this binary code will be loaded into st52x301 memory in the subsequently programming phase. the programming operations are performed directly by selecting the programmer item from the tools menu or by clicking the apposite toolbar button. the programming phase starts with a default blank-check of st52x301 eprom and continues with the data writing. during these phases, a green led will light to indicate the memory access. the downloading generates a .log file named download.log. this supplies the following information: the name of the binary file bin containing the program code to be loaded onto the device. the file contained in file .bin in hexadecimal format. the result of the device programming indicating the code lenght contained in the file .bin, in hexadecimal and decimal (into brackets) format, and the code lenght effectively transmitted (if an error occurs, this lenght does not correspond with the previous one). note: it might occur that the green led is lighting when the pc is on; it will be turned off after fuzzy- studio ? 3.0 has been run. it is suggested to disconnect the board from the pc parallel port when not is use, becuase it may cause problems to the pc operating system when fuzzystudio ? 3.0 is not open. 127 chapter 16 - st52x301 programmer
error messages the software can detect some problems related to the programming board. during the programming steps fuzzystudio ? 3.0 output window could display the following messages: the output window will appear and these are the messages it can show : "successfully programming" the device has been successfully programmed and is ready to be used in the application. "data not found; please compile before programming" the current project has not been compiled yet, or the file obtained is not available anymore. in this case compile the project and restart the programmer. "invalid data; please compile before programming" the file obtained after the compilation is corrupted. recompile the project and restart the compiler. "data transmission failure" an error occurred during the data transmission to the parallel port; check if the device has been correctly inserted in its socket or check if the board is correctly connected to the port and if power supply has been connected. "device not blank" the device inserted is already programmed. "not enough memory" the pc memory is not enough to perform the programming of the device. close some applications and try again. "internal error" an internal error occurred. contact stmicroelectronics - fuzzy logic b.u. 128 fuzzystudio ? 3.0 user manual
129 chapter 16 - st52x301 programmer
appendix a - fuzzy logic introduction. human language and indeterminacy in 1950 alan turing proposed a way to test computers for intelligence. he argued that if we have a human (the interrogator ) talking via keyboard and screen with another human and a computer, and the interrogator is not able to decide which one is the human and which one is the computer just from the analysis of the answers to his/her questions, then we have to admit that the computer (or program) is intelligent. so far, no computer program able to pass this test has been written. it is very clear that the difficulties involved in designing such a machine (or software) are as complex as the human way of thinking. the interrogator can ask absurd questions such as: " yesterday i saw a donkey flying over my house, what do you think of that? ", therefore the program needs to have a huge database of facts concerning animals and things and deduction rules of common- sense reasoning. moreover, one of the main problems is the communication language. human natural languages are very imprecise and ambiguous. however they are understood and used by humans in their everyday life. part of our intelligent behaviour certainly consists of this under- standing common language capability. however, it is not easy (and it is indeed a very challenging task) to fully understand how humans accomplish this task and, as a by product, how to teach machines to do it. for instance, we make a heavy use of adjectives , that is to say words whose task is to classify objects. the objects classified by the adjectives belong to any universe of discourse which is the set of all possible objects to which the adjective may be applied. such universes of discourse may depend upon the context. for instance, the adjective tall may be applied to humans or to buildings, etc. computers are able to understand very well adjectives such as even or odd, but how can they deal with big or small when referred to numbers? todays machines are based on classical logic. a logic comprises a formal language for making statements about (certain) objects and reasoning about properties of these objects. classical logic has been for many years the only mathematical mean of reasoning and it has been extensively applied in many applications related to artificial intelligence and control. classical logic is black and white (0 or 1). it relates to a binary world which is the same one on which our computer are (mostly) based on. even or odd are binary adjectives. a number is either even or odd. no other possibilities are allowed. but when can we say that a number is big or small ? likewise, when we say that a certain person is married or single we are making a statement which is 0-1: a person is either married or single, no other possibilities. however when we say that a person is young or old we are making an imprecise yet for human beings useful and well understood statement. if we wanted to define the adjective young by means of classical logic we would need to find a threshold value, say for instance 30 years, so that if a person is less than thirty then is young, more than thirty is old. however, we would have the unreasonable result that in a matter of seconds one person would change status from young to old. fuzzy logic (and more in general fuzzy set theory) provides a mathematical tool to deal with such a kind of uncertainty and imprecision. a-1
a general overview despite the meaning of the word fuzzy , fuzzy logic is a precise and exact mathematical instrument which can be used for control systems with the advantage of simplifying the development of application of any complexity. the above claimed development simplification is determined by the possibility to express the system knowledge by means of linguistic expressions rather than mathematical equations, as needed by traditional techniques, which in many cases are a quite complicated way to express human experience. the system development is also simplified because one can use control rules which are locally defined. by combining the linguistic and local approaches of the rules, it is possible to evaluate in a very simple way the effect of a single rule and in turn the way of modifying the rule to improve the results. to better clarify how to transfer human experience to a fuzzy expert system we will use a simple but complete example regarding the driving of a vehicle in proximity of a road crossing controlled by a light. the information we can use is: color of the light distance from the crossing vehicle speed the goal is to control the vehicle speed by means of an action that can be: to brake to keep the speed to accelerate the linguistic approach. fuzzy logic is a formal instrument that partially closes the gap between human reasoning and computers world. this is possible because we can use reasoning rules which can be expressed in a linguistic way, that is to say the same way that a human being would express them to another human being, to teach him/her how to make a decision and act given certain facts. both antecedent and consequent part of the rules do not express defined actions but respectively they are reference conditions and behaviours. notice that the consequent part of each rule contains only a qualitative expression of the action to be performed, while the quantitative expression of the final decision is determined by the occurrence of all the rules. a-2 fuzzystudio ? 3.0 user manual
going back to our example we could say: if the light is red and the speed is high then the action is to brake; if the light is red and the speed is low and the crossing is far away then the action is to keep the speed if the light is yellow and the speed is medium and the crossing is far away then the action is to brake ........ if the light is green and the speed is very low and the crossing is very close then the action is to accelerate by comparing the observed data with the reference term we obtnain a degree of truth which determines how much the observed condition is really the hypothesis of the rules and consequently how much the final decision must be similar to the reference conclusion expressed on the rules light is green, speed is medium, the crossing is not far red, yellow, green; very low, low, medium, high; very far away, far away, close, very close if the light is green and the speed is medium and the crossing is away then the action is to keep the speed the above action rules are a result of the experience gained in time and to them we refer every time we approach a road light. every time we have to make a decision we use rules specifying the correct behaviour under well known conditions, which are used as a reference to be compared with the observed data. in our example, the observed data are the road light colour, the distance from the road crossing and the vehicle speed, which might be obtained from the speed meter rather than visually approximated with respect to the external world; the decision to make is related to the pressure to be exercised on the brakes or on the accelerator. it is important to stress once again that the decision is determined by all the rules in a way which is proportional to their degree of truth. a-3 appendix a - fuzzy logic introduction
50 km/h 70 km/h 60 km/h binary set fuzzy set figure 1. fuzzy logic, fuzzy sets and membership function to allow the computer to make decisions according to the linguistic rules we must make possible for it to evaluate the quantity that we have called similarity degree of the observed data and the reference terms. this can be done by using fuzzy logic. fuzzy logic is an extension of the binary or boolean logic on which is based the mathematical reasoning usually encountered in schools or universities. to briefly introduce fuzzy logic we will start from binary logic and we will sketch their differences. a boolean or binary set is a collection of objects all verifying the same condition (the characteristic property of the set). for instance, we could define the set of medium speeds as the collection of all the speed values between 50 e 70 km/h. in this way we are implicitly saying that all values which are less than 50 km/h or more than 70 km/h do not belong to the set of medium speeds. a fuzzy set is associated with a reference term (for example red, yellow, green for the light colour) and is characterized by a collection of objects which are similar to it. if, for instance, we decide that a medium speed is 60 km/h, the closer a certain speed value is to 60 km/h, the higher is its similarity degree to 60 km/h. this similarity degree is what is denoted as membership degree to the fuzzy set. all the membership degree associated to a fuzzy set generate a shape called membership function. the difference between the binary set and the fuzzy set medium speed is illustrated in fig. 1. in this way, by using boolean logic the made decision will be the same for all the values between 50 e 70 km/h; moreover, we might obtain a completely different action in going from 50 km/h to 49.999.. km/h. on the other hand, if we use fuzzy logic we would have an answer which will proportionally depend on the membership degree . a-4 fuzzystudio ? 3.0 user manual
fuzzy reasoning it is important to stress at this point that in order to make a decision it is necessary to have an experience in the field, which in fuzzy terms means that we need to have defined, for each input and output variable, the universe of discourse (i.e. the set of elements where it is defined), the fuzzy sets and the related membership functions, and to have identified the inference rules. the fuzzy reasoning is composed by two computational steps, which permit to infer fuzzy value, for the output variables, starting from fuzzy value, for the input variables. these steps are: 1 alpha-values computation: given the observed values we compute the membership degree to the fuzzy sets by means of the membership functions. for instance, if we suppose that we have the following data: light colour: green speed:53 km/h distance from crossing:350 m the operation of alpha-values computation provides us the degrees of memberships of 53 km/h to the fuzzy sets very low, low, medium, high etc.; the degrees of membership of 350 m to the fuzzy sets very far away, far away, close, very close, etc. and combines this values in order to compute the strength of activation of each fuzzy rule. in figure 2 we give a pictorial representation of the computation of the membership degree of 53 km/h to the fuzzy set medium speed . medium speed fuzz y set 60 km/h 53 km/h the alpha-value corresponds to the intersection point between the observed data and the membership function a figure 2. a-5 appendix a - fuzzy logic introduction
figure 3. 2 fuzzy inference: this operation formalizes the fuzzy reasoning by using the fuzzy rules and the alpha-values to deduce the fuzzy output. in order to use fuzzy logic capability in real applications, involving crisp values which are usually supplied by sensors for the input and provided to the actuators for the output, it is necessary to accomplish the fuzzification and defuzzification operations to interface between the real system and the fuzzy inference engine. fuzzification: given an observed data we fuzzify it by means of the association with a corresponding function. up to now, to speed up the calculus and to simplify the problems, the experts have been used to associate to each observed data a crisp value. defuzzification: this is the last operation of the reasoning process. in this case we obtain a precise answer and consequently a precise action to be taken. a-6 fuzzystudio ? 3.0 user manual
figure 4. the mathematical definition of fuzzy sets to better clarify the concept of fuzziness that we are going to mathematically introduce let us briefly mention the sugar paradox . suppose that we have a cup of coffee with no sugar. if we add a little grain of sugar certainly we still have a bitter cup of coffee. more in general, given a bitter cup of coffee by adding a little grain of sugar we are still left with a bitter cup of coffee. however, this process of adding little grains of sugar will eventually produce a sweet cup of coffee. from a classical logic point of view we have a paradox. what is happening in this case is that the passage from bitter to sweet is continuous and not abrupt as classical logic would want. if we consider then the sets of sweet cups of coffee and bitter cups of coffee we have the situation described in fig. 4. the border between sweet and bitter is not crisp but fuzzy. so for every element of the gray area we have a certain amount of indeterminacy concerning its sweetness. is this indeterminacy of a statistical nature ? this is a natural question that scientists working in the field of fuzzy logic have already answered many times and in many ways. to answer this question we have to consider two cups of coffee. the first one has a high degree of sweetness. the sweetness concept is not of probabilistic nature. it has a linguistic value and its meaning varies from person to person. this means that the same cup of coffee can be sweet with respect to a person and less sweet with respect to another person. regarding the second cup, we know that with high probability is sweet and with low probability is bitter. if one wants a sweet cup of coffee or at least with some sugar in it then the choice is the first cup. by choosing the second cup one may end up drinking a completely bitter coffee (not likely, but still possible). choosing the first cup, one will be sure that the coffee is not bitter even though we do not know exactly the amount of sugar in it. a-7 appendix a - fuzzy logic introduction
the sugar paradox introduces the notion of sets of a particular nature. these sets are such that some elements belong to them only up to a certain extent. a cup of coffee with just a little sugar cannot be considered bitter but can be considered sweet up to a certain extent only. this kind of membership cannot be formalized with classical (crisp) set membership functions defined, for a set a and an element a ? u , as: a ( a ) = ? ? ? 1 0 a : u ? {0,1}. which has value 1 (for membership) or 0 (for non membership). l.a. zadeh introduced the notion of fuzzy sets in 1965. he defined them as a class of objects with a continuous membership function, valued into the whole interval [0,1]. this way a cup of coffee with just a little sugar will have (for instance) a degree of membership 0.1 to the set of sweet cups of coffee. a possible membership function for the fuzzy set sweet is shown in fig. 5. thus, a fuzzy set a can be completely characterized by its membership function a defined as: a : u ? [0,1] where u (the universe of discourse) is the set of elements where a is defined or equivalently the set of parameters to be taken into account to define the degree of membership. if a ? a if a ? a figure 5. a-8 fuzzystudio ? 3.0 user manual
membership functions at this point, a natural question is: where do membership functions come from? the answer is straightforward. they come from people experience and are related to people knowledge and understanding of the problem to be modeled. for instance, a membership function for hot temperature when referred to a room temperature will be different from the membership function referred to an oven temperature. moreover, it may (and generally will) change from person to person. fuzzy set operators to build our mathematical formalism of fuzzy sets we need to define the operators that allow us to combine fuzzy sets and obtain new ones, i.e. we need to extend to the fuzzy case the definition of operators such as set complement , union , intersection , and predicates such as set containment to the fuzzy sets. to do it we need to introduce a new operator called "triangular norm" and commonly known as t_norm . stated i = [0, 1], the t_norm t function is defined as t: i ? i, and satisfies the following properties: 1 t(x,1) = x " x ? i 2 t(x,y) t(u,v) if x u and y v 3 t(x,y)= t(y,x) " x, y ? i 4 t(t(x,y),z) = t(x,t(y,z)) " x, y, z ? i where " means: for every value ? means: belong to a set ? means: correspondence between function domain and its support means: less or equal. the properties mentioned above are respectively: 1 neutral element existence with respect to t 2 monotony property of t 3 commutative property of t 4 associative property of t starting from t it is possible to define a function s: i ? i as: s(x,y) = 1- t(1-x, 1-y) a-9 appendix a - fuzzy logic introduction
known as t_conorm , maintaining the associative, commutative and monotony properties and satisfying the condition: a s(x,0) = x, s(x,1) = 1 " x ? i b t(x,y) = 1- s(1-x,1-y) " x, y ? i these operators are the basis for the fuzzy set operators definition. in fact, considering two fuzzy sets a and b the union and intersection operators are defined in terms of t and s as follows: ( a ? b )(x) = t(a(x),b(x)) " x ? x ( a b )(x) = s(a(x),b(x)) " x ? x the following step is the identification of t and s with some algebraic operators. in literature they are used to define: t(x,y) = min (x,y) " x ? i s(x,y) = max (x,y) " x ? i since these two operators satisfy the required properties. it is important to stress that these are the most commonly used association but they are not the only one. now we are able to formulate the fuzzy set operators. by doing this we will find out that certain laws of the aristotelian 0-1 logic do not hold any longer. set complement let us start with the set complement. the way this operator is classically defined is the following. given a set a subset of a universe u, the complement of a is the set whose elements are all and only the elements of u which are not in a , as shown by the (venn) diagram in fig. 6 thus, denoted by b the complement of a , for every a in u we have b(a)=1-a(a) these means that, if a is in a then its membership degree is 1 (a(a)=1), which implies that b(a)=0, so a is not in b . conversely if a is in b then b(a)=1 and in turn a(a)=0 and so a is not in a . notice that in particular for the classical logic holds: for every a in the universe of discourse we have that either a(a)=1 or b(a)=1. equivalently, we can say that the maximum between a(a) and b(a) is equal to 1. this property is known as the law of the excluded middle : every element of the universe of discourse is either in a or in its complement. no other possibilities are allowed. in terms of set operators: a b = u for every a in the universe of discourse we have that either a(a)=0 or b(a)=0. equivalently, we can say that the minimum between a(a) and b(a) is equal to 0. this property is known as the law of non contradiction every element of the universe of discourse cannot be both in a and in its complement at the same time. in terms of set operators: a ? b = ? what happens when a is fuzzy , that is to say when the border with its complement is not clearly defined as shown in the fig. 7 ? in this case we have to define the membership degree to the complement of a of the elements in the border of a . for consistency with the crisp case we define: a-10 fuzzystudio ? 3.0 user manual
b(a)=1-a(a) we notice however that both the law of the excluded middle and the law of non contradiction do not hold any longer. indeed, if 0 the above definition extends to the case of fuzzy sets by using the maximum rule as stated in the previous paragraph while speaking of t_norm and t_conorm operator. in details, the degree to which an element a belongs to the union of a and b is given by the maximum of the degree of memberships in a and in b : a b(a) = max(a(a), b(a)) set intersection the intersection of two sets is the set whose elements belong to both sets, as shown in fig. 9. figure 7. figure 8. a-12 fuzzystudio ? 3.0 user manual
the above definition extends to the case of fuzzy sets by using the minimum rule. in details, the degree to which an element a belongs to the intersection of a and b is given by the minimum of the degree of memberships in a and in b : a ? b(a) = min(a(a), b(a)) this way we have built a mathematical tool which allows us to deal with fuzzy sets in a formal and as we will see useful way. figure 9. a-13 appendix a - fuzzy logic introduction
the mathematical formalism of fuzzy logic fuzzy logic derives from fuzzy set theory. fuzzy logic is concerned with statements of type this coffee is sweet, my brother is tall, the temperature in the room is high. these statements are characterized by the presence of concepts (such as height, temperature etc.) called linguistic variables which are defined over a set called universe of discourse and which are given linguistic values . what is a linguistic value ? let us consider the example statement: the temperature in the room is high. we have no information on the exact value of the temperature but we have instead a good information to decide on the possibility that the temperature has a certain value. for instance we can say that 1 it is clearly impossible that the temperature is 10 degrees or less 2 it is very possible that the temperature is 30 degrees or higher. a linguistic value (applied to a concept) so generates a set of possibilities on the exact value of the linguistic concept. this set of possibilities (or possibility distribution) is the logical counterpart of a fuzzy set: in our examples the fuzzy set of high room temperature. for any given temperature t the higher is the degree of membership to the fuzzy set high room temperature, the higher the possibility that t is the exact temperature in the room. this kind of statements are indicated as fuzzy predicates . they are usually denoted by " x is a " where x is an element of the universe of discourse and a is a fuzzy term. the possibility value that "x is a" is also the degree to which the proposition "x is a" is true. the set of linguistic values that can be given to a linguistic variables is called term set . term sets are built starting from pairs of antonyms and applying to them logical and linguistic modifications. for instance the term set of the linguistic variable temperature can be described as follows linguistic variable temperature antonym pair hot, cold modifiers not, very, quite, etc. cold hot quite cold quite hot temperature membership degree figure 10. a-14 fuzzystudio ? 3.0 user manual
0 1 temperature 15 20 high medium 0 1 temperature 15 20 high medium medium and 0 1 temperature 15 20 high medium medium or high high figure 11. to each of this linguistic values corresponds a specific possibility distribution which is obtained from the basic ones via logical aggregations. the following picture illustrated a possible term set for the variable temperature. the logical connectives: and, or, not used to aggregate fuzzy sets correspond to the set operators. it is quite simple to understand how this connectives are defined if one has a clear understanding of the set operations. not: the logical negation corresponds to the set complement operator. so, given a fuzzy predicate x is a with degree of truth t , the degree of truth of not (x is a) will be 1 - t . and: the logical conjunction corresponds to the set intersection operator. therefore, given two fuzzy predicates "x is a" and "x is b" the truth value of "x is a and b" will be obtained by taking the minimum of the two input truth values. or: the logical disjunction corresponds to the set union operator. as a consequence, given two fuzzy predicates "x is a" and "x is b" the truth value of "x is a or b" will be obtained by taking the maximum of the two input truth values. fig. 11 gives a pictorial representation of the two logical connectives in the case we have the fuzzy predicates "x is high" and "x is medium" where x ranges over the universe of discourse of temperature. as we mentioned above, fuzzy statements are evaluated by means of linguistic values. therefore, along with the above mathematical operators, we can apply to them linguistic transformations (called hedges ). for instance, given " x is young " we can obtain " x is very young " or " x is quite young " etc. a-15 appendix a - fuzzy logic introduction
fuzzy reasoning the main reason for the world-wide popularity gained by fuzzy logic is its capability to formalize patterns of human reasoning in a very simple, efficient and useful way. the continuously growing number of applications in fields such as control theory, expert systems, robotics, image recognition, databases, etc. is an outstanding proof of it. the key idea comes from a simple consideration on classical logic. the fundamental inference rule, that is a rule that allows to obtain new true propositions from given ones, in classical logic is modus ponens: premise 1:if x is a then y is b premise 2:if x is a conclusion: y is b premise 1:if x is a then y is b premise 2:if x is a conclusion: yis b the meaning of modus ponens is clear: if we have that x is a is true and if it is also true that the fact that x is a implies that y is b then we can conclude that y is b is true. thus, from the true premises that " humans are mortal" and " john is human " we can deduce that " john is mortal ". fuzzy logic gives us a way to deduce useful conclusions either when the premises are not absolutely true or when the antecedent of premise 1 is similar but not equal to premise 2 or when premise 2 is obtained as a modification from the antecedent of premise 1. premise 1 above is in the form of a production rule of the kind usually applied in the field of expert systems. the production rule has the meaning: if the antecedent (x is a) is true then apply the action (y is b). production rules of this kind are applied in fuzzy system control. a-16 fuzzystudio ? 3.0 user manual
fuzzy computation fuzzy models are used whenever they can competitively provide better information about any physical process or any system. fuzzy models are simple and strongly related to the human knowledge. a fuzzy model is given as a collection of (fuzzy) production rules: fuzzy if-then rules. the collection of fuzzy if-then rules and the related membership functions represent the knowledge of the system. in the example below we have defined the following fuzzy sets for the input x i variables and the y output variable: x 1 : high, medium and low x 2 : high, medium and low y : a, b, c and we have the following set of fuzzy if-then rules: rule 1:if x1 is high and x2 is low then y is a rule 2:if x 1 is medium and x2 is medium then y is b rule 3:if x 1 is low and x2 is high then y is c as you can see above the correspondence between input values (condition) and output value (action) is expressed in terms of relation on input and output fuzzy sets. medium medium low high low high aa 12 a a a 1 2 3 0.9 0 0.5 0.6 0.9 0.3 = min (0.9, 0) = 0 = min (0.5, 0.6) = 0.5 = min (0.3, 0.9) = 0.3 figure 12. a-17 appendix a - fuzzy logic introduction
the rules are used as follows. step 1 : fuzzification phase. the input are coded associating to each of them the corresponding crisp value. step 2 : alpha-values computation phase. the coded input are compared with the antecedent fuzzy sets in order to evaluate their membership degree to the linguistic values. in our example above, given values a 1 and a 2 for the antecedents, we obtain the membership values: a 1 1 =high(a 1 ) a 2 1 =low(a 2 ) a 1 2 =medium(a 1 ) a 2 2 =medium(a 2 ) a 1 3 =low(a 1 ) a 2 3 =high(a 2 ) which are aggregated using the minimum rule in order to compute the strength to which the rules apply: a i = min ( a 1 i , a 2 i )i = 1..3 the figure 12 gives a pictorial representation of the alpha-values computation. step 3 : inference phase. using the alpha-values obtained from antecedent parts the membership functions of the consequent are modified. the most classical of the inference methods are the max-min method and the max-dot method. using the max-min method the membership functions of the consequent are cut at the alpha-value of the antecedent. so, defined u = {y 1 , ..y n } the universe of discourse of the output variable y, we obtain new fuzzy sets a b and c as follows: a(y i )=min(a(y i ), a 1 ), b(y i )=min(b(y i ), a 2 ), c(y i )=min(c(y i ), a 3 ). using the max-dot method the membership functions of the consequent are scaled using the alpha-value of the antecedent. so, we obtain new fuzzy sets a b and c as follows a(y i )=min(a(y i ) a 1 ), b(y i )=min(b(y i ) a 2 ), c(y i )=min(c(y i ) a 3 ). fig. 13 gives a pictorial representation of the two most classical methods of inference. max-min method max-dot method a a figure 13. a-18 fuzzystudio ? 3.0 user manual
the membership functions of the consequent part, computed following one of the criteria mentioned above, represents the inferred fuzzy set for each rule. the next step is the combination of these fuzzy sets in order to deduce a single value for the output variables. it is realized summing the modified output fuzzy set to obtain a new global fuzzy set g. the sum can be performed in two different ways: either logical sum which corresponds to the logical operator max, or arithmetic sum which corresponds to the point to point summation of the membership function values. the difference between them is illustrated in the figure 14. m.f.1 m.f. 2 max(m.f.1, m.f.2) m.f.1 + m.f.2 figure 14. the membership function g associated to the consequent is then used in the fourth step as follows. step 4 : defuzzification phase. the last step produces a crisp output from the fuzzy set g. in particular notice that this crisp value is an element of the universe of discourse. this crisp output will be the value of the control action. many defuzzification methods have been proposed. they vary according to the specific application and the designer knowledge and understanding of the system. we will describe below the most commonly used in the hypothesis that g is defined over a finite universe of discourse u={u 1 ,u 2 ,...,u n }: 1 center of gravity : the output value y is given by the formula y= s u i g(u i ) / s g(u i ) therefore we obtain the center of gravity of the area belonging to the real plane identified by g. 2 centroid method : the output value y is given by the formula y= s a i b i / s a i where i varies over the inference rules. a i is the area of the modified output fuzzy sets (i.e. a(y), b(y), c(y) for the proposed example) and b i the centroid associated with the fuzzy set. in the following picture we will illustrate the difference between this two defuzzification methods. the first one start from the global output fuzzy set g and deduces a crisp value as the center of gravity of g. this approach implies a problem in case of a logic sum of the modified output fuzzy sets, since the common areas are taken once only, implying the exclusion of the fuzzy sets covered by the others. the second one, based on the area of the single modified output fuzzy sets, implicitly implies the arithmetic sum, thus the common areas are taken twice. a-19 appendix a - fuzzy logic introduction
fuzzification fuzzy defuzzification y fuzzy computational model input 1 input n . . . . . . . . . . . . m= number of rules inference output rule 1 output rule 2 output rule m-1 output rule m alpha- calcolus a a a a 1 2 m-1 m figure 15. it is interesting to stress that, summing the modified output fuzzy sets using the arithmetic sum in the inference phase and applying the two different defuzzification methods, the result will be the same. 3 mean of maxima : the output value is given by the formula y= s m i / h where m 1 ,m 2 ,...,m h are the h values where of maximum membership degree is g. center of gravity method centroid method first modified output fuzzy set second modified output fuzzy set fuzzy set g centroid b 1 centroid b 2 figure 15. we conclude with a picture that summarizes the structure of a fuzzy computational model. a-20 fuzzystudio ? 3.0 user manual
bibliography [1] g. klir, t. folger: fuzzy sets, uncertainty and information. englewood cliffs, nj: pren- tice-hall, 1988. [2] d. dubois, h. prade: fuzzy set and system: theory and applications. new york: academic press, 1980. [3] h. zimmerman: fuzzy set theory-and its applications , 2nd ed. boston: kluwer, 1990 [4] a. kauffmann, m. gupta: introduction to fuzzy arithmetic: theory and applications . new york: van nostrand reihold, 1985 [5] t. terano, k. asai, m. sugeno: fuzzy systems theory and its applications. new york: academic press, 1987. a-21 appendix a - fuzzy logic introduction
a-22 fuzzystudio ? 3.0 user manual
appendix b - quick reference w.a.r.p. control language (wcl) general features of a wcl program wcl language is a medium-high level language dedicated for the programming of w.a.r.p. family processors. source code organization a generic wcl program is organized into 3 sections, set in the following order: chip target definition and characteristics global variables declaration procedure declaration for more information on each section internal structure refer to the following paragraphs. characters conventions wcl language employs all alphabetical characters, distinguishing between upper and lower cases, numeric digits and the following symbols: #, _, -, +, =, <, >, &, ^, |, !, (, ) the control characters (tabulation, return, ...) are considered as space characters. the language is "case-sensitive", i.e. it distinguishes between "high", "high", "high", ... . in particular, the following conventions are used: keywords (begin, end, if, ...) are entered in lower case; library functions name have initial capitals; predefined constants are typed in upper cases. naming conventions all names used within a wcl program are made up by a sequence of characters subject to the following constraints: the first character must be alphabetic; only alphabetic, numeric characters and the symbol _ are admitted; maximum sequence lenght is fixed to 32 characters. standard libraries wcl language allows to manage all w.a.r.p. family chips in the same way. due to the different functionalities and peripherals that characterize w.a.r.p. family chips, the information about each chip is contained in a standard library. this library allows to distinguish the control language for the chip controlled, but it should be continuously updated. all names defined in the standard library for a specific chip are to be considered as reserved and cannot be used for other purposes (for example, in the global or local variables definition). b - 23
conditional expressions a conditional expression is made up by an operand set connected by logic and/or relational operators, and supplies always a "true/false" value. operands the operands admitted within a conditional expression are all the variables (predefined, global and local) visible within the evaluation context of the condition and the numeric values (signed or unsigned). operators the operators admitted within a conditional expression can be of two types: logic or relational operators. logic operators have lower priority than relational operators. in case of numeric operands, the value "0" is considered false and true any other value. the following operators are indicated according to a decreasing priority order: ! ("logic not" unary operator) && ("logic and" binary operator) || ("logic or" binary operator) relational operators have higher priority than logic operators. these are indicated below according to a decreasing priority order: <, >, <=, >= (less than, greater than, less than or equal to, greater than or equal to) ==, != (equal to, different by) within a conditional expression the use of parenthesis is not allowed. the operators can be associated from left to right except where requested in a different way by the priority of the operators involved. moreover, it is not possible to use sequences of more operators of the same type. the maximum number of operators admitted in a conditional expression is 3, in order to evaluate the eventual membership to a value given to a given interval. b - 24 fuzzystudio ? 3.0 user manual
library functions in a conditional expression it is also possible to use the following standard library language functions. the available parameters are shown in table 1: function description parameter isbitset(bit,variable); verifies if a variable bit value is 1. bit = 0 ? 7 variable * isbitreset(bit,variable); verifies if a bit variable value is 0. bit = 0 ? 7 variable * isoverflow(); verifies if the last arithmetic-logic instruction performed has generated an overflow. isunderflow(); verifies if the last arithmetic-logic instruction performed has generated an underflow. isoutofrange(); verifies if the last arithmetic-logic instruction performed has generated an overflow o underflow. timerstatus(param); verifies if the timer is in set or reset status. set verify if the timer is in start or stop status. start scistatus(param); verifies the end of transmission tx_end verifies if the transmission buffer has been emptied tx_empty returns true if the ninth bit of the frame is "1" ninth_bit verifies if an overrun error has occurred overrun verifies if the reception buffer is full rx_full verifies if a frame error has occurred frame_error verifies if a noise error has occurred noise_error table 1. these library functions can be used instead of one of the generic operands of the conditional expression. their result will be true in case of positive check, otherwise it is false. b - 25 appendix b - control language
reference labels a reference label is a name, unique inside the whole wcl program, that allows to refer to a particular position in the source code. the label definition directly occurs in the position in which, through it, you want to refer, by using the following syntax: label_name: the symbol : does not belong to the label, it only indicates the end of the characters sequence that define the name. during the definition, such a symbol must not be separeted by the label name. in a wcl program it is possible to make reference to a label before its definition, but only from another point inside the same procedure in which will be later defined the label. predefined names besides the crisp global and local variables, inside a wcl program some predefined variables are also available. these allow to address particular configuration registers or the eventual data registers of the peripherals. these variables can indicate read-only locations, write-only or read/write and their use is conse- quently constraint. any information relative to the predefined variables depends by the selected chip and it is therefore contained in the standard library language. it is not possible to redefine the name of a predefined variable, using it for example in the definition of the user variables, either global and local. predefined variables are considered as "byte" variables, or unsigned. b - 26 fuzzystudio ? 3.0 user manual
chip features definition the definition of the chip features must be present at the beginning of the wcl program and provides a description of the chip required for the execution of the program, together with its particular configuration. the instructions present in this section are introduced by the symbol "#", to highlight the definition functionality of the working environment (in parallel with similar pre-processing instructions of the c language). within this section there are two types of instructions: 1. #chip chip_name this instructions allows to identify a specific chip of w.a.r.p. family that will be used for the wcl program. the instruction must be the first instruction of the program, unique and it cannot be omitted. the argument chip_name is a predefined constant, to be chosen among the ones contained for this purpose in the standard library language. 2. #define environment_variable value this instruction allows to define the particular working configurations of the chip and its internal peripherals, and is used to define the value of all possible functionment parameters of the chip selected, since apposite default values are not forecast. the argument environment_variable is a predefined variable, contained in the standard library language. the argument value depends from the particular environment_variable and must be chosen among the values contained for that purpose within the standard language library. all necessary instructions are grouped in a unique sequence located immediately after the instruction #chip. b - 27 appendix b - control language
global variables declaration this section immediately follows the one dedicated to the chip selection and its characteristics definition. two sets of information have to be defined, in the following order: the membership functions at first and then the global crisp variables. membership function definition this sequence of instructions allows to define the various memberships functions that will be later used by the fuzzy variables declared in the fuzzy procedures declared in the program. the syntax is described below: mbfxxx(distance_left, vertex, distance_right); the name mbfxxx() is an abbreviation for mbf000(), mbf001(), ..., up to the maximum number of membership allowed by the particular chip selected. the membership functions definition order is not relevant. it is possible to skip one or more numbering positions and it is also possible to place elements of such a list before or after. only the necessary memberships have to be declared and it is possible to declare them in the desired order, provided that their declaration occurs inside a unique adjacent block of instructions mbfxxx(). the parameters left_distance , vertex and right _distance allow to define triangular mbfs, appropri- ately locating the central vertex position on the x-axis ( vertex ) and the size of the right and left triangle semi-bases ( right_distance and left_distance ), as it has been defined for w.a.r.p. family chips. for more information refer to st52x301 data sheet. global crisp variables definition sequence of instructions that allow to define the crisp global variables are visible within the whole program. two types of crisp variables, signed or unsigned, are available according to the following syntax: byte variable_name [ = unsigned_value]; allows to declare, and eventually initialize, integer unsigned variables, defined in the range [0,255]. signed [byte] variable_name [ = signed_value]; allows to declare, and eventually initialize, integer signed variables, defined in the range [-128, 127] in both cases, the parameter variable_name, being visible within the whole program, must be unique. moreover, you cannot define define global crisp variables having the same name as the predefined variables. the global crisp variables can be defined in any order provided that it is inside a unique adjacent block of global variables declarations. the maximum number of crisp variables (global + local) allowed depends by the chip selected. b - 28 fuzzystudio ? 3.0 user manual
procedure declaration a procedure is a particular set of instructions of the wcl language characterised by the following syntax: begin type_procedure name_procedure; instruction; ..... instruction; end name_procedure; the parameter name_procedure is a unique name within the whole wcl program. the parameter type_procedure identifies the particular type of procedure, allowing to choose among the different elaboration environment and the relative set of instructions. the procedures are the following ones: arithmetic asm control folder fuzzy for more information refer to the following paragraphs for information on the different charac- teristics procedures. arithmetic procedures the arithmetic procedure allows to perform logic-arithmetic computations, organized by means of simple control flow structures. an arithmetic procedure can be defined within another control or folder procedure and cannot contain any type of procedure. local variables declaration inside the arithmetic procedure it is possible to define some crisp local variables, that will be added to the existing crisp global variables and will be valid in the single procedure. the crisp local variables declaration must occur immediately after the beginning of the procedure, in a unique sequence of instructions that follow the same syntax adopted for the declaration of global crisp variables. the maximum number of crisp variables (global + local) allowed depends by the chip selected. it is not possible to declare local variables with the same name as predefined or global variables. b - 29 appendix b - control language
flow control instruction the if instruction is the only flow control instruction available in an arithmetic procedure that allows to choose between two different sequences of instructions according to the evaluation of a conditional expression and is characterised by the following syntax: if condition then instruction; ..... instruction; [else instruction; ..... instruction;] endif; the syntax of the condition is the one described in the apposite paragraph about the conditional expression. inside the blocks then and else you can use any instruction allowed inside an arithmetic procedure, and it is then possible to define if nested instructions. note: library functions described in table 1 can be also used. logic & arithmetic operations the logic & arithmetic operations allowed inside an inside procedure are simple assignment instructions between a variable and an expression that contains an arithmetic-logic operator, according to the following syntax: variable = term operator term; where term can be another variable or numeric value. the operators admitted are the following ones: arithmetic operators: + - (unary and binary); logic operators: ~, &, ^, | (not, and, xor, or) the arithmetic operators can work with any type of operands while logic operators only work with byte type operators (unsigned). moreover, it is also possible to arrange many of these operators with the assignment operators, obtaining the following assignment operators: +=, -=, &=, ^=, |= b - 30 fuzzystudio ? 3.0 user manual
it is then possible to define expressions with the following syntax: variable composed_assignement_operator term; that is equivalent to the syntax: variable = variable operator term; library functions in an arithmetic procedure it is possible to use the following library functions: function description parameter bitset(bit, variable); allows to set to 1 the value of a variable bit. bit=0 ? 7 variable * bitreset(bit, variable); allows to set to 0 the value of a variable bit. bit=0 ? 7 variable * bitnot(bit, variable); allows to negate the value of a variable bit. bit=0 ? 7 variable * reset () ; restarts the program * the parameter "variable" is a byte or unsigned variable, visible in the procedure that contains the conditional expression. table 2. asm procedures asm procedures allow to insert sets of assembler instructions in a wcl program. an asm procedure can only be defined in control or folder procedures and cannot contain any type of procedures. local variables declaration in an asm procedure it is possible to use any crisp variable defined at global level, besides particular crisp variables defined at local level and visible only inside that particular procedure. the declaration of the local crisp variables must occur immediately at the beginning of the procedure, according to the sytanx and modality described for the definition of the global crisp variables. in an asm procedure it is possible to use and declare only byte crisp or unsigned variables. however, in and asm procedure it is possible to use, and then declare, only crisp variables of "byte" type, or unsigned. eventual global crisp variables of signed type, or signed, will be be treated as unsigned variables. the maximum number of crisp variables (global +local) allowed depends by the chip selected. it is not possible to declare local variables with the same name as the predefined or global variables. b - 31 appendix b - control language
instructions the set of instructions available in an asm procedure is a subset of the assembler instructions accepted by the selected chip. for further information on the set of assembler instructions available in this procedure refer to the standard library language of the chip chosen. in an asm procedure it is not possible to directly address the registers of the chip, but only use the crisp variables (predefined, global and local) eventually available. any reference to hardware addresses in an assembler instruction must be replaced by one of the crisp variables available. moreover, it is possible to use jump unstructions, provided that these are used only in the same procedure and they refer only to labels defined according to standard modalities . control procedure it is the highest level type of procedure. all the other procedures can be present only inside a procedure of this kind, while a control procedure can only be defined outside any other procedure. each control procedure can allow to define the control flow of one of the procedures that make a wcl program. in fact, a wcl program wiill consists of at least one main control procedure, named main, and eventually, by other control procedures that describe the interrupt routines linked to the different peripherals of the chip selected, if employed by the user. the name of a control prccedure is therefore chosen among a set of predefined names, contained in the standard library language and depending on the particular chip selected. this set will always contain the main name, that indicates the description of the main control flow. local variables declaration currently it is not possible to define any type of local variables inside a control procedure. control flow instructions two instructions for the flow control are supplied: if instruction allows to choose between two different sequences of instructions according to the evalutation of a condition, and is characterised by the following syntax: if condition then instruction; ..... instruction; [ else instruction; ..... instruction;] endif; b - 32 fuzzystudio ? 3.0 user manual
the syntax of the condition is the one described in the apposite paragraph on conditional expressions. inside then and else blocks it is possible to use any instructions allowed in a control procedure. it is then possible to define if instructions variously nested and also other procedures (even if not of they are not control procedures). goto instruction allows to interrupt the sequential execution of the instructions, jumping directly to the instruction indicated. the syntax of a generic goto instruction is the following one: goto label; the label is a name, unique inside the whole wcl program, that indicates the memory location. for the definition of a label refer to the relative paragraph. return instruction allows to interrupt the instructions sequential execution, skipping the procedure that contains it. the syntax is the following: return; computational expressions it is not possible to define logic-arithmetic expressions directly inside a control procedure. b - 33 appendix b - control language
function description parameter deviceset(peripheral, operation, ...); allows to set the peripheral configuration status. the parameter peripheral and "operation" must be chosen among the names available in the standard library language related to the chip selected. irqsetting(external_trig ger_interrupt, interrupt_identifier, ...); enables the management of all the interrupt signals indicated in the argument list (automatically disabling any signal not included in the same list. trigger_external_interrupt, to be chosen among the values supplied by the standard library language, indicates the signal that triggers the external interrupt. the parameters of the type interrupt_identifier are to be chosen among the values available in the standard library language related to the chip selected. irqpriority (interrupt_identifier, ...) ; sets the interrupt signal priority. the parameters of the type interrupt_identifier are to be chosen among the values available in the standard library language related to the chip selected. receive(variable_name,pe ripheral_identifier); stores the current data of the peripheral selected in a variable. the parameter variable_name can refer to any crisp variable (predefined and global) visible in the current context. the parameter peripheral_identifier is to be chosen among the values available in the standard library language related to the chip selected. send( peripheral_identifier, variable_name); sends the values of a variable to the peripheral selected. the parameter peripheral_identifier is to be chosen among the values available in the standard library language related to the chip selected. wait(); interrupts the performing of the programs instructions waiting for one incoming interrupt signals enabled. ta bl e 3 . library functions in a control procedure it is also possible to use the following library functions: b - 34 fuzzystudio ? 3.0 user manual
folder procedures it is a particular version of the control type procedure, that can be contained inside other control or folder procedures. refer to the paragraph relative to control procedure for more information. fuzzy procedures it is a procedure that allows to define a single fuzzy system according to the chip selected. a fuzzy procedure can only be contained inside a control or folder type procedure. the fuzzy procedure consists of two sections set in the following order: fuzzy variable declaration fuzzy rules definition further information is provided in the relatives paragraphs. fuzzy variables declaration in a fuzzy procedure the first step to perform is to declare the fuzzy variables to be used by the its fuzzy rules. the fuzzy variables declaration must occur in a unique block of instructions. these do not follow a particular order but must be necessarily placed at the beginning of the procedure according to the following syntax: begin fuzzyvar variable_name; input (crisp_variable_name); output (crisp_variable_name); storein (number) domain (lower_bound, upper_bound); mbf (membership_name, membership_value); ..... mbf (membership_name, membership_value); end variable_name the single fields of a fuzzy variable must be strictly set in the sequence indicated. it is not necessary to follow any particular order inside the declaration of the fields mbs ( ). the parameter variable_name must have a unique name inside the fuzzy procedure. the parameters lower_bound and upper_bound of the field domain() allow to indicate the universe of discourse bounds of the variable. the indicated values are included in the universe of discourse. the parameter membership_name must have a unique name inside the current variable declara- tion. b - 35 appendix b - control language
the parameter membership_value allows to associate its value to a membership function. the value of an input variable is chosen among the ones defined in the section related to the membership functions definition, included in the section of the global variables declaration, then its nameos of the type mbfxxx. the value of an output variable is a crisp value (signed or unsigned) belonging to the universe of discourse indicated. the keyword input()and output() are mutually exclusive. they identify the type of fuzzy variable. moreover, the field input(), used only for the input variables, indicates the crisp variable necessary to supply the iniatialisation value of the fuzzy variable. the field output(), used only for the output variables, indicates the crisp variable to be initialized with the output variable value at the end of the fuzzy procedure processing. in both cases, the parameter crisp_variable_name can contain onlt the global crisp variable or a predefined variable. when output () keyword, the strein () keyword must also be supplied, the parameter "number" indicates the number of the logic output of the fuzzy computational unit. fuzzy rules definition the main part of a fuzzy procedure is the set of fuzzy rules declared immediately after the fuzzy variables. these do not have a particular order but follow the syntax: if antecedent_list then consequent_list; where: antecedent_list ::= antecedent [fuzzy_operator antecedents_list] antecedent ::= input_variable_name is [not] membership_name and consequent_list ::= consequent [and consequent_list] consequent ::= output_variable_name is output_variable_value the term fuzzy_operator can indicate only one of the following operators: and , or. the terminput_variable_name refers to the name of a fuzzy input variable defined in a procedure, and the term membership_name refers to the name of a membership defined for this variable. the term output_variable_name refers to the name of a fuzzy output variable defined in a procedure, but the term output_variable_value can refer to the name of one of the memberships defined for this variable or directly to a crisp value (signed or unsigned) belonging to the universe of discourse defined for this variable. the maximum number of antecedents and consequents that can be used in a fuzzy rule depends on the chip selected. b - 36 fuzzystudio ? 3.0 user manual
st52x301 standard library the following keys refer to the processors configuration and are used together with the instruction of the type #define keys [value]. processors type: wa rp 3_ tc indicates the st52x301 processor. working frequency key: f re que ncy n = 5/10/20 a/d converter: a dc_ cha n n specifies the number of channel to be converted. n = [ 1 , 4 ] parallel port: p ort _d ir b specifies each pins direction. b = xxxxxxxx x=i input pin x=o output pin timer: t i me r_ pr es n specifies the prescalers value n = [ 0 , 65535 ] t i me r_ wav e n specifies the type of output n = square / pulse t i me r_ po la r n specifies the output polarity n = h / l t i me r_ sta rt _s rc n specifies the start signal source n = int/ext t i me r_ sta rt _de t n specifies the start detection n = lev / edge t i me r_ loa d n specifies the counter data source n = fuzzy0 fuzzy1 register t i me r_ clk n indicates the clocks source n = int / ext t i me r_ in t n indicates the interrupts source n = stop / h / l / hl/none triac driver: t ri ac _p re s n specifies the prescalers value n = [ 0 , 65535 ] t ri ac _m ode n specifies the working modality n=pwm/burst/phase t ri ac _p ol ar n specifies the output polarity n = h /l t ri ac _ load n specifies the counter data source n = fuzzy0 fuzzy1 register t ri ac _i nt n indicates the interrupt source n = h / l / hl /none t ri ac _cl k_ sr c n specifies the clocks source n=int/ext/pow t ri ac _re t ei o_ di r n specifies the reteio pin direction n = i / o b - 37 appendix b - control language
tri ac_p ul se n specifies the triac pulse length n = [ 0 , 32767 ] tri ac_p ow_ fr eq n specifies the power line frequency n = 50 / 60 tri ac_m a sk _t i me n specifies the masking time n = [0 , 6553.7] serial communication interface sc i_ b aud _rat e n specifies speed transmission n = 600 1200 2400 4800 9600 19200 38400 ext sc i_ fr am e _b i ts n specifies the frame bit number n = 8/9 sc i_ pa ri ty p specifies the use of the parity bit p = even/odd/none sc i_ s to p_ bi t s s specifies the use of the stop bits s = 1/2 sc i_ i nt n specifies the possible interrupts source n = tx_empty tx_end rx_full overrun break none peripherals identifier for main procedure instructions ti m er identifies thetimer peripheral tri ac identifies the triac driver peripheral ad c identifies the a/d converter peripheral po rt identifies the parallel port peripheral sc i identifies the serial output pi n identifies the port direction pin b - 38 fuzzystudio ? 3.0 user manual
predefined variables read-only variables: c han 0 identifies the variable in which the value of the a/d 0 channel is stored. c han 1 identifies the variable in which the value of the a/d 1 channel is stored. c han 2 identifies the variable in which the value of the a/d 2 channel is stored. c han 3 identifies the variable in which the value of the a/d 3 channel is stored. t i me r_ stat us identifies the variable in which the timer status is stored. s ci _ stat us identifies the variable in which the sci status is stored. f uz zy 0 identifies the first fuzzy output. f uz zy 1 identifies the second fuzzy output. a dc_ s tatus identifies the variable in which the value of the a/d converter status is stored. write-only variables t ri ac _co unt identifies the variable in which the triac counter value is set. t ri ac _p re s identifies the triac driver prescaler. t i me r_ pr es identifies the timer prescaler. read/write variables t i me r_ coun t identifies the variable in which the timer counter value is writ- ten or read. p ort identifies the variable with the values written/read in the paral- lel port. s ci _ buf fe r identifies the variable with the values written/read in the serial. peripherals configuration variables the peripherals configuration registers can be addressed in the assembler procedures with instructions of the type: ldcf reg_confxx , value where xx is the range [0,15]. moreover, in the assembler blocks, the instruct ions that adress the peripherals registers, can use the predefined variables previously described; more precisely: the instruction ldri can use the following predefined variables: chan0, chan1, chan2, chan3, timer _status, sci_status, fuzzy0, fuzzy1, timer_count, port. the instruction ldpr can use the following predefined variables: triac_count, timer_count, port. b - 39 appendix b - control language
interrupts service routines keywords ti m er identifies the timer interrupt routine. tri ac identifies thetriac driver interrupt routine. ad c identifies the a/d converter interrupt routine. sc i identifies the serial ports interrupt routine. ex t identifies the external interrupt routine. timer status keywords se t verifies if the timer is in set or reset status. sta rt verifies if the timer is in start or stop status. sci status keywords tx _e nd verifies the end of transmission. tx _e m pt y verifies if the transmission bufferhas been emptied. ni nth _b i t returns true if the ninth bit of the frame is 1. ov er run verifies if an overrun error has occurred. rx _f ull verifies if the reception buffer is full. fra m e_ e rror verifies if a frame error has occurred. noi s e _e rro r verifies if an noise error has occurred. b - 40 fuzzystudio ? 3.0 user manual
appendix c - assembler language program memory and registers architecture to program in assembler, it is important to consider the processors architecture, in particular the address space: program memory and registers. program memory the program memory is the eprom memory where the program is stored. this is made up by three main sections with a fixed space: membership functions (mf) data memory from 0 to 191 interrupt vectors from 192 to 201 program space from 202 to 2047 the mf data memory contains the data describing the membership functions in a codified form: 3 bytes per mf that represent respectively the left semi-base, the vertex position in the universe of discourse and the right semi-base. the memory locations about the interrupt vectors are organised in byte couples where the routine service addresses in the program memory are contained. in particular, the locations 192 - 193 contain the start address of the routine service of the interrupt associated to the a/d converter the locations 194 - 195 to the sci interrupt, the locations 196 - 197 to the timer interrupt. the locations 198 - 199 to the triac driver interrupt and the location 200-201 to the external interrupt. the program memory starts at the address 202. it contains all the boolean, arithmetics and fuzzy instructions. the traditional boolean or arithmetic instructions and the ones for the flow control of the program (jump instructions) are separated from the fuzzy instructions by a stop instruction and vice versa. note the fuzzy computation cannot be interrupted, then a fuzzy computation block can be con- sidered as a single assembler instruction. the eventual pending interrupts are served after the stop instruction. register file the register file is a set of 16 registers that can be used either as read and write (addresses 0-15). these are the registers in which you can perform arithmetic and boolean operations. several assembler instructions can address these locations: add additions of the registers. and logic and between two registers. ldrc register loading with a constant. ldri register loading with the content of one input register. ldpr peripheral register loading with a register of the register file. ldrr register loading with another register. sub subtraction between registers. subo subtraction between registers with offset. all 16 registers can be considered general purpose but some of them have a particular use: c - 41
registers from 0 to 3: used as inputs to the fuzzy processing unit. in particular, the registers 0 to 3 are also used by fuzzystudio ? 3.0 as working registers for the execution of the instructions at high level. then these four registers can be used only working directly in assembler, excluding the loading of the inputs to the fuzzy core that is an operation inserted automatically by the compiler in a transparent way for the user. in fuzzystudio ? 3.0 assembler block, these registers must be addressed by using global variables. configuration registers the configuration registers file consists of 16 write only registers (addresses 0-15). these registers have the task to contain the internal peripherals configuration to the processor. it is only possible to load some constants on these registers through the following instructions: ldcf loads a constant on the configuration register specified. irqm determines the interrupts mask: it is equivalent to a ldcf on the register 14. irqp determines the interrupts priority: it is equivalent to a ldcf on the register 15. input registers the input registers file is consists of 11 read-only registers (addresses 0 - 10). these registers allow to read the peripherals values and to check their status. they can be addressable only by means of the instruction ldri that reads the value from the input register specified and loads it on the specified register of the register file. the registers have the following functions: register 0 a/d converter channel 0 converted data. register 1 a/d converter channel 1 converted data. register 2 a/d converter channel 2 converted data. register 3 a/d converter channel 3 converted data. register 4 timer counter value. register 5 timer status register: it gives information about the set/reset (bit 0) and start/stop status (bit 1). register 6 parallel port input data register. register 7 serial input register. register 8 sci status register; gives information about sci. (see data sheet for more information.) register 9 fuzzy output 0 register 10 fuzzy output 1 note in addition, the serial input register must be directly accessed by a srx instruction. use this instruction for a correct execution of the data reading. in an assembler block these register are ad- dressed by means of predefined variables. c - 42 fuzzystudio ? 3.0 user manual
peripherals data registers the data registers file of the peripherals consists of three registers write only (addresses 0 - 2). their function is to write particular data to be used by some of the peripherals. they can be addressed only with the instruction ldpr that transfers the content of the register specified of the register file on the data register of the peripherals specified. their registers are: register 0 timer data counter. register 1 triac data counter. register 2 parallel port output data register. in addition, serial output register can be accessed directly by a stx instruction. the related register is contained inside the peripheral, so it does not belong to this file. note in an assembler block these registers are addressed by means of predefined variables. flags st52x301 core owns two flag bits with four stack levels for the interrupts. this means that both the main program and all the interrupt routines have their own flags. a return from interrupt restores the flags status at the moment of the interrupt request. the flags bit are two: s sign flag: it is set in case of overflow or underflow. z zero flag: it is set when the result of an operation is zero. the instructions that modify the flags are the following ones: add sets the zero flag when you add two registers both containing zero; sets the sign flag when the sum of the two registers is higher than 255: in this case the result is always sum-256. and sets the zero flag when the result of the operation is zero sub sets the zero flag when the result of the operation is zero; sets the sign flag when the value of the destination register is lower than the value of the source register that is the result should be negative: in this case the result of the operation is 256+result. subo like sub but with the adding that in case of overflow both flags are set. this can occur when the destination register is bigger than the source one of at least 128, in fact the instruction subo adds 128 to the result of the subtraction and then the result would be higher than 255. the flags are taken into consideration by the instructions of conditional jump that are: jpz jumps if zero flag is set. jpnz jumps if zero flag is not set. jps jumps if sign flag is set. jpns jumps if sign flag is not set. note in the assembler block jumps are allowed only inside the block. other instructions are de- scribed in the following paragraphs. c - 43 appendix c - assembler language
fuzzy programming in assembler the programming of the fuzzy functionalities in assembler is a complex task. for this reason it is more convenient to perform the programming by using the graphic tools provided by fuzzystu- dio ? 3.0. anyway, this complex task can be performed with the arithmetic/logic assembler programming, by using the fs3asm.exe tool included in the installation directory of fuzzystu- dio ? 3.0 (see appendix d for further information). the fuzzy programming in assembler is divided into two phases: the first to define the mbfs and the second for the rule inference. membership functions definition the assembler instruction to define the membership functions is data. it indicates to the compiler which data have to be loaded on the mbf data memory according to the programmers specifica- tions. the data instruction syntax is the following one (see figure on the left): data var mbf lvd vtx rvd where: var the order number of the variable to which the mbf is associated. mbf the order number of the mbf that you are defining. lvd distance of the left vertex mbf from the central vertex [ from 0 to 255]. vtx position of the central vertex in the universe of discourse [from 0 to 255]. rvd distance of the right vertex mbf from the central vertex [from 0 to 255]. note in case you want to store trapezoidal mbfs to the extremes of the universe of discourse, the value of lvd (if the horizontal side is the left one) or the value of rvd (if the horizontal side is the right one), is 0. the following membership function is stored as third membership function of the second variable with the instruction: data 1 2 0 120 80 the membership functions definition by means of data instructions must end with the instruction stop. c - 44 fuzzystudio ? 3.0 user manual
rule inference the instructions for the rules inferencing are described in the appendix c relative to the structure of the assembler language and to the fuzzy instructions. the fuzzy computation unit is made up by: multiplier block for the a calculation and for the consequent inference. a two-level stack to contain the two operands of a fuzzy operation. temporary buffer to store partial results. computational block for and ( min) and or (max) operations. adder to obtain the partial results of the defuzzification. two registers to hold the partial results of the defuzzification. divider for the defuzzification and the calculation of the output. assembler instructions operate on these devices in the following way: let us suppose you have previously defined the mbf with data instructions, the rule: if inp 0 is not mf 01 and inp 2 is mf 21 or inp 3 is mf 33 then crisp 1 is therefore codified as: ldn 0 1 loads in the stack the not a value relative to the first term of the rule. ldp 2 1 loads in the stack the not a value relative to the second term of the rule. fzand calculates the min between two values in the stack. ldk stores the result of the previous operation in the stack. ldp 3 3 loads in the stack the value of the a relative to the third term of the rule. fzor calculates the max between the two values in the stack. con 58 performs the product between the values calculated and the value crisp 1 = 58 (consequent calculus) the assembler instructions work on these devices in the following way. let us suppose you have previously defined the membership functions with the instruction data , the rule: if (inp2 is mf21 and inp3 is not mf35) or (inp0 is mf03 or inp1 is not mf16) then crisp2 is codified with the following instructions: ldp 2 1 loads in the stack the value of the a relative to the first term of the rule. ldn 35 loads in the stack the not a value relative to the second term of the rule. fzand calculates the min between the two values in the stack. skm stores the calculated value on the temporary register. ldp 0 3 loads in the stack the value of the a relative to the third term of the rule. ldn 1 6 loads in the stack the not a value relative to the fourth term of the rule. c - 45 appendix c - assembler language
fzor calculates the max between the two values in the stack. ldk stores the result of the previous operation in the stack. ldm copies the content of the temporary register in the stack. fzor calculates the max between the two values in the stack con 35 performs the product between the value calculated and the value crisp1=35 (consequent calculus). after the inference of all the rules relative to an output, you can obtain the output through the instruction: out 0 to calculate the first fuzzy output. the fuzzy computation instructions always end with a stop instruction and are preceded by another instruction stop to end the assembler instructions of the alu. the rules that can inferenced in assembler must have a max format of eight antecedent terms and one consequent term. more complex rules can be reduced into equivalent ones with an allowed format. note all rules relative to an output have to be consecutive to calculate the output. c - 46 fuzzystudio ? 3.0 user manual
the structure of a program st52x301 programs in assembler language follow the rigid structure shown below: the easiest program for a chip of w.a.r.p. family consists of a set of arithmetic instructions as the one shown in following list: to the scheme presented above, formed by a single section of arithmetic instructions, you can add other sections to form a structure as the one shown in the first figure. ; ; arithmetic instructions set ; loop: jp loop stop the last two sections in the figure must necessarily be present in couple to follow the scheme, but they can be repeated (or not be present) to the user discretion. data definition interrupt vector definition arithmetic instructions fuzzy instructions arithmetic instructions each section is made up by an assembler code line sequence, with the eventual insertion of blank lines, and is ended by the instruction stop. note the programmer has to make sure that the last arithmetic instruction is the unconditional jump. on the contrary, even if the assembler program is syntactically correct, the chip would con- tinue to execute and sequentially perform the eprom content, with malfunctionment. ............................................... ............................................... arithmetic instructions fuzzy instructions arithmetic instructions ............................................... .............................................. fuzzy instructions arithmetic instructions c - 47 appendix c - assembler language
structure of a generic code line each code line consists of a single instruction followed by the relative topics. the instruction must not necessarily be at the beginning of the line, but it can be preceded by any number of space character. the instruction is separated by its arguments by at least one space character. the arguments are separated among them by at least one space character and optionally, by a " , " character. the tabs characters are considered as space characters. the use of capital or lower case letters is equivalent. comment sequences it is possible to insert comment sequences in the code by inserting a " ; " character before. the comment sequences can be written along the whole line until its end. it is possible to insert only single comment lines or add a sequence of comment at the end of the instruction. line label a line label is a particular characters sequence that allows to univocally determine a code line and then an assembler instruction. a line label must begin with an alphabetic character and can only contain alphanumeric characters. the definition of a line label occurs only when inserting that label at the beginning of the corresponding code line (the new label can be preceded only by space characters) and making it follow by a " : " character the maximum length of a labe is 32 characters. the character " : " does not belong to the labels: it is used only to define a new label, to end the corresponding alphanumeric sequence. furthermore, the character " : " does not carry out as separator and has to be followed by one or more space characters. st52x301 assembler language allows to define line labels only within blocks of arithmetic instructions, that is only to refer to arithmetic instructions. however, it is possible to associate line labels to blank lines containing only comment sequence, but those lines have to be followed by at least one line containing an arithmetic instruction. data definition section it is a section of the program that allows to define the mbfs for the fuzzy variables that will be used in the program. this section is necessary to use the fuzzy part of a chip of w.a.r.p. family. without it fuzzy instructions sections can not be admitted. the instructions allowed within a data definition section are described in the following table: data var mbf lvd vtx rvd var = variable mbf = membership function lvd = left mbf vertex distance vtx = vertex rvd = right mbf vertex distance stores a fuzzy variable mbf, defining vtx, lvd and rvd. stop end of data definition section table 1. data definition instructions c - 48 fuzzystudio ? 3.0 user manual
interrupt vectors definition it is a programs section that allows to define the starting address for the interrupt procedures that will be defined in the program. the interrupt procedures starting addresses are supplied through apposite line labels that identifies the first code line. the programmer is not obliged to define the interrupt procedures for the available signals. it is then possible to omit even the entire interrupt vector definition section. the instructions allowed within the section are described in table 2. arithmetic instructions section it is an executable code section, dedicated to the management of the arithmetic part of the chip (refer to table 3 to 7 for instructions set). in particular, in this type of sections it is possible to manipulate the various registers of the chip (table 3), perform arithmetic and logic operations (table4) and execute the jump instructions (table 5). irq num label num = interrupt signal label = starting address assigns the routine initial address to the corresponding interrupt signal. stop end of interrupt vector definition section table 2. interrupt vector section definition ldcf reg cost reg = configuration register cost = constant value stores a constant value into a configuration register. ldpr dev reg dev = peripheral register reg = register value stores a register file value into a peripheral register. ldrc reg cost reg = register cost = constant value stores a constant value into a register file element. ldri reg input reg = register input = input register stores an input register value into a register file element. ldrr dest src dest = destination register src = source register stores a register file element into a register file element. table 3. registers management c - 49 appendix c - assembler language
the arithmetic instructions sections have to be used to define possible interrupt procedures (refer to instructions in table 6). add reg1 reg2 reg1 = register reg2 = register sum operation reg1 = reg1 + reg2 it sets the sign flag (overflow). it sets the zero flag (null result) and reg1 reg2 reg1 = register reg2 = register logic and operation reg1 = reg1 and reg2 it sets the zero flag (null result) sub reg1 reg2 reg1 = register reg2 = register subtraction operation reg1 = reg1 - reg2 it sets the sign flag (negative result) it sets the zero flag (null result). subo reg1 reg2 reg1 = register reg2 = register subtraction operation with offset reg1 = reg1 - reg2 + 128 it sets the sign flag (negative or overflow result) it sets the zero flag (null or overflow result). table 4. arithmetic logic operations jp lab lab = instruction address label jumps to an instruction. jpns lab lab = instruction address label jumps to an instruction, if the sign flag is not set. jpnz lab lab = instruction address label jumps to an instruction, if the zero flag is not set. jps lab lab = instruction address label jumps to an instruction, if the sign flag is set. jpz lab lab = instruction address label jumps to an instruction, if the zero flag is not set. table 5. jump operations c - 50 fuzzystudio ? 3.0 user manual
irqm mask mask enable interrupt routines enable/disable. irqp priority priority priority code interrupt signal priority setting. mdgi temporarily disables the interrupt signals management. megi reactivates the management of the interrupt signals. reti end of an interrupt routine. rint num num = interrupt signal resets an interrupt signals. udgi temporarily disables the interrupt signals management. uegi reactivates the interrupt signals management. waiti stops the program until the overcoming of an interrupt signal. table 6. interrupt signals management nop null instruction. stop end of an arithmetic instruction section. table 8. srx reg reg = register receives data from the serial and download in a register files register. stx reg reg = register transmitts the register files register content to the serial. table 7. arithmetic instructions for the serial port. if an arithmetic operation generates an overflow, the destination register is set to the result value equal to the result decreased by 256. if an arithmetic operation generates an overflow, the destination register is set to the value 256 decreased by the result. c - 51 appendix c - assembler language
fuzzy instructions section it is an executable code section, dedicated to the management of the fuzzy part of the chip. the fuzzy instructions sections are allowed only with the presence of a data definition section. moreover, each fuzzy section has to be necessarily followed by the arithmetic instructions block (i.e. at least by a jump operation in order to execute properly the program). the instructions allowed within a fuzzy block are listed in table 8. these are instructions aimed at the definition of fuzzy rules set of whose valuation determines the fuzzy output values. in w.a.r.p. family, each fuzzy rule is consists of 2 - 8 antecedents and 1 consequent. each antecedent is the result of the fuzzyfication of the value of one fuzzy variable according to its particular membership, while the consequent is a constant value. the combination of the antece- dents, eventually negated, through fuzzy and/or operations generates a weight to evaluate the consequent. the two available operations, fzand and fzor , work on a stack with two positions that must be previously loaded by the user through the ldn and ldp instructions. being these commutative operations, the loading order of the values on the stack is not relevant. the stack is automatically emptied after the performing of each fuzzy operation. the instructions ldn and ldp provide the loading of the stack with the result of the fuzzyfication of the current value of a fuzzy variable according to a given membership (refer to table 8 for the difference of the two instructions). in particular, the first argument of these instructions indicates either the fuzzy variable in question and the element of the register file in which the user has previously transferred the value of the corresponding input register. c - 52 fuzzystudio ? 3.0 user manual
after the performing of a fuzzy operation, the programmer has to manage the result by means of one of the instructions ldk , skm , con . in particular, the instruction ldk allows to load again the result of a fuzzy operation in the stack, to use it in the following operation, while the instruction skm stores that result in a temporary buffer, from which it could be loaded in the stack by means of the instruction ldm . the instructions skm and ldm implement the equivalent of a couple of brackets, that cannot be however nested. the instruction con associates the result of the last fuzzy instruction to a constant value, using it as a weight to evaluate such value. the instruction out performs the defuzzification of a fuzzy output using the results of all the previous con instructions. con consequent consequent constant it multiplies the result of the last fuzzy operation with the crisp value of the consequent. fzand it implements the fuzzy operation and between the last two values stored in the data stack. fzor it implements the fuzzy operation or between the last two values stored in the data stack. ldk it stores the result of the last fuzzy operation in the data stack ldm it stores the value of temporary buffer in the data stack ldn var mbf var = fuzzy variable mbf = membership function it calculates the not a value (result of fuzzification) of the fuzzy input with the indicated membership function and stores the result in the data stack. ldp var mbf var = fuzzy variable mbf = membership function it calculates the a value (result of fuzzification) of the fuzzy input with the indicated membership function and stores the result in the data stack. skm it stores the result of the last fuzzy operation executed in the temporary buffer. stop end of a fuzzy instruction section. out output output = fuzzy output it performs the defuzzification of a fuzzy output. table 9. fuzzy instructions c - 53 appendix c - assembler language
c - 54 fuzzystudio ? 3.0 user manual
appendix d - fs3asm: assembler programming tool. the file fs3asm.exe, provided in the fuzzystudio ? 3.0 installation directory, is a tool that allows to program st52x301 in assembler. it consists of a text editor for the writing and editing of the assembler program, completed by the assembler to generate the machine code and the commands for the programming of the devices by means of the board linked to the pc through the parallel cable. it is possible to generate the assembler program starting from the beginning or loading a file with the extension .asm generated by fuzzystudio ? 3.0 and modify it. in any case, the original program written with fuzzystudio ? 3.0 will not be changed and will not correspond to the generated code. fs3asm main window this section provides an overview of the major elements of the assembler programming window, such as menus, toolbar and status bar. for additional information, see the index and online help. fs3asm menus file provides standard commands for the management of files, printing and a list of the most recently used files. edit contains standard commands for the editing of the program. view provides commands to show/hide the toolbar and status bar and font settings commands. tools provides commands for the machine code generation and the device programming by means of the programming board. windows contains commands related to windows management. help contains help commands. d - 55
fs3asm toolbar the fs3asm toolbar allows you to perform the most frequently used commands quickly. to execute a task by means of a button, just click the related button on the toolbar. it is possible to display or hide the toolbar by using the apposite command of the view menu. fs3asm status bar the status bar contains information about the current line number, the position of the cursor, the blank check status (enabled/disabled), the caps lock and num lock status. it is possible to display/hide the status bar by using the apposite command from the view menu. new, open, save, print cut, copy, paste assembly, download help d - 56 fuzzystudio ? 3.0 user manual
managing and printing files a new editing page, and then a new program, can be started with the command new (ctrl+n) from the file menu or clicking the apposite toolbar button. as default, the file name is untitledx being x a progressive number according to the already existing files "untitled". the file can be saved by means of the command save (ctrl + s) or, with the possibility to modify its name and location, with the command save as ? the file can be closed with the close command. to open an already existing file use the command open ? (ctrl + o) or the apposite toolbar button. this command allows to open the dialog box for the selection of the file to open. to print the file the following commands are available: the print ? command (ctrl + p) allows you to print the current file. the command print setup ? allows to open a dialog box for the printer setup. print preview allows you to display a program before printing it. the command exit allows you to exit fromfs3asm tool (alt + f4). editing commands fs3asm provides standard editing commands: cut (ctrl + x) removes the currently selected text and places it on the clipboard. copy (ctrl + c) makes a copy of the currently selected text and places the copy on the clipboard. paste (ctrl + v) places a copy of the text currently on the clipboard at the currently selected location. the text remains on the clipboard. delete (del) removes the current selected text. undo (ctrl + z) choose undo from the edit menu to undo the previous editing action. find ? searches a selected text. find next (f3) repeats the last search performed. replace ? allows to search for and replace text items. select all selects every text item included in the document. word wrap wrapping text enables you to see all the text on the line, but it doesnt affect the way text appears when it is printed. it is also possible to set fonts and tabs by selecting the following commands on the view menu: set tab stops ? allows to specify the number of blank characters which form a single tab stop. set font ? allows you to set the fonts. set printer fonts allows to open the dialog box for the printer fonts setting. d - 57 appendix d - fs3asm
machine code generation to generate the machine code relative to the assembler program of the current document, select the command assembly from the tools menu or click the apposite toolbar button. this command opens a dos window in which are shown the programs compilation results. in case of correct compilation a file is generated containing the code in binary format and the following message appears: compiling assembler code ? 0 error(s) 0 warning(0) assembler code compilation done. in case of errors, the list of errors is shown. device programming before programming a st52x301 device, ensure that: the chip is inserted correclty in the socket, the board has been linked to the parallel port and that the power supply is on. remind as well that the program has to be compiled first. it is possible to choose if you want to perform the blank check before the downloading or by selecting blank check on the tools menu. the download command on the tools menu or the equivalent toolbar button launches the programming of the chip. at the end of the downloading the following messages can appear: successfully download the program has been correctly downloaded on the devices memory. error opening file the binary code file has not been found, compile again before downloading. invalid bin file the binary file is corrupt or it is not a file generated by the compiler. error writing memory you tried to unsuccessfully write on the devices memory. the chip could be broken or not well inserted. device not blank in case the blank check is not enabled and the device was not erased before the programming. board not present the board has not been properly connected or the power supply has not been enabled yet. winexec error code windows cannot start the download module. try to close some currently active programs. internal error an internal error occurred, please contact stmicroelectronics - fuzzy logic b.u. d - 58 fuzzystudio ? 3.0 user manual
w3asm error list argument "xxx" is not integer the specified argument "xxx" is not an integer value. only integer values can be used in assembler commands. argument "xxx" out of range the argument "xxx" is out of the allowed range. bad label string "name" the label "name" is not a valid label. it may contain not allowed characters. call to wrong output function internal error: contact stmicroelectronics - fuzzy logic b.u. cannot access an output file the code file cannot be accessed. check the right of the destination directory or if the disk is full. cannot access input file the assembler input file is corrupted or has been deleted or an internal error occurred. cannot access temporary file the temporary file used during code generation cannot be accessed: the disk may be full or the file is read-only or an internal error occurred. cannot open input file "name" the assembler input file "name" is corrupted or has been deleted or an internal error occurred. cannot open output file "name" the code file "name" cannot be opened. check the right of the destination directory or if the disk is full. cannot open temporary output file the temporary file used during code generation cannot be opened: the disk may be full or the file is read only or an internal error occurred. error using input file an error occurred reading assembler source file: it may be corrupted or has been deleted or an internal error occurred. error using output file an error occurred writing the code file: the disk may be full or the file is read only or an internal error occurred. function "name" returned value "value" internal error: contact stmicroelectronics - fuzzy logic b.u. d - 59 appendix d - fs3asm
fuzzy output not computed the fuzzy instruction out is missing for the computation of the output fuzzy variable. illegal label "lab_name" before command "com_name" the label "lab_name" has been specified before irq or data commands or before a fuzzy instruction. delete the label. interrupt number "value" out of range the specified interrupt number is not allowed. specify a value between 0 and 3. interrupt redefined for signal "number the interrupt "number" vector has been already defined. check the interrupt vectors indexes in irq commands. left vertex distance "number" out of range the specified number is not in the range [0 , 255]. line "number" is too long the line number "number" is more than 256 character membership "number" out of range the membership index "number" is not in the range [0 , 15] membership "num_mbf" redefined for variable "num_var" the membership "num_mbf" for variable "num_var" has been already defined. check the mbf indexes in data instructions. misplaced command "name" for adm block the command "name" not belonging to the allowed set for antecedent data setting has been found. check for syntax errors. misplaced command "name" for alu block the command "name" not belonging to the allowed set for alu operations has been found. check for syntax errors. misplaced command "name" for fuzzy block the command "name" not belonging to the allowed set for fuzzy computation has been found. check for syntax errors. misplaced command "name" for irq block the command "name" not belonging to the allowed set for interrupt management has been found. check for syntax errors. missing adm definition. bad fuzzy block fuzzy commands have specified without the definition of antecedent memory data. missing operand(s) for command "name" one or more operands expected for the command "name" were not found. complete the instruction with all the correct operands. d - 60 fuzzystudio ? 3.0 user manual
missing reference for label "name" the label "name" has been used but not referenced inside the program. check for syntax errors. no more memory available there is no enough memory to run assembler. try closing some open programs. not enough fuzzy operands and/or operator have been used loading only one value in the stack. out of chip code space the generated program is longer than the available chip memory space. try optimising the program. pending operands into fuzzy core a value, previously loaded in the buffer with skm instruction, has been left without using it. redefinition for label "name" the label "name" has been previously defined in the program. right vertex distance "number" out of range the specified number is not in the range [0 , 255] temporary fuzzy core buffer is empty a ldm instruction has been specified without using skm instruction before. temporary fuzzy core buffer is not empty a skm instruction has been specified twice without using a ldm instruction between for using the previously loaded value. temporary fuzzy core stack is empty con or ldk or skm instruction has been specified with the stack empty. too many fuzzy antecedents too many antecedents term (more than 8) have been included in rule processing. too many fuzzy operands too many operands have been specified in instructions for rule processing. too many operands for command "name" more than the expected operands were found with command "name". check the correctness of the instruction deleting unnecessary operands. variable "number" out of range the variable index "number" is not in the range [0 , 3] vertex "number" out of range the specified number is not in the range [0 , 255] d - 61 appendix d - fs3asm
undefined label "name" the label "name" is used but not defined. check for syntax errors. unexpected end of source the source code ended in a not correct way. check if the source file is corrupted or for syntax errors. unrecognised command "name" the specified command "name" is not a valid command. check for syntax errors. unsupported function "name" for command "command" internal error: contact stmicroelectronics - fuzzy logic b.u. d - 62 fuzzystudio ? 3.0 user manual
appendix e full - fuzzy logic language full (fuzzy logic language) is a programming language oriented to the definition of fuzzy control systems. a full program is composed by two fundamental parts: the declarations part to define the fuzzy variables term set, and the procedural part to define fuzzy control rules. < full program > ::= . in order to define the term set, the language allows the following actions: associates a label to an universe of discourse; defines templates for the membership functions; defines modifiers for the membership functions by using expressions; defines a variable specifying the name, the associated universe and the membership functions composing the term set. the set of the rules, having format if ... then ..., defines the knowledge base to determinate the values of output variables starting from the input variables values. the antecedent part of the rules consists in a logic expression of fuzzy operators and, or and not. the expression terms are the logic premise. each premise is defined by an is relation between a variable and one of its membership function eventually modified. the consequent part of the rules is a linguistic ex- pression composed by consequence joint by the connective and. a consequence is defined by an is relation between a variable and one of its membership functions. full language elements token tokens are elements of source program that are not further reduced by compiler in its components. in full language, tokens are classified in the following categories: white space; punctuation; operators; keywords; identifiers; real values and constants. e-63
white space white space characters are introduced in the program text in order to improve the readability. during the parsing of the program, the compiler ignores the white spaces. the recognized white spaces are: space tab (escape \t) carriage-return (escape \r) linefeed (escape \n) newline (escape \r\n) vertical tab (escape \v) formfeed (escape \f) comments a comment is a sequence closed between double quote () containing whatever combination of characters except the double quote itself. a comment can be inserted anywhere in the source program and the compiler considers it as a white space. punctuation the punctuation characters in full are used mainly to organize the program text. actually they dont specify any operation with the language elements. the punctuation characters are the following: ;._[] {}(). some punctuation characters are operator symbols too. operators operators are symbols that specify the operation to execute with the program objects. in the following, the full operators are listed, sorting them according to the priority. (alt+<0163> character) definition of independent variable; [] indexing of membership functions; () changing of priority in mathematical expressions; +- unary sign operator; %^ module and power operators; */ multplicative operators; +- additive operators; @ entry point; , sequencer; = definition operator. all the operators are left associative. e-64 fuzzystudio ? 3.0 user manual
keywords keywords assume a particular meaning in full language and, for this reason, the compiler manages them differently from the other words. the list of reserved full keywords is the following: and if or times at is points universes begin lambda polyline variables continue less rename very end modifiers shapes with for not then identifiers identifiers are names assigned to universes, modifiers, forms, variables and terms in a fullpro- gram. it is not possible to use reserved keywords as identifiers. after being declared, the identifier can be used in the program text as the object that it represents. the full language puts some limitations on the words used as identifiers. an identifier must start with a letter (upper or lower case) and it can be composed by letters, digits and underscores ( _ ). upper and lower case letters are considered different. in the following, the identifiers grammar is shown: ::= | . ::= | | | . ::= | _. with we intend one of the following: a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z. with we intend one of following: 0 1 2 3 4 5 6 7 8 9. e-65 appendix e - full
constants a constant in full is a decimal number with a sign. the constant is composed by an integer part, a decimal part and an exponent. the limits of the constant values depends on implementation. in any case, the full compiler considers as equal constant values having the same first 9 significative digits. in the following, the constants grammar is shown: ::= | . ::= | . ::= + | -. ::= | . ::= . | . ::= | . ::= e | e . without explicit indication of sign, the positive sign is assumed by default. expressions an expression is a sequence of operands and operators. an operand is the object managed by the operator. operands in full are identifiers, constants, mathematical functions or expressions between parenthesis. expressions are used in full to define modifiers and terms (membership functions) with continuous functions. both modifiers and terms are real functions of a real variable. the full language asks the definition of an identifier for the real variable of the function dominion (independent variable). the identifier for the independent variable is declared with the operator or lambda. the identifier is valid only in the expression defining the function and it is no longer valid after the end of expression. in the following, the function grammar is shown: ::= . . ::= | lambda . ::= . the operators priority rules (see "operators" paragraph) are used for the evaluations of the expression together to the left associativity. e-66 fuzzystudio ? 3.0 user manual
::= | . ::= | . ::= | + | - | . ::= | | ( ). ::= ( ). with we intend one of following operations: + sum operation; - subtraction operation. with we intend one of following operations: * multiplication operation ; / division operation; % module operation; ^ power operation. is one of the following symbols of mathematical function: abs absolute value of a real number; acos arcos of a real number in the interval [-1,1]; asin arcsin of a real number in the interval [-1,1]; atan arctan of a real number; cos cosine of a real number; cosh hyperbolic cosine of a real number; exp exponential function; log natural logarithm of a positive real number; log10 decimal logarithm of a positive real number; round real number rounding; sin sine of a real number; sinh hyperbolic sine of a real number; sqrt square root of a not negative real number; tan tangent of a real number; tanh hyperbolic tangent of a real number; the function symbols are not reserved words of the language. e-67 appendix e - full
declarations a declaration specifies the interpretation to be given to an identifier. the objects in full that can have a name are the universes of discourse, modifiers, forms, variables and membership functions. for this reason the declarations are divided in sessions called paragraph. each paragraph starts with a keyword that indicates the kind of objects to be defined and ends with the start keyword of another paragraph or with the begin keyword that indicates the start of the rule list. paragraphs can have any order. a paragraph can appear more than once in the paragraph list. after the declaration, the introduced identifier is valid in the whole source program but the use is restricted to the syntactical and semantical rules of full language. ::= | . ::= | | | . universes the universes paragraph starts with the keyword universes. it is possible to define whatever number of universes inside the paragraph. a universes declaration consists in the definition of a label for a real number interval. ::= universes . ::= | . ::= = ;. ::= [ , ]. the first constant in the interval definition must be lower than the second one. the universe identifiers can be used anywhere a universe of discourse specification is requested. e-68 fuzzystudio ? 3.0 user manual
modifiers the modifiers paragraph is introduced by modifier keyword. it is possible to define whatever number of modifiers inside the paragraph. a modifier declaration defines an association between an identifier and a real function of a real variable. this variable, called independent variable, assumes values in the interval [0,1]. the modifier function must assume values in interval [0,1]. during compilation, values external to the interval [0,1] will be cut to the interval extremes. the independent variable identifier is introduced with the notation or with the keyword lambda (see "expressions" paragraph). ::= modifiers . ::= | . ::= = ;. full supplies three already defined modifiers: not, very e less defined as: not = x . 1-x; very = x . x^2; less = x . sqrt(x); it is possible to define again each modifier inside the program. a modifier can be applied to variable terms specifying the modifier name. a modifier works in different ways if it is used during a variable definition (see "variables" paragraph) or if it is applied in a rule (see "rules" paragraph). e-69 appendix e - full
shapes the shapes paragraph is introduced by the keyword sha pes. it is possible to def ine inside the paragraph any number of shapes. a shape declaration defines a link between an identifier and a normalized shape for a membership function. the shape is defined in a normalized universe of discourse, that is in the interval [0,1]. each normalized shape has an entry point associated, that is a point in the interval [0,1] where the normalized shape is defined that represents the shape itself. when the shape is fixed into the universe of discourse of the variable and it becomes a membership function, the entry point is used to give a position to the membership function so created (see "variables" paragraph). as a default the entry point value is 0. ::= shapes . ::=
| . ::= = ; | =;. ::= @ . full supplies three different ways to define shapes (membership function in the normalized universe of discourse): by using points, multi-line, and continue. ::= | | . using the definition by points (keyword points), the membership function is defined by a list of couples of values. the first value represents a value in the universe of discourse. the second value represents the belief value of the membership function in the point of the universe of discourse specified with the first value of the couple. a belief value is a value in the interval [0,1]. the couples list must be sorted considering first the lower values of the universe of discourse. ::= points { }. ::= , | . ::= / . ::= . using the multi-line definition (keyword polyline), the membership functions defined by a list of couples of values that specifies the segments extremes of the polyline representing the member- ship function. each couple, with the exception of the first and the last one, defines the end of the previous segment and the start of the following one. the couples list must be sorted considering first the lower values of the universe of discourse. ::= polyline { }. e-70 fuzzystudio ? 3.0 user manual
in order to define continuous shapes (keyword continue), the membership function must be defined using a list of stroke. a stroke is a couple composed by an interval of the universe of discourse and a function of the independent variable. the identifier of the independent is specified just after the keyword continue and it is valid just for the definition of the membership function. the rules of this kind of definition are the following: the function is considered zero where it is not specified; negative function values are converted to zero; function values higher than 1 are converted to 1; if a is the first interval bound and b is the second one, then it must be b 3 a; if ii and ii+1 are two consecutive intervals, then it must be sup{ii} inf{ii+1 }; if ii and ii+1 are two consecutive intervals and max{ii} = min{ii+1 } then it must be verified that fi (max{ii}) = fi (min{ii+1 }). the compiler does not compute the function and issues a warning message. ::= continue { }. ::= , | . ::= . . ::= | | | . ::= ( , ). ::= ( , ]. ::= [ , ). e-71 appendix e - full
variables the variables paragraph is introduced by the keyword variables. inside the paragraph, it is possible to define whatever number of variables. a variable declaration defines a link between a variable identifier and a term set. a term set is a set of membership functions defined on a universe of discourse. if not specified, the universe is the normalized one (that is an universe in [0,1] interval). ::= variables . ::= | . ::= = . ; | = ;. ::= | . ::= { }. ::= , | . an identifier and its definition must be supplied for each membership function belonging to the term set. the membership functions identifiers are valid only inside the term set definition. in other words, a membership function belonging to a term set can be accessed only by the variable identifier. a membership function in a term set can be defined directly inside the term set. in this case, the same rules of shape definition (see "shapes" paragraph) are valid. otherwise, it is possible to fix shapes or to modify already defined membership functions. ::= = ;. ::= | | | . to fix a shape it is necessary to supply three parameters: the shape name, the position, in the universe of discourse of the variable, of the shapes entry point and the shapes width. the shapes width indicates a scale factor that allows to map the normalized universe to the universe of the discourse of the variable. ::= ( , ). ::= . ::= . e-72 fuzzystudio ? 3.0 user manual
it is possible to define membership functions using modifier with fixed shapes or with already defined membership functions in the term set. the modifiers can be used in cascade. ::= | . ::= | . ::= | | . ::= [ ]. ::= . ::= | not | very | less. the repetition of shape fixing can be realized using for ... times ... at. in this way a membership function vector can be declared defining: the vector dimension, that is the number of repetitions of shape fixing; the fixing of the first element of the vector; the distance between the entry points of the following shapes. the compiler issues an error message if the entry point positions so computed are out of the universe of discourse boundaries. using the rename construct it is possible to rename the membership functions of the vector. this construct accepts a list of identifiers. the association between the membership functions of the vector and the identifiers is done by the position of the identifier in the list. if a membership function has not to be renamed, the character _ (underscore) can be used. it is not necessary that the identifier list has the same length of the vector: the exceeding identifiers are ignored. the not renamed membership functions can be accessed indexing the vector name. the vector option base is 1. ::= for times at [ rename ]. ::= . ::= | . ::= . ::= , | . ::= | _. e-73 appendix e - full
rules the procedural part of full language starts with the keyword begin and ends with the keyword end. the keyword end closes also the source fullprogram. the procedural part is composed by a set of rules. a weight can be associated to each rule using the with construct. as a default, the weight associated is 1. to increase the importance of a rule, the weight associated to the rule must be higher than 1; otherwise, to decrease the importance of the rule, the weight must be lower than 1. ::= begin end. ::= | . ::= [ with ] ; | . ::= . a rule is an inference of the kind if ... then ... composed by an antecedent part and a consequent part. ::= if then . the antecedent part is a logic expression that uses the fuzzy logic operators and & or. in fuzzy logic expressions, and operator has higher priority than or operator. the use of parenthesis can alter the order in which the operators are evaluated. ::= or | . ::= and | . ::= ()| . the consequent part contains a list of consequences of the inference, grouped with the and connector. the and connector has only a syntactical role and a totally different meaning of the and fuzzy logic operator. ::= and | . e-74 fuzzystudio ? 3.0 user manual
premises and consequences are unary predicates of the kind m(x) where m is a membership function defined in the universe of discourse of the variable x. in order to define this kind of predicates, full supplies the syntactical connective is. so the unary predicate can be syntactically described as x is m. as a consequence, m can be substituted by a membership function name, by an element of a membership functions vector, or by a crisp value in the universe of discourse of variables x. ::= is . ::= | | . in a premise, m can be substituted by a membership function name, by an element of a membership functions vector, or a modified membership function of the variable x. ::= is . ::= | | . in full a consequence can be considered as a premise of another rule. in such a case, the rule interpretation assigns to the premise p an a value equal to the max j value of the rules having p as consequence. e-75 appendix e - full
full program example in this paragraph, all the functionalities given by full language are described by means of an example program. this program has not a particular semantic, except the necessary one to explain the language. the first three shapes are defined: the building of variables term sets is based on them. the first shape is a triangle having the vertex with max belief in the center of normalized universe; the vertex is also the entry point of the shape. the second shape is a crisp value in the middle of the normalized universe. the third is a parabola equation having vertex with max belief in the middle of the normalized universe a minimum belief in the universe extremes. shapes triangle = polyline {0/0, 0.5/1, 1/0} @ 0.5; crisp = points {0.5/1} @ 0.5; parabola = continue x { [0,1]. -4*(x^2) + 4*x }; in addition, a modifier that transforms the triangular membership functions in gaussian membership functions is defined. the equation for the modifier is obtained making repeated modifications to the triangle corresponding to not very not very triangle. modifiers gauss = lambda y . 1-(1-y^2)(1-y^2); the control to be defined uses three variables: temperature, pressure and out. after defining the universes, the term set declaration must be done. the variable temperature, defined in the universe degrees, has a term set composed by 5 membership functions. the membership functions verylow and veryhigh are defined directly inside the term set definition as polyline. they are triangles in the extremes of the universe of discourse. the other membership functions are defined using a multiple fixing of the shape triangle. the first element of the vector middle has the vertex, that is the entry point of the triangle shape, in the position 25 of the universe degrees and the base of triangle width equal to 50. the second and the third element of the vector have vertex respectively in 50 and 75. the variable pressure, defined in the universe atmosphere, has a term set having three membership functions. the membership function low and high are gaussians obtained with the modifier gauss of the shape triangle. notice that the vertex of low and high are on the extreme of the universe. the membership functions medium is a fixing of the shape parabola with the vertex in the position 10 in the universe of discourse atmosphere. the variable out has a term set composed by a vector of 10 fixing of the shape crisp. e-76 fuzzystudio ? 3.0 user manual
universes degrees= [0,100]; atmosphere = [1, 20]; variables temperature = degrees . { verylow = polyline { 0/1, 25/0 }; veryhigh = polyline { 75/0, 100/1 }; middle = for 3 times triangle(25,50) at 25 rename low, medium, high; } pressure = atmosphere . { low = gauss triangle(0,20); medium = parabola(0,20); high = gauss triangle(20,20); } out = [1,10] . { out = for 10 times crisp(1,2) at 1 rename off; } begin if temperature is verylow then out is off with 2; if temperature is very low and (pressure is low or pressure is medium) then out is out[1] and out is out[2]; if temperature is not verylow and out is off then out is 3.5; end in the following 3 rules, defined on the declared variables, are showed. e-77 appendix e - full
full language grammar in the following the whole full grammar is showed. ::= . ::= | . ::= | | | . ::= universes . ::= | . ::= = ;. ::= [ , ]. ::= modifiers . ::= | . ::= = ;. ::= shapes . ::= | . ::= = ; | = ;. ::= @ . ::= | | . ::= points { }. ::= , | . ::= / . ::= . ::= polyline { }. ::= continue {}. ::= , | . ::= . . e-78 fuzzystudio ? 3.0 user manual
::= | | | . ::= ( , ). ::= ( , ]. ::= [ , ). ::= variables . ::= | . ::= = . ;| = ;. ::= | . ::= { }. ::= , | . ::= = ;. ::= | | | . ::=(,). ::= . ::= . ::= . ::= | . ::= | . ::= | | not | very | less. ::= [ ]. ::= . ::= for times at [ rename ]. ::= . e-79 appendix e - full
::= | . ::= . ::= , | . ::= | _. ::= begin end. ::= | . ::= [ with ] ;| . ::= . ::= if then . ::= and | . ::= is . ::= | | . ::= or | . ::= and | . ::= ()| . ::= is . ::= | | . ::= . . ::= | lambda . ::= . ::= | . ::= | . e-80 fuzzystudio ? 3.0 user manual
::= | + | - | . ::= | | ( ). ::= ( ). ::= | . ::= | | | . ::= | _. ::= | . ::= | . ::= + | -. ::= | . ::= . | . ::= | . ::= e | e . e-81 appendix e - full
" full source from sample project by fuzzy studio 2.0 " variables distance = [0,100] .{ medium = polyline {24.7058824/0, 49.8039216/1, 75.2941176/0}; low = polyline {0/1, 24.7058824/1, 49.8039216/0}; high = polyline {49.8039216/0, 75.2941176/1, 100/1}; }; speed = [0,250] .{ medium = polyline {61.7647059/0, 124.509804/1, 188.235294/0}; low = polyline {0/1, 0.980392157/1, 123.529412/0}; high = polyline {124.509804/0, 249.019608/1, 250/1}; }; brakes_power = [0,8] .{ one = points {1.03529412/1}; two = points {2.00784314/1}; five = points {5.05098039/1}; four = points {4.01568627/1}; three = points {3.01176471/1}; six = points {6.02352941/1}; seven = points {7.09019608/1}; eight = points {8/1}; zero = points {0/1}; }; begin "9 rules defined" if distance is low and speed is high then brakes_power is eight ; if distance is low and speed is medium then brakes_power is four ; if distance is low and speed is low then brakes_power is two ; if distance is medium and speed is low then brakes_power is 1 ; if distance is medium and speed is medium then brakes_power is 4 ; if distance is medium and speed is high then brakes_power is six ; if distance is high and speed is low then brakes_power is zero ; if distance is high and speed is medium then brakes_power is two ; if distance is high and speed is high then brakes_power is four; end e-82 fuzzystudio ? 3.0 user manual
full product information at http://www.st.com information furnished is believed to be accurate and reliable. however, stmicroelectronics assumes no responsib ility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. no license is granted by implication or otherwise under any patent or patent rights of stmicroelectronics. specification mentioned in this publicatio n are subject to change without notice. this publication supersedes and replaces all information previously supplied. stmicroelectronics product s are not authorized for use as critical components in life support devices or systems without express written approval of stmicroelectro nics. the st logo is a registered trademark of stmicroelectronics ? 1998 stmicroelectronics C printed in italy C all rights reserved fuzzystudio ? is a registered trademark of stmicroelectronics dualogic ? is a trademark of stmicroelectronics ms-dos ? , microsoft ? and microsoft windows ? are registered trademarks of microsoft corporation. matlab ? is a registered trademark of mathworks inc. stmicroelectronics group of companies australia - brazil - canada - china - france - germany - italy - japan - korea - malaysia - malta - mexico - morocco - the neth erlands - singapore - spain - sweden - switzerland - taiwan - thailand - united kingdom - u.s.a.


▲Up To Search▲   

 
Price & Availability of STFLSTUDIO3UM

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X