projects:mmt4ue2:mmtquellcode0
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| projects:mmt4ue2:mmtquellcode0 [2014-11-07 12:01] – mka | projects:mmt4ue2:mmtquellcode0 [2014-11-19 08:45] (aktuell) – mka | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | Ist noch im Arbeit. Aber schau es dir mal an... | + | \ MMT Source Code of Version 1.0 |
| - | Work in progress. But take a look… | + | |
| - | + | ||
| - | \ v11-2014-11-06 | + | |
| | | ||
| - | \ swk4 "swiss knife" 4bit I/O | + | : .MMT# \ -- |
| - | \ using 4e4th Release0.34 on TI MSP430G2553 MCU LaunchPad | + | ." |
| + | |||
| + | \ ---------------------------------------------------------- | ||
| + | \ Mini Multi Tool | ||
| + | \ using 4e4th Release 0.34 on TI MSP430G2553 MCU LaunchPad | ||
| \ started: mka, 2014_10_26 | \ started: mka, 2014_10_26 | ||
| - | \ Idea: Juergen Pintaske | + | \ Idea: Juergen Pintaske |
| | | ||
| + | \ " | ||
| + | \ and have something running immediately in Forth. | ||
| + | \ Even without understanding it in the beginning. | ||
| + | \ This was our starting point for MMT." (JP) | ||
| | | ||
| + | \ ---------------------------------------------------------- | ||
| + | \ Table of Contents | ||
| + | \ Defining the I/O for this application, | ||
| + | \ Device Pinout: MSP430G2553 20-Pin PDIP | ||
| + | \ Some scratch variables | ||
| + | \ Juggling nibbles for packing and unpacking into 16 bit | ||
| + | \ I/O initialisation, | ||
| + | \ Utilities for this MCU | ||
| + | \ Square wave at P1.5 (Pin7) using timer TA0.0 | ||
| + | \ Midi tones B3 to B5, 2 octaves; pitch list, play a note | ||
| + | \ PWM of 16KHz for 8MHZ DCO using timer TA0 | ||
| + | \ ADC - init ADC0 and ADC4, get ADC value | ||
| + | \ Servos - position 4 servos using digital OUT, double function | ||
| + | \ Initialisation of MMT4 | ||
| + | \ Example Programs - using switches only | ||
| + | \ EX0 - Leave demo loop, run Forth | ||
| + | \ EX1 - Display IN at OUT | ||
| + | \ EX2 - Display IN at OUT, set PWM-LED too | ||
| + | \ EX3 - Falling edge detector (1) | ||
| + | \ EX4 - Falling edge detector with tone (2) | ||
| + | \ EX5 - Dance of 4 servos (test servos) | ||
| + | \ EX6 - Servo follows analog input on pin ADC4 | ||
| + | \ EX7 - Get analog input from ADC channel 4 | ||
| + | \ EX8 - Audio visual display of ADC4 value | ||
| + | \ EX9 - Play demo song | ||
| + | \ DEMOLOOP - Select an example programm by its nummber. | ||
| + | \ More Example Programs - using serial interface to PC. | ||
| + | \ EX11 - Echo any key | ||
| + | \ EX12 - Toggle OUT bits manually | ||
| | | ||
| - | \ History: | + | |
| - | \ renamed | + | |
| - | \ added: DEMOLOOP to select examples | + | |
| - | \ cleaning | + | |
| - | \ added: 2 servo examples | + | |
| - | \ added: 4 servo pulses | + | \ 20141117: We are ready for a release - V10 |
| - | \ renamed | + | \ Added help lines to PC examples. |
| - | \ added: | + | \ Made MMT4 images. |
| - | \ added: ADC (29.10.2014 00:02) | + | \ Split examples in MMT and PC part. |
| - | \ first test today (26.10.2014 23:49) | + | \ 20141109: Made duration of notes selectable. |
| + | \ Use TONE@ TON+ now instead of NOTE in soem EXs. | ||
| + | \ Better EX8, wait after output, not before. | ||
| + | \ Better visualisation of EX3 and EX4, LEDs switch. | ||
| + | \ Better EX2, no delay any more. | ||
| + | \ Renamed file to mmt4ue2.4th because this name was unique | ||
| + | \ while "swiss knife" and its abreviations are not. | ||
| + | \ Renamed | ||
| + | \ Added: DEMOLOOP to select examples | ||
| + | \ 20141103: Cleaning | ||
| + | \ 20141102: Added 2 servo examples. | ||
| + | \ 20141030: Added pulses for 4 servos | ||
| + | \ 20141029: Renamed | ||
| + | \ Made some demos Pn. | ||
| + | \ Added: ADC | ||
| + | \ 20141026: First test today. | ||
| \ | \ | ||
| \ | \ | ||
| - | | + | \ ... functioning, |
| \ | \ | ||
| \ PWM running, SWEEP is ok. | \ PWM running, SWEEP is ok. | ||
| \ I/O and nibbels working on variables. | \ I/O and nibbels working on variables. | ||
| - | \ mem u. 6703 (plenty flash left) | ||
| | | ||
| \ Issues: | \ Issues: | ||
| - | \ Glitches while setting upper nibble of P2 - fixed OUT! | + | \ Glitches while setting upper nibble of P2 - fixed OUT! . |
| - | \ port name P2 is in conflict with modul name P2 - renamed. | + | \ port name P2 is in conflict with example |
| - | + | \ renamed | |
| - | \ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | + | |
| - | \ Start of Program | + | |
| + | |||
| + | \ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| + | \ Start of Program | ||
| + | \ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| | | ||
| - | \ This program | + | \ This program |
| + | | ||
| \ And we use them here as an example of how to program the | \ And we use them here as an example of how to program the | ||
| - | \ MSP430 Controller. | + | \ MSP430 Controller |
| - | \ Add the 5 resistor LED cominations | + | \ Add the 5 resistor LED combinations |
| - | \ 3 switches to 430 board and run routines completely | + | \ 3 switches to the 430 board or any type of breadboard |
| - | \ in the MSP430, using Forth | + | \ and run routines completely in the MSP430, |
| + | \ using this program running on top of Forth | ||
| + | \ either interfaced to a PC or some parts independent of the PC | ||
| | | ||
| | | ||
| Zeile 50: | Zeile 105: | ||
| \ (TOP VIEW) | \ (TOP VIEW) | ||
| | | ||
| - | \ VCC-----------------[01 | + | \ VCC-----------------[01 |
| \ (LED1 LP) AD0 P1.0--[02 | \ (LED1 LP) AD0 P1.0--[02 | ||
| \ RXD-----------P1.1--[03 | \ RXD-----------P1.1--[03 | ||
| Zeile 56: | Zeile 111: | ||
| \ -----------S2 P1.3--[05 | \ -----------S2 P1.3--[05 | ||
| \ ..........AD4 P1.4--[06 | \ ..........AD4 P1.4--[06 | ||
| - | \ _-_-_-_-_-FRQ P1.5--[07 | + | \ _-_-_-_-_-FRQ P1.5--[07 |
| \ ----------IN0 P2.0--[08 | \ ----------IN0 P2.0--[08 | ||
| \ ----------IN1 P2.1--[09 | \ ----------IN1 P2.1--[09 | ||
| Zeile 67: | Zeile 122: | ||
| \ P1.2 TX are used as the serial interface to the PC | \ P1.2 TX are used as the serial interface to the PC | ||
| \ P1.3 used as S2 as on the TI Launchpad, | \ P1.3 used as S2 as on the TI Launchpad, | ||
| - | \ internal resistor enabled | + | \ internal |
| \ P1.4 used as Input, later on as Analog Input 2 | \ P1.4 used as Input, later on as Analog Input 2 | ||
| - | \ P1.5 used as Output, | + | \ P1.5 used as Output, later on to output |
| - | \ | + | \ one of 16 frequencies |
| - | \ P1.6 Outout, later on as Pulse Width Modulation output | + | \ P1.6 Output, later on as Pulse Width Modulation output |
| - | \ | + | \ |
| - | \ P1.7 Input S3, internal resistor enabled | + | \ P1.7 Input S3, internal |
| | | ||
| \ All P2.x Inputs have internal resistor enabled, | \ All P2.x Inputs have internal resistor enabled, | ||
| - | \ so open input means HIGH | + | \ so open input means HIGH signal |
| \ P2.0 Input 0 | \ P2.0 Input 0 | ||
| \ P2.1 Input 1 | \ P2.1 Input 1 | ||
| Zeile 86: | Zeile 141: | ||
| \ P2.6 Output 2 | \ P2.6 Output 2 | ||
| \ P2.7 Output 3 | \ P2.7 Output 3 | ||
| + | | ||
| + | \ Yes, we downgraded from 16 bit to 4 bit IO - but the pin | ||
| + | \ numbers were limited, and if you add a PC via USBtoTTL3.3V | ||
| + | | ||
| | | ||
| | | ||
| | | ||
| \ The MSP 430 will be rather fully used. | \ The MSP 430 will be rather fully used. | ||
| - | \ So to save Program Space, the 4 Bit Nibbles are packaged | + | \ So to save Program Space, the 4 Bit Nibbles are packed |
| \ into 4x4 nibbles to be one Variable (16Bit cell). | \ into 4x4 nibbles to be one Variable (16Bit cell). | ||
| \ This will save on RAM used. | \ This will save on RAM used. | ||
| | | ||
| - | \ Some scrach | + | |
| + | |||
| + | \ Source code start ---------------------------------------- | ||
| + | | ||
| \ IN 4 bit input, when used reflects status of 4 Input lines | \ IN 4 bit input, when used reflects status of 4 Input lines | ||
| \ F 4 bit value for tones | \ F 4 bit value for tones | ||
| \ A 4 bit A register | \ A 4 bit A register | ||
| \ B 4 bit B register | \ B 4 bit B register | ||
| - | variable IFAB | + | variable IFAB \ define |
| | | ||
| \ W 4 bit W variable | \ W 4 bit W variable | ||
| Zeile 105: | Zeile 167: | ||
| \ Y 4 bit Y variable | \ Y 4 bit Y variable | ||
| \ Z 4 bit Z variable | \ Z 4 bit Z variable | ||
| - | variable WXYZ | + | variable WXYZ |
| | | ||
| \ A1 4 bit analog in channel 1 | \ A1 4 bit analog in channel 1 | ||
| Zeile 111: | Zeile 173: | ||
| \ P 4 bit pulse width modulated output | \ P 4 bit pulse width modulated output | ||
| \ O 4 bit output register | \ O 4 bit output register | ||
| - | variable 12PO | + | variable 12PO |
| | | ||
| - | : INITSV \ -- \ init scrach | + | : INITSV \ -- \ init these 3 scratch |
| - | 0 IFAB ! 0 WXYZ ! 0 12PO ! ; | + | 0 IFAB ! 0 WXYZ ! 0 12PO ! ; |
| - | initsv | + | initsv |
| | | ||
| \ define a Word to show a cell at address unsigned | \ define a Word to show a cell at address unsigned | ||
| Zeile 122: | Zeile 184: | ||
| | | ||
| | | ||
| - | \ juggling nibbles | + | \ juggling nibbles |
| HEX | HEX | ||
| - | : 0! \ n adr -- \ store nibble 0 to variable at address | + | : n0! \ n adr -- \ store nibble 0 to variable at address |
| >r r@ @ FFF0 and swap F and + r> ! ; | >r r@ @ FFF0 and swap F and + r> ! ; | ||
| - | : 1! \ n adr -- \ store nibble 1 to variable at address | + | |
| + | | ||
| >r r@ @ FF0F and swap F and 4 lshift + r> ! ; | >r r@ @ FF0F and swap F and 4 lshift + r> ! ; | ||
| - | : 2! \ n adr -- \ store nibble 2 to variable at address | + | |
| + | | ||
| >r r@ @ F0FF and swap F and 8 lshift + r> ! ; | >r r@ @ F0FF and swap F and 8 lshift + r> ! ; | ||
| - | : 3! \ n adr -- \ store nibble 3 to variable at address | + | |
| + | | ||
| >r r@ @ 0FFF and swap F and C lshift + r> ! ; | >r r@ @ 0FFF and swap F and C lshift + r> ! ; | ||
| | | ||
| - | : 0@ \ adr - n \ fetch nibble 0 of variable at address | + | : n0@ \ adr - n \ fetch nibble 0 of variable at address |
| @ 000F and ; | @ 000F and ; | ||
| - | : 1@ \ adr - n \ fetch nibble 1 of variable at address | + | |
| + | | ||
| @ 00F0 and 0004 rshift ; | @ 00F0 and 0004 rshift ; | ||
| - | : 2@ \ adr - n \ fetch nibble 2 of variable at address | + | |
| + | | ||
| @ 0F00 and 0008 rshift ; | @ 0F00 and 0008 rshift ; | ||
| - | : 3@ \ adr - n \ fetch nibble 3 of variable at address | + | |
| + | | ||
| @ F000 and 000C rshift ; | @ F000 and 000C rshift ; | ||
| | | ||
| | | ||
| \ As a first step we have to define the relevant IO Bits | \ As a first step we have to define the relevant IO Bits | ||
| - | \ as Input ( with enabling internal pull-up resistor) | + | \ as Input (with enabling internal pull-up resistor) |
| \ or as output. | \ or as output. | ||
| \ Here you can find the relevant memory mapped addresses | \ Here you can find the relevant memory mapped addresses | ||
| Zeile 151: | Zeile 219: | ||
| \ so in the beginning we will test as Input and Output only, | \ so in the beginning we will test as Input and Output only, | ||
| \ see separate Forth Code | \ see separate Forth Code | ||
| + | \ for details, | ||
| + | \ see 1 http:// | ||
| + | \ and 2 http:// | ||
| + | \ and 3 http:// | ||
| + | \ we plan to show page numbers, here in document 3 page 18 onwards | ||
| | | ||
| | | ||
| - | \ In 4e4th, P1 and P2 are predefined 2constants. | + | \ In 4e4th, P1 and P2 are already |
| HEX | HEX | ||
| - | : INITIO \ -- \ I/O initialisation of JPS4 ports mk0 | + | : INITIO \ -- \ I/O initialisation of MMT ports mk0 |
| \ mask adr op | \ mask adr op | ||
| \ | \ | ||
| Zeile 162: | Zeile 235: | ||
| [ bin ] 10001000 [ hex ] 0024 ( P1IES ) cset \ falling edge detect | [ bin ] 10001000 [ hex ] 0024 ( P1IES ) cset \ falling edge detect | ||
| [ bin ] 00100000 [ hex ] 0026 ( P1SEL ) cset \ P1.5 sec func TA0.0 (FRQ) | [ bin ] 00100000 [ hex ] 0026 ( P1SEL ) cset \ P1.5 sec func TA0.0 (FRQ) | ||
| - | [ bin ] 10001000 [ hex ] 0027 ( P1REN ) cset \ pullup | + | [ bin ] 10001000 [ hex ] 0027 ( P1REN ) cset \ pull-up |
| - | [ bin ] 10000000 [ hex ] P1 cset \ P1.7 pullup enabled | + | [ bin ] 10000000 [ hex ] P1 |
| [ bin ] 00001111 [ hex ] 002A ( P2DIR ) cclr \ P2 INs | [ bin ] 00001111 [ hex ] 002A ( P2DIR ) cclr \ P2 INs | ||
| [ bin ] 11110000 [ hex ] 002A ( P2DIR ) cset \ P2 OUTs | [ bin ] 11110000 [ hex ] 002A ( P2DIR ) cset \ P2 OUTs | ||
| [ bin ] 00001111 [ hex ] 002F ( P2REN ) cset \ P2 pullups selected | [ bin ] 00001111 [ hex ] 002F ( P2REN ) cset \ P2 pullups selected | ||
| - | [ bin ] 00001111 [ hex ] P2 cset \ P2 pullups enabled | + | [ bin ] 00001111 [ hex ] P2 |
| [ bin ] 11000000 [ hex ] 002E ( P2SEL ) cclr \ clear these bits to I/O | [ bin ] 11000000 [ hex ] 002E ( P2SEL ) cclr \ clear these bits to I/O | ||
| - | + | | |
| - | | + | INITIO |
| | | ||
| | | ||
| Zeile 182: | Zeile 255: | ||
| | | ||
| : OUT> | : OUT> | ||
| - | 12PO 0@ out! ; | + | 12PO n0@ out! ; |
| | | ||
| - | : OUT \ n -- \ save n to O and do OUT! | + | : OUT \ n -- \ save n to O-nibble |
| - | 12PO 0! out> ; | + | 12PO n0! out> ; |
| | | ||
| - | : IN@ \ -- n \ read digital input pins (nibble | + | : IN@ \ -- n \ read digital input pins, lower nibble |
| P2 1- c@ 000F and ; | P2 1- c@ 000F and ; | ||
| | | ||
| - | \ helper | + | |
| + | in@ | ||
| + | dup IFAB n3! ; \ copy to I-nibble of IFAB | ||
| + | |||
| + | |||
| + | |||
| + | \ output a nibble to terminal | ||
| HEX | HEX | ||
| - | : 4# \ n -- | + | : 4# \ n -- \ display 4 digits unsigned |
| - | <# | + | <# |
| - | : 2# \ n -- | + | : 2# \ n -- \ display 2 digits unsigned |
| - | <# | + | <# |
| + | |||
| + | | ||
| | | ||
| \ test falling edge at switch S3 and S2 mk0 | \ test falling edge at switch S3 and S2 mk0 | ||
| Zeile 207: | Zeile 288: | ||
| | | ||
| \ Delays | \ Delays | ||
| - | \ 1MS is prefefined | + | \ 1MS is predefined |
| - | \ predefined for MCU running with 8Mhz DCO = default. | + | \ predefined for MCUs running with 8Mhz DCO = default. |
| \ Use Forth word MS to make any ms delay. | \ Use Forth word MS to make any ms delay. | ||
| \ Example: | \ Example: | ||
| Zeile 218: | Zeile 299: | ||
| | | ||
| : SECS \ n -- \ delay of n seconds | : SECS \ n -- \ delay of n seconds | ||
| - | 0 DO 1sec LOOP ; | + | 0 DO 1sec LOOP ; \ put the seconds value before the SECS word |
| | | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| \ Utilities for this MCU | \ Utilities for this MCU | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Tones | + | \ Tones and notes |
| - | \ Output is for MSP430G2553, | + | |
| | | ||
| HEX | HEX | ||
| - | \ Output square wave at P1.5 using timer TA0.0 mk0 | + | \ Output |
| | | ||
| \ Use P1.5 as timer TA0.0 ouput. | \ Use P1.5 as timer TA0.0 ouput. | ||
| \ This is done by setting P1.5 to its second function. | \ This is done by setting P1.5 to its second function. | ||
| \ Then set and start Timer. | \ Then set and start Timer. | ||
| - | \ Note: In second function, pin is no longer | + | \ Note: In second function, |
| \ a general purpose I/O pin. It is switched to another I/O | \ a general purpose I/O pin. It is switched to another I/O | ||
| \ mode called ' | \ mode called ' | ||
| Zeile 243: | Zeile 323: | ||
| 020 dup p1 1+ cset 026 cset ; | 020 dup p1 1+ cset 026 cset ; | ||
| | | ||
| - | : P15IO \ set back P1.5 to its GPIO | + | : P15IO \ set back P1.5 to its general |
| 020 026 cclr 020 041 cclr ; | 020 026 cclr 020 041 cclr ; | ||
| | | ||
| - | : TON- | + | : TON- |
| + | 00 0160 ! | ||
| + | p15io \ P1.5 back to I/O | ||
| + | 20 p1 cclr ; \ shut down current through speaker. | ||
| | | ||
| : TON+ \ n -- \ start timer-A with interval n | : TON+ \ n -- \ start timer-A with interval n | ||
| + | \ MSP430G2553, | ||
| p15sec | p15sec | ||
| 0080 0162 ! \ CCTL0 set timer output mode | 0080 0162 ! \ CCTL0 set timer output mode | ||
| Zeile 255: | Zeile 339: | ||
| ; | ; | ||
| | | ||
| - | \ midi tones B3 to B5, 2 octaves; pitch list. mk0 | + | \ Midi tones B3 to B5, 2 octaves; pitch list for TON+ mk0 |
| DECIMAL | DECIMAL | ||
| IHERE | IHERE | ||
| Zeile 276: | Zeile 360: | ||
| constant TONELIST | constant TONELIST | ||
| | | ||
| - | : T@ \ i -- n \ get pitch using index i | + | |
| + | | ||
| cells tonelist + @ ; | cells tonelist + @ ; | ||
| | | ||
| - | | + | : NOTE \ i d -- \ play note i of duration d |
| - | | + | |
| - | | + | |
| - | : LNOTE \ i -- | + | |
| - | note 500 ms ; | + | |
| - | : PAUSE \ n -- \ play pause of duration n | + | |
| - | | + | |
| | | ||
| - | \ see example melodie EX14 | + | |
| + | ton- ms ; | ||
| | | ||
| + | \ see example melody below | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | |
| - | \ PWM of 16KHz mk0 | + | |
| - | \ for 8MHZ DCO using timer TA0 | + | \ PWM of 16KHz for 8MHZ DCO using timer TA0 |
| | | ||
| HEX | HEX | ||
| Zeile 307: | Zeile 389: | ||
| | | ||
| : PWM- | : PWM- | ||
| - | | + | |
| p16io 0040 0021 cclr ; \ set p1.6 I/O and clear p1.6 | p16io 0040 0021 cclr ; \ set p1.6 I/O and clear p1.6 | ||
| | | ||
| Zeile 313: | Zeile 395: | ||
| 01F4 0172 ! \ TA0CCR0 | 01F4 0172 ! \ TA0CCR0 | ||
| 00E0 0164 ! \ TA0CCTL1 | 00E0 0164 ! \ TA0CCTL1 | ||
| - | 0174 ! \ TA0CCR1 | + | 0174 ! \ TA0CCR1 |
| - | 0210 0160 ! \ TA0CTL | + | 0210 0160 ! \ TA0CTL |
| ; | ; | ||
| Zeile 324: | Zeile 406: | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ ADC | + | \ ADC - init ADC0 and ADC4, get ADC value |
| HEX | HEX | ||
| - | \ You may name addresses and bits. | ||
| - | | ||
| \ address name \ function | \ address name \ function | ||
| \ 01B0 constant ADC10CTL0 \ ADC10 control register 0 | \ 01B0 constant ADC10CTL0 \ ADC10 control register 0 | ||
| Zeile 349: | Zeile 429: | ||
| \ 0010 constant ADC10ON | \ 0010 constant ADC10ON | ||
| \ ---- | \ ---- | ||
| - | \ 3070 <-- sum of option bits | + | \ 3070 <-- sum of option bits in hexadecimal |
| | | ||
| : ADCOFF | : ADCOFF | ||
| - | | + | |
| | | ||
| : ADCON \ -- \ start ADC10 | : ADCON \ -- \ start ADC10 | ||
| Zeile 379: | Zeile 459: | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ 4 servos connected to OUT | + | \ RC Servo Control - position |
| | | ||
| - | \ Use extern | + | \ Use external |
| \ Connect servo-GND to MCU-GND. | \ Connect servo-GND to MCU-GND. | ||
| \ Connect servo control lines to OUTx. | \ Connect servo control lines to OUTx. | ||
| - | \ Control line needs one 1..2ms | + | \ Control line needs a pulse between |
| + | \ 1ms left end, 1,5ms middle, 2ms right end. | ||
| + | \ Minimum pulse repetition rate is every 20ms, ~$40x, | ||
| \ for one position | \ for one position | ||
| | | ||
| Zeile 397: | Zeile 479: | ||
| x3 ! x2 ! x1 ! x0 ! ; | x3 ! x2 ! x1 ! x0 ! ; | ||
| | | ||
| - | : INITX \ -- \ load X0 .. X3 wit &500 | + | |
| + | | ||
| 500 dup dup dup ldx ; | 500 dup dup dup ldx ; | ||
| initx | initx | ||
| | | ||
| + | \ linit x to &480 ... &1700 (Range is ~1200 steps) | ||
| + | 480 constant sermin | ||
| + | 1700 constant sermax | ||
| + | : limit \ x -- x' \ linit x to servo minimum an maximum | ||
| + | sermin max sermax min ; | ||
| + | | ||
| + | HEX | ||
| : x? \ -- \ print all X | : x? \ -- \ print all X | ||
| x0 ? x1 ? x2 ? x3 ? ; | x0 ? x1 ? x2 ? x3 ? ; | ||
| Zeile 407: | Zeile 497: | ||
| 0 DO LOOP ; | 0 DO LOOP ; | ||
| | | ||
| - | : PULS | + | : PULS \ x n -- \ send puls x to bit n of P2; n=80, |
| >r r@ p2 cset dex r> p2 cclr 4 ms ; | >r r@ p2 cset dex r> p2 cclr 4 ms ; | ||
| | | ||
| Zeile 433: | Zeile 523: | ||
| \ adjust x-min and x-max to match your servo. | \ adjust x-min and x-max to match your servo. | ||
| | | ||
| - | \ test for oscilloscope | + | \ test, look at pulses on an oscilloscope |
| : SERTEST \ -- \ position all servos, permanent | : SERTEST \ -- \ position all servos, permanent | ||
| initio BEGIN serve key? UNTIl ; | initio BEGIN serve key? UNTIl ; | ||
| Zeile 439: | Zeile 529: | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Initialisation | + | \ Initialisation |
| DECIMAL | DECIMAL | ||
| : INIT \ -- \ set pin I/O and variables. | : INIT \ -- \ set pin I/O and variables. | ||
| Zeile 447: | Zeile 537: | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ --> up to here the image is saved as file |
| - | \ Example Programms | + | \ 4e4th+mmt4-V10.txt in TI format |
| - | \ ------------------------------------------------------------ | + | |
| | | ||
| - | \ ------------------------------------------------------------ | ||
| - | \ Example 0 - leave demo loop, run forth. | ||
| - | : EX0 | ||
| - | cr .ver | ||
| - | cr ." forth - command me." abort ; | ||
| | | ||
| - | | + | |
| - | + | | |
| - | \ ------------------------------------------------------------ | + | \ Example Programs made for MiniTool |
| - | \ Example 1 - display IN (1) | + | \ You need 3 switches S1 S2 S3, and 5 LED + 470Ohm at OUT and PWM. |
| + | \ ---------------------------------------------------------- | ||
| + | \ Note: (solo) means no PC connection needed. | ||
| + | \ ---------------------------------------------------------- | ||
| + | \ Example 1 - display IN. (solo) | ||
| HEX | HEX | ||
| - | : EX1 \ -- \ IN to OUT | + | : EX1 \ -- \ |
| initio | initio | ||
| BEGIN | BEGIN | ||
| - | in@ out \ get IN and store it to OUT | + | in out \ get IN and store it to OUT |
| key? UNTIL key drop ; \ leave loop, clean up | key? UNTIL key drop ; \ leave loop, clean up | ||
| | | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Example 2 - display IN (2) | + | \ Example 2 - display IN at OUT, set PWM-LED too. (solo) |
| HEX | HEX | ||
| : EX2 \ -- \ IN to PWM and OUT mk0 | : EX2 \ -- \ IN to PWM and OUT mk0 | ||
| - | initio | + | initio |
| BEGIN | BEGIN | ||
| - | in@ \ get IN | + | in@ \ get INex5 |
| - | dup out \ store to OUT | + | |
| - | PWM 1sec \ do PWM for a second | + | IF in dup out pwm THEN \ store IN to OUT and PWM |
| - | key? UNTIL | + | key? UNTIL |
| key drop pwm- ; | key drop pwm- ; | ||
| | | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Example 3 - faling | + | \ Example 3 - falling |
| HEX | HEX | ||
| - | : EX3 \ -- \ faling | + | : EX3 \ -- \ falling |
| - | initio | + | \ reset with S3. |
| + | initio | ||
| + | s2- s3- \ and reset edge detection | ||
| + | 1 out \ set initial OUT value | ||
| BEGIN | BEGIN | ||
| - | s2? IF | + | s2? IF s2- 08 out THEN |
| - | 1 out \ set on edge detect | + | s3? IF s3- |
| - | 1sec s2- zero out \ wait, then reset | + | |
| - | | + | |
| key? UNTIL \ leave loop, clean up | key? UNTIL \ leave loop, clean up | ||
| key drop ; | key drop ; | ||
| Zeile 499: | Zeile 588: | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Example 4 - faling | + | \ Example 4 - falling |
| HEX | HEX | ||
| - | : EX4 \ -- \ faling | + | : EX4 \ -- \ falling |
| - | initio s2- \ init system | + | initio |
| - | 01 note \ start low note | + | |
| + | 1 out \ set initial OUT value=1 | ||
| + | 01 tone@ ton+ | ||
| BEGIN | BEGIN | ||
| - | s2? IF | + | s2? IF s2- |
| - | 1 out \ set on edge detect | + | s3? IF s3- |
| - | 0F note \ do high note | + | key? UNTIL \ leave loop |
| - | 1sec s2- zero out \ wait, then reset out ... | + | key drop \ clean up |
| - | 01 note | + | 00 out |
| - | THEN | + | |
| - | key? UNTIL | + | |
| - | key drop ton- ; | + | |
| | | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Example 5 - toggle OUT bits | + | \ Example 5 - dance of 4 servos. To test the 4 servos |
| - | HEX | + | |
| - | : tout \ c -- c \ | + | |
| - | dup [char] 1 = IF 01 12po ctoggle out> exit THEN | + | |
| - | dup [char] 2 = IF 02 12po ctoggle out> exit THEN | + | |
| - | dup [char] 3 = IF 04 12po ctoggle out> exit THEN | + | |
| - | dup [char] | + | |
| - | dup [char] 0 = IF zero out exit THEN | + | |
| - | dup [char] f = IF 0f out exit THEN ; | + | |
| - | + | ||
| - | : EX5 \ -- \ press 1 2 3 4 to toggel OUT bits, | + | |
| - | \ 0 to clear all, F to set all. | + | |
| - | initio zero out | + | |
| - | BEGIN | + | |
| - | key tout | + | |
| - | 1B ( esc ) = UNTIL | + | |
| - | ; \ exit on esc-character | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | \ ------------------------------------------------------------ | + | |
| - | \ Example 6 - dance of 4 servos | + | |
| DECIMAL | DECIMAL | ||
| 0480 constant SL | 0480 constant SL | ||
| Zeile 568: | Zeile 636: | ||
| 1 rows +LOOP ; \ advance one row | 1 rows +LOOP ; \ advance one row | ||
| | | ||
| - | : EX6 \ -- \ dance until key is pressed | + | : EX5 \ -- \ dance until key is pressed |
| initio | initio | ||
| BEGIN | BEGIN | ||
| Zeile 576: | Zeile 644: | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Example | + | \ Example |
| | | ||
| \ ADC@ is 0 .. $3FF | \ ADC@ is 0 .. $3FF | ||
| Zeile 586: | Zeile 654: | ||
| 480 + ; | 480 + ; | ||
| | | ||
| - | : EX7 \ -- \ Position of servo2 given by potentiometer | + | : EX6 \ -- \ Position of servo2 given by potentiometer |
| initio | initio | ||
| adc4 adcon \ init ADC | adc4 adcon \ init ADC | ||
| Zeile 596: | Zeile 664: | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Example | + | \ Example |
| HEX | HEX | ||
| - | : EX8 \ -- \ ADC to OUT and terminal | + | : EX7 \ -- \ ADC to OUT and terminal |
| initio adc4 adcon \ init all modules | initio adc4 adcon \ init all modules | ||
| + | s2- | ||
| BEGIN | BEGIN | ||
| adc@ 44 / \ scale 10Bit value, 3FF..0 --> F...0 | adc@ 44 / \ scale 10Bit value, 3FF..0 --> F...0 | ||
| dup out \ display scaled value | dup out \ display scaled value | ||
| - | | + | . 1sec \ print to terminal, wait 1 second |
| - | | + | |
| key? UNTIL \ leave loop, clean up | key? UNTIL \ leave loop, clean up | ||
| key drop ton- ; | key drop ton- ; | ||
| Zeile 611: | Zeile 679: | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Example | + | \ Example |
| - | : EX9 ; | + | HEX |
| + | : EX8 \ -- \ ADC to OUT and play note mk0 | ||
| + | initio adc4 adcon \ init all modules | ||
| + | BEGIN | ||
| + | adc@ 44 / \ scale 10Bit value, 3FF..0 --> F...0 | ||
| + | dup out \ display scaled value | ||
| + | 200 note \ play apropriate tone | ||
| + | key? UNTIL \ leave loop, clean up | ||
| + | key drop ton- ; | ||
| | | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | \ ---------------------------------------------------------- |
| - | \ Example | + | \ Example |
| - | | + | |
| | | ||
| + | variable BEAT \ holds delay time in ms | ||
| | | ||
| + | : whole \ -- n \ duration of whole note | ||
| + | beat @ ; | ||
| + | : quarter \ -- n \ duration of quarter note | ||
| + | whole 4 / ; | ||
| + | : eighth | ||
| + | quarter 2 / ; | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | |
| - | \ Example 11 - tbd | + | whole note ; |
| - | : EX11 ; | + | : n4 \ i -- \ play quarter note i |
| + | quarter note ; | ||
| + | | ||
| + | | ||
| | | ||
| + | : p1 \ -- \ play whole pause | ||
| + | whole pause ; | ||
| + | : p4 \ -- \ play quarter pause | ||
| + | quarter pause ; | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | |
| - | \ Example | + | 500 beat ! |
| - | | + | 06 n4 \ G4 |
| - | | + | 0C n4 \ F5 |
| - | initio s2- \ init system and reset edge detection | + | 0A n4 \ D5 |
| - | | + | 09 n4 \ C5 |
| + | 0A n4 \ D5 | ||
| + | 09 n4 \ C5 | ||
| + | 07 n4 \ A4 | ||
| + | 06 n4 \ G4 | ||
| + | 04 n1 \ E4 | ||
| + | 06 n4 \ G4 | ||
| + | 0C n4 \ F5 | ||
| + | 0A n4 \ D5 | ||
| + | 09 n4 \ C5 | ||
| + | 09 n4 \ C5 | ||
| + | 08 n4 \ B4 | ||
| + | 09 n4 \ C5 | ||
| + | 0A n1 \ D5 | ||
| + | ton- ; \ try to make it sound better ... | ||
| + | |||
| + | |||
| + | |||
| + | \ ---------------------------------------------------------- | ||
| + | \ Example | ||
| + | | ||
| + | cr .ver | ||
| + | cr ." forth - command me." abort ; | ||
| + | | ||
| + | |||
| + | |||
| + | \ ---------------------------------------------------------- | ||
| + | | ||
| + | \ Select an example program by it's number using S2. | ||
| + | \ Press S3 to run it. | ||
| + | \ Select and run Example 11 to enter forth. | ||
| + | |||
| + | : DEMOLOOP \ -- | ||
| + | initio s2- S3- \ init system and reset edge detection | ||
| + | | ||
| + | 000F out! \ indicate ' | ||
| BEGIN | BEGIN | ||
| - | | + | |
| - | 12po 0@ 1+ F and 12po 0! \ increment OUT nibble | + | 12po n0@ 1+ F and 12po n0! \ increment OUT nibble |
| - | out> | + | out> |
| - | 100 ms s2- | + | 100 ms s2- \ wait, then reset S2 |
| THEN | THEN | ||
| - | key? UNTIL \ leave loop, clean up | + | S3? IF \ run demo with S3 |
| - | | + | 12po n0@ |
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | drop S3- | ||
| + | 00 out \ back to start value | ||
| + | THEN | ||
| + | AGAIN ; | ||
| | | ||
| | | ||
| + | \ --> up to here the image is saved as file | ||
| + | \ --> 4e4th+mmt4+ex-V10.txt in TI format | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | |
| - | \ Example | + | |
| - | : EX13 \ -- \ | + | |
| + | \ More example programs made for terminal interaction. | ||
| + | \ You need a serial PC connection to the MSP430 MCU. | ||
| + | \ How to do that is shown in the documentation of MMT4. | ||
| + | \ ---------------------------------------------------------- | ||
| + | |||
| + | \ ---------------------------------------------------------- | ||
| + | \ Example | ||
| + | HEX | ||
| + | : EX11 \ -- \ terminal KEY to OUT with echo | ||
| base @ hex \ save number base on stack, set hex output | base @ hex \ save number base on stack, set hex output | ||
| - | initio | + | initio |
| - | cr ." press any key to start - press Esc-key to exit" | + | cr ." press any key to start, " |
| + | cr ." | ||
| cr \ new line | cr \ new line | ||
| BEGIN | BEGIN | ||
| - | key | + | key |
| dup over 20 < IF | dup over 20 < IF | ||
| 5E emit 40 + emit \ echo control character | 5E emit 40 + emit \ echo control character | ||
| ELSE emit THEN \ echo character | ELSE emit THEN \ echo character | ||
| dup space 2# space \ print character value | dup space 2# space \ print character value | ||
| - | dup out | + | dup out |
| 1B ( esc ) = UNTIL | 1B ( esc ) = UNTIL | ||
| base ! | base ! | ||
| ; \ exit on esc-character | ; \ exit on esc-character | ||
| - | | ||
| | | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | |
| - | \ Example | + | |
| + | \ Example | ||
| HEX | HEX | ||
| - | : EX14 \ -- \ | + | : tout \ c -- c \ |
| - | initio | + | dup [char] 1 = IF 01 12po ctoggle out> exit THEN |
| + | dup [char] 2 = IF 02 12po ctoggle out> exit THEN | ||
| + | dup [char] 3 = IF 04 12po ctoggle out> exit THEN | ||
| + | dup [char] 4 = IF 08 12po ctoggle out> exit THEN | ||
| + | dup [char] 0 = IF 00 out exit THEN | ||
| + | dup [char] f = IF 0f out exit THEN ; | ||
| + | |||
| + | : EX12 \ -- \ | ||
| + | \ 0 to clear all, F to set all. | ||
| + | initio | ||
| + | cr ." press 1 2 3 4 " | ||
| + | cr ." Esc to quit ... " | ||
| + | cr | ||
| BEGIN | BEGIN | ||
| - | | + | |
| - | | + | |
| - | note 50 pause \ play apropriate tone | + | ; \ exit on esc-character |
| - | key? UNTIL \ leave loop, clean up | + | |
| - | | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | | + | |
| - | \ Example 15 - play MYBONNIE | + | |
| - | \ Connect speaker between P1.5 and GND. | + | |
| - | HEX | + | |
| - | : EX15 \ -- \ play once | + | |
| - | 06 note 50 pause \ G4 | + | |
| - | 0C note 50 pause \ F5 | + | |
| - | 0A note 50 pause \ D5 | + | |
| - | 09 note 100 pause \ C5 | + | |
| - | 0A note 50 pause \ D5 | + | |
| - | 09 note 50 pause \ C5 | + | |
| - | 07 note 100 pause \ A4 | + | |
| - | 06 note 50 pause \ G4 | + | |
| - | 04 lnote 100 pause \ E4 | + | |
| - | 06 note 50 pause \ G4 | + | |
| - | 0C note 50 pause \ F5 | + | |
| - | 0A note 100 pause \ D5 | + | |
| - | 09 note 50 pause \ C5 | + | |
| - | 09 note 50 pause \ C5 | + | |
| - | 08 note 100 pause \ B4 | + | |
| - | 09 note 50 pause \ C5 | + | |
| - | 0A lnote 200 pause \ D5 | + | |
| - | ton- ; \ try to make it sound better ... | + | |
| - | | + | |
| | | ||
| + | \ --> up to here the image is saved as file | ||
| + | \ --> 4e4th+mmt4+ex+pcex-V10.txt in TI format | ||
| + | |||
| + | \ Add your own examples here. | ||
| + | \ SAVE when compiled. | ||
| | | ||
| - | \ ------------------------------------------------------------ | + | |
| - | \ In DEMOLOOP you may select an example programm by its nummer | + | |
| - | \ and run it. EXIT demoloop by selecting EX0. | + | |
| - | + | \ ---------------------------------------------------------- | |
| - | : DEMOLOOP \ -- | + | |
| - | BEGIN | + | |
| - | initio s2- S3- \ init system and reset edge detection | + | |
| - | F OUT \ initial OUT value | + | |
| - | BEGIN | + | |
| - | s2? IF \ select demo with S2 | + | |
| - | 12po 0@ 1+ F and 12po 0! \ increment OUT nibble | + | |
| - | out> | + | |
| - | 100 ms s2- \ wait, then reset S2 | + | |
| - | THEN | + | |
| - | S3? IF \ run demo with S3 | + | |
| - | 12po 0@ | + | |
| - | dup 0 = IF EX0 THEN \ run example ... | + | |
| - | dup 1 = IF EX1 THEN | + | |
| - | dup 2 = IF EX2 THEN | + | |
| - | dup 3 = IF EX3 THEN | + | |
| - | dup 4 = IF EX4 THEN | + | |
| - | dup 5 = IF EX5 THEN | + | |
| - | dup 6 = IF EX6 THEN | + | |
| - | dup 7 = IF EX7 THEN | + | |
| - | dup 8 = IF EX8 THEN | + | |
| - | dup 9 = IF EX9 THEN | + | |
| - | dup A = IF EX10 THEN | + | |
| - | dup B = IF EX11 THEN | + | |
| - | dup C = IF EX12 THEN | + | |
| - | dup D = IF EX13 THEN | + | |
| - | dup E = IF EX14 THEN | + | |
| - | dup F = IF EX15 THEN | + | |
| - | drop S3- \ clean up stack, reset S3 | + | |
| - | F out \ back to start value | + | |
| - | THEN | + | |
| - | AGAIN ; | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | \ --> swk4-0x.txt | + | |
| - | + | ||
| - | \ save | + | |
| - | | + | |
| - | \ ------------------------------------------------------------ | + | |
| \ todo *** | \ todo *** | ||
| - | \ P0..P15 loop | ||
| - | \ > Wie verkuerzt man die Tonlaenge? | ||
| - | \ < | ||
| - | \ ausgang via taster statt key? | ||
| - | | ||
| | | ||
| decimal | decimal | ||
projects/mmt4ue2/mmtquellcode0.1415358081.txt.gz · Zuletzt geändert: 2014-11-07 12:01 von mka