Home

\ swk4 "swiss knife" 4bit I/O \ using 4e4th Release0.34 on TI

image

Contents

1. Device Pinout MSP430G2553 20 Pin PDIP TOP VIEW VCC 01 20 VSS LED1 LP ADO P1 0 02 19 P2 6 OUT2 RXD P1 1 03 18 P2 7 OUT3 TXD P1 2 04 17 test S2 LP S2 P1 3 05 16 RST S1 LP EEEE E AD4 P1 4 06 151 P1 7 S1 SPI E EE FRQ P1 5 07 14 P1 6 PWM LED2 LP SPI TAO 1 SSS Sse ae INO P2 0 08 13 P2 5 OUTI E IN1 P2 1 09 12 P2 4 OUTO IN2 P2 2 10 11 P2 3 IN3 P1 0 used as Input later on as Analog Input 1 P1 1 RX and P1 2 TX are used as the serial interface to the PC P1 3 used as S2 as on the TI Launchpad internal resistor enabled P1 4 used as Input later on as Analog Input 2 P1 5 used as Output later on to output a frequency with defined length P1 6 Outout later on as Pulse Width Modulation output quasi D A Output Oe P1 7 Input S1 internal resistor enabled All P2 x Inputs have internal resistor enabled so open input means HIGH P2 0 Input 0 P2 1 Input 1 P2 2 Input 2 P2 3 Input 3 P2 4 Output 0 P2 5 Output 1 P2 6 Output 2 P2 7 Output 3 The MSP 430 will be rather fully used So to save Program Space the 4 Bit Nibbles are packaged into 4x4 nibbles to be one Variable 16Bit cell This will save on RAM used Some scrach variables mko IN 4 bit input when used reflects status of 4 Input lines EF 4 bit value for tones
2. 16 x ADC10CLKs 0040 constant REF2 5V ADC10 Ref 0 1 5V 1 2 5V 0020 constant REFON ADC10 Reference on 0010 constant ADC100N ADC10 On Enable Sh 3070 lt sum of option bits ADCOFF stop ADC10 zero O1BO N can be modified only when ENC 0 ADCON Be start ADC10 0002 OIBO set Set ENC DC Ne es get ADC value EGIN 04 01B0 cget UNTIL test BIT2 ADC10IFG 1B4 get result A 03 01B0 SET start conversion ENC ADC10SC bits B 0 ADCO select and init ADC channel 0 adcoff 3070 O01BO0 set options see MCU user manual 0100 01B2 select input channel AO at P1 0 01 004A cset set pin analog input enable ADC4 select and init ADC channel 4 adcoff 3070 O1B0 set options see MCU user manual 4000 01B2 select input channel A4 at P1 4 10 004A cset set pin analog input enable Example adc4 adcon adc print single conversion a a 4 servos connected to OUT Use extern DC power supply for servos Connect servo GND to MCU GND Connect servo control lines to OUTx Control line needs one 1 2ms puls 20ms pause S40x for one position HEX variabl variabl variabl variabl x0 x1 x2 x3 LDX x0 x1 x2 x3 load variables X0 X3 x3 l x2 Lxi 1 X0 l3 e BO gE eo a i H NITX load XO X3 wit amp 500 500 du
3. A 4 bit A register B 4 bit B register variable IFAB define a variable W 4 bit W variable X 4 bit A variable KN 4 bit Y variable Z 4 bit Z variable variable WXYZ Al 4 bit analog in channel 1 A2 4 bit analog in channel 2 P 4 bit pulse width modulated output O 4 bit output register variable 12PO NITSV init scrach variables 0 FAB 0 WXYZ O A2ZPO hs initsv define a Word to show a cell at address unsigned mko adr e s 7 juggling nibbles mk0 HEX 0 n adr store nibble 0 to variable at address gt r r FFFO and swap F and r gt 1 n adr store nibble 1 to variable at address gt r r FFOF and swap F and 4 lshift r gt 2 n adr store nibble 2 to variable at address gt r r FOFF and swap F and 8 lshift r gt 3 n adr store nibble 3 to variable at address gt r r OFFF and swap F and C lshift r gt 0 adr n fetch nibble 0 of variable at address OOOF and 1 adr n fetch nibble 1 of variable at address OOFO and 0004 rshift 2 adr n OFOO and 0008 3 adr n F000 and 000C rshift As as Input a first step we have to defin with enabling internal or as output Here you can find the relevant memory mapped addresses to set functionality fetch nibble 2 of variabl r
4. TAO HEX PI6IO X set P1 6 to GPIO 0040 0022 cset P1DIR P1 6 OUT 0040 0026 cclr PISEL P1 6 GPIO P16SEC set P1 6 to second function 0040 0022 cset P1DIR P1 6 OUT 0040 0026 cset P1SEL P1 6 select second function PWM zero 160 TAOCTL stop timer pl6io 0040 0021 cclr set pl 6 I O and clear pl 6 PWM n init and start PWM at P1 6 O1F4 0172 TAOCCRO set period 16KHz at 8MHZ DCO 00E0 0164 TADCCTL1 set output mode 0174 TAOCCR1 set pulsewidth 0210 0160 TAOCTL set timer mode and run PWM n set PWM at P1 6 n O ton OOOF and dup 05 IF drop pwm ELSE OO1F pwm pl6 sec THEN ADC HEX You may name addresses and bits address name function 01B0 constant ADC1OCTLO ADC10 control register 0 01B2 constant ADC1OCTL1 ADC10 control register 1 004A constant ADCIOAEO ADC10 input enable register 0 01B4 constant ADC1OMEM ADC10 Memory conversion result some named bits 0002 constant ENC ADC10 Enable Conversion bit 4000 constant INCH 4 Selects Channel 4 10 constant BIT4 for P1 4 Analog Input Enable 0001 constant ADC10SC start conversion bit 0004 constant ADC1OIFG ADC10 Interrupt Flag option bits are 2000 constant SREF 1 set VR VREF and VR AVSS 1000 constant ADC1OSHT 2
5. THEN dup D F EX13 THEN dup E F EX14 THEN dup F IF EX15 THEN drop sl clean up stack reset S1 F out back to start value THEN AGAIN gt swk4 Ox txt save todo PO P15 loop decimal unused u RAM mem u FLASH hex s finis
6. apropriate tone key UNTIL leave loop clean up key drop ton Example 15 play MYBONNIE Connect speaker between P1 5 and GND HEX EX15 play once 06 note 50 pause OC note 50 pause OA note 50 pause 09 note 100 pause OA note 50 pause 09 note 50 pause 07 note 100 pause 06 note 50 pause 04 Inote 100 pause 06 note 50 pause OC note 50 pause OA note 100 pause 09 note 50 pause 09 note 50 pause 08 note 100 pause 09 note 50 pause C5 OA Inote 200 pause D5 ton try to make it sound better F5 D5 C5 C3 B4 GI fi In DEMOLOOP you may select an example programm by its number and run it EXIT demoloop by selecting EXO DEMOLOOP BEGIN initio s2 sl 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 gt display it 100 ms s2 wait then reset S2 THEN sl IF run demo with S1 12po 0 dup 0 IF EXO THEN run example EX1 THEN Hy dup 1 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 F EX9 THEN dup A F EX10 THEN dup B F EX11 THEN dup C F EX12
7. to its second function Then set and start Timer Note In a general second function pin is no longer purpose I O pin It is switched to another I O mode called second function of the pin P15SEC 020 dup p P15I0 set P1 5 to its second function 1 1 cset 026 cset set back P1 5 to its GPIO 020 026 cclr 020 041 cclr TON zero 0160 pl5io stop timer TON n start timer A with interval n pl5sec init pin 0080 0162 CCTLO set timer output mode n 0172 CCRO set interval 0160 L CTL start timer clock mode and divider 0254 midi tones B3 to B5 2 octaves pitch list mk0O DECIMAL HERE 0000 i 7962 i 7515 i 6695 i 5965 i 5630 i 5016 i 4469 i 3981 i no tone Cc SMOD Ey NAS 3348 i D5 2983 i E5 2815 iy F5 2508 i G5 2235 1 A5 1991 i B5 onstant TONELIST T i n cells tonelist get pitch using index i ECIMAL NOTE Gos play note i t ton 500 ms LNOTE i play note 500 ms PAUSE n play ton ms use n see example melodi EX14 note i longer pause of duration n 50 100 200 PWM of 16KHz mko for 8MHZ DCO using timer
8. 7 AAA a a a a swk4 swiss knife 4bit I O using 4e4th Release0 34 on TI MSP430G2553 MCU LaunchPad started mka 2014 10 26 Idea Juergen Pintaske History added DEMOLOOP to select examples with S2 and S1 switches cleaning up examples added EX12 3 11 2014 added 2 servo examples 02 11 2014 added 4 servo pulses to OUT 30 10 2014 22 47 renamed demos to EXx 29 10 2014 21 19 added some demos Px 29 10 2014 13 05 added ADC 29 10 2014 00 02 first test today 26 10 2014 23 49 Compiles in target without errors blocks with mkO mark tested ok on first glance functioning stack ok MYBONNIE is playing no stack error ok PWM running SWEEP is ok I O and nibbels working on variables mem u 6703 plenty flash left Issues Glitches while setting upper nibble of P2 fixed OUT port name P2 is in conflict with modul name P2 renamed HAHA A EEE ET TF FLEET A A EE ETEE EE ET Start of Program SWK4 programmed in Forth This program gives some routines planned to help Learning Programming And we use them here as an example of how to program the MSP430 Controller Add the 5 resistor LED combinations and the 3 switches to e th430 board and run routines completely in the MSP430 using Forth wich is on this chip as well Defining the I O for this application
9. 80 constant SL 1700 constant SR 1000 constant SM ERE create a list of moves Sh 4 Sh i Sh ty Sh ae SR i SR i SMi SR i SM i SMi SR i SM i Slo ip Sly Sip SMe a SLi SM i SM i SL i SM i SR i SR i SR i SR i CONSTANT MO adr get list address ROWS Ae as n calculate row offset in bytes r A cells ROW adr x0 xl x2 x3 get 4 values from adr dup 4 cells swap DO i cell LOOP DANCE adr n play list at address n rows rows over swap calculate end of list DO from beginning till end of list iu testing i row ldx servos drive servos to positions of row 1 rows LOOP advance one row EX6 dance until key is pressed initio BEGIN m0 6 dance set list and rows then play it once key UNTIL again until key is pressed key drop clean up Example 7 servo follows analog input pin ADC4 ADC is 0 3FF SERVO is amp 480 amp 1700 iCIMAL POSITION adc pos scale adc value to servo position 480 EX7 Position of servo2 given by potentiometer initio init ports adc4 adcon init ADC initx statposition of servos BEGIN adc position x2 serve key UNTIL key drop clean up Example 8 get analog input HEX EX8 ADC to OUT and terminal mko initio adc4 adcon i
10. ins nibble P2 1 c OOOF and helper to output a nibble to terminal HEX 4 lt 2 lt test falling edge at switch S1 023 constant P11 S1 52 S1 9 yon aE zero Ken Zero 080 PI1IFG 008 P1IFG 080 PLIFG display 4 digits unsigned with gt TYPE disp gt TYPE SPACE FG cget i cget i eeln Noes SPACE ay 2 digits unsigned with 1 Fh Fh and S2 mk0O set on edg vent set on edg vent reset edg vent flag Bits write Output Data Input and Output only ing edge detect func TAO 0 up selected ullups selected cclr clear these bits to leading zeros leading zeros FRQ I O S2 008 PIIFG cclr i Se reset edg vent flag Delays mko IMS is prefefined in 4e4th Its an empty loop Use Forth Example predefined for MCU running with 8Mhz DCO default word MS to make any ms delay decimal 10 ms delay of 10 miliseconds DECIMAL 1000 ms SECS n 0 DO 1sec F ISEC delay of one second delay of n seconds mko LOOP Utilities for this MCU Tones Output is HEX for MSP430G2553 8Mhz DCO and SMCIK 2 Output square wave at P1 5 using timer TA0 0 mko Use P1 5 as timer TA0 0 ouput This is done by setting P1 5
11. nit all modules BEGIN adc 44 scale 10Bit value 3FF 0 gt F 0 dup out display scaled value dup note 50 pause play apropriate tone print to terminal key UNTIL leave loop clean up key drop ton Example 9 tbd EX9 L8 A Example 10 tbd EX10 a Example 11 tbd EX11 PO a aa Example 12 pressing S2 increments OUT HEX BX12 o faling edge detector S2 counting up OUT initio s2 init system and reset edge detection F OUT initial OUT value BEGIN s2 IF 12po 0 1 F and 12po 0 increment OUT nibble out gt display it 100 ms s2 wait then reset S2 THEN key UNTIL leave loop clean up key drop Example 13 echo any key EX13 terminal KEY to OUT with echo MK initio zero out cr press any key to start press Esc key to exit cr new line BEGIN k d ey get key up over 20 lt IF 5E emit 40 emit echo control character ELSE emit THEN echo character up space 2 space print character value up out send lower nibble to OUT B esc UNTIL exit on esc character OO A Example 14 HEX EX14 display ADC at OUT and play note mk0O initio adc4 adcon init all modules BEGIN adc 44 scale 10Bit value 3FF 0 gt F 0 dup out display scaled value note 50 pause play
12. p dup dup ldx initx x print all X xO 2 UxL Po x2 2 x3 PF DEX x waste time x 0 DO LOOP PULS x n send puls x to bit n of P2 n 80 40 20 10 gt r rl p2 cset dex r gt p2 cclr 4 ms SERVE send one puls to all servos x0 10 pul x1 20 pul x2 40 pul x3 80 pul nnn wn SERVOS position all servos initio 30 0 DO serve LOOP ECIMAL set x to amp 480 amp 1700 Range is 1200 steps SERO x reposition servo0 x0 servos SERI x reposition servol xl servos SER2 x reposition servo2 x2 servos SER3 x reposition servo3 x3 servos adjust x min and x max to match your servo test for oscilloscope SERTEST position all servos permanent initio BEGIN serve key UNTIL Initialisation ECIMAL NIT set pin I O and variables initio initsv initx Example Programms Example 0 leave demo loop run forth EXO cr ver cr forth command me abort Example 1 display IN 1 EX EX1 IN to OUT mko initio BEGIN in out get IN and store it to OUT key UNTIL key drop leave loop clean up Example 2 display IN 2 HEX EX2 IN to PWM and OUT mko initio BEGIN in get IN dup out store
13. shift fetch nibble 3 of variabl the relevant e at address e at address O pull up resistor read Input Data Some of the functions used ar so in the beginning we will test as see separate Forth Code rather complex In 4e4th P1 and P2 are predefined 2constants HEX INITIO I O initialisation of JPS4 ports mk0 mask adr op 76543210 bin 10011001 hex 0022 P1DIR cclr Pl INs bin 01100110 hex 0022 P1DIR cset Pl OUTs bin 10001000 hex 0024 PIIES cset fall bin 00100000 hex 0026 PISEL cset P1 5 sec bin 10001000 hex 0027 PIREN cset pull bin 10000000 hex P1 cset P1 7 pullup enabled bin 00001111 hex 002A P2DIR cclr P2 INs bin 11110000 hex 002A P2DIR cset P2 OUTs bin 00001111 hex 002F P2REN cset P2 p bin 0000 hex P2 cset P2 pullups enabled bin 1000000 hex 002E P2SEL A NITIO Basic I O mkO HEX OUT n write OUT to P2 upper nibble 4 LEDS 04 lshift move to n upper nibble OF or keep input pullups set p2 c write port OUT gt copy O to OUT 12P0 0 out OUT Ae save n to O and do OUT 12PO 0 out gt IN n read digital input p
14. to OUT PWM 1sec do PWM for a second key UNTIL leave loop clean up key drop pwm Example 3 falling edge detector 1 HEX EXS A E N faling edge detector S2 to OUTO mko initio s2 init system and reset edge detection BEGIN s2 IF 1 out set on edge detect lsec s2 zero out wait then reset THEN key UNTIL leave loop clean up key drop X Example 4 falling edge detector 2 HEX EX4 falling edge detector S2 to note mko initio s2 init system and reset edge detection 01 note start low note BEGIN s2 IF 1 out set on edge detect OF note do high note lsec s2 zero out wait then reset out 01 note and low note THEN key UNTIL leave loop clean up key drop ton Example 5 toggle OUT bits HEX tout c Cc dup char 1 IF 01 12po ctoggle out gt exit THEN dup char 2 IF 02 12po ctoggle out gt exit THEN dup char 3 IF 04 12po ctoggle out gt exit THEN dup char 4 IF 08 12po ctoggle out gt exit THEN dup char 0 IF zero out exit THEN dup char f IF Of 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 04

Download Pdf Manuals

image

Related Search

Related Contents

Operating instructions - TLS Communication GmbH  HI 141 - Hanna Instruments Canada  GR60 User Manual - Stanley Hydraulic Tools  Samsung AQV09KBBN Užívateľská príručka  DECOR 902/903 - Thermex Scandinavia AS  I 30/55s      Manuale d`uso  Hardinge B160A DD100 Direct  

Copyright © All rights reserved.
Failed to retrieve file