From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.7 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FREEMAIL_REPLYTO,FROM_WORDY,INVALID_MSGID,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fd6dd,c78177ec2e61f4ac X-Google-Attributes: gidfd6dd,public X-Google-Thread: 103376,c78177ec2e61f4ac X-Google-Attributes: gid103376,public From: jim granville Subject: Re: ada and robots Date: 1997/06/20 Message-ID: <33AAC183.34C0@xtra.co.nz>#1/1 X-Deja-AN: 251430684 References: <338CDA96.53EA@halcyon.com> <338F5D7D.6C03@tiac.net> <338F9D05.5EB3@bix.com> <5mqpj3$bc5$1@goanna.cs.rmit.edu.au> <33930245.12A1@sprintmail.com> <5mv984$7kn@news.emi.com> <33A5D644.37A3@epix.net> <33A69E46.3230@gsfc.nasa.gov> Organization: Mandeno Granville El Ltd. Reply-To: DesignTools@xtra.co.nz Newsgroups: comp.robotics.misc,comp.lang.ada Date: 1997-06-20T00:00:00+00:00 List-Id: ---- Ada & Robots --- As this thread has diverged to become a language/religion discussion, I thought some real code, from real applications, might help. This code is not Ada, but Modula-2 / IEC1131, which are Ada 'subsets'. ( ie are much closer to Ada in style, syntax, and approach, than to C ) For ROBOT applications, Ada is too large to fit in small controllers, but Modula-2 has all the TYPE and SCOPE benefits of Ada, and it actually fits _very well_ on the C51 core - we have REAL CONTROL apps running in 89C1051's, with 1K of FLASH ROM. Unlike C, M2 has true BOOLEAN types, which overlay well on the C51 Boolean Engine. A C51 core also struggles to efficently support C's wide use of pointers. ( commonly seen in C's are 3 byte, run time interpreted, SLOW pointers.. ) All of the below can be coded in M2, C, and Assembler for that matter. It can just be done quicker, with fewer errors, in Modula-2. ( a good example of a user supplied C error, is below ) Conclusion : Choose the highest level language that will do the job. It may be Ada, BASIC, C, Clarion, Delphi, Forth, Modula-2, Visual BASIC... ( or sometimes, even Assembler ) This code fragment in Modula2, is from a MM53200 'Garage Door' style decoder, coded for a 89C2051. Total code size, for a self testing receiver, is 227 bytes. This code uses the BITSET feature of Modula-2, to greate a PACKED BOOLEAN ARRAY of 24 Data bits, into 3 BYTES. CASE BitTimeL OF | OneMIN..OneMAX : INCL(RxCODE[RxCtr >> 3],RxCtr); | ZeroMIN..ZeroMAX : (* default is a Zero *) ELSE (* bad value, so reset *) TF0 := TRUE; (* catch Reset, next pass *) RxCtr := 0; END; INC(RxCtr); This code illustrates two methods of loading, one 'collects' BOOLEANs and is highly readable, the other uses BINARY format. IE := {EA,ET0,ES}; IE := 2#1001_0010; (* EA.EC.ET2.ES.ET1.EX1.ET0.EX0 *) This code is from a DUAL 6 BIT Picket fence D to A converter. Total code, for Dual DAC is 95 bytes. It allows appx 33KHz clock rates, and can run as a background DAC. More, or less, BITS / Channels are easy to add / remove. Such DACs are highly linear, use just 1 PIN per DAC, and are ideal for integration to control voltage outputs. DACaPIN := DACa; DACbPIN := DACb; (* does ONE of these IF statements ONLY *) IF PWM.0 THEN (* 32 Pickets, odd numbers *) DACa := DAC_A.5; (* Uses BYTE BITADDRESSABLE syntax *) DACb := DAC_B.5; ELSIF PWM.1 THEN (* 16 Pickets xxxx10 *) DACa := DAC_A.4; DACb := DAC_B.4; ELSIF PWM.2 THEN (* 8 Pickets xxx100 *) DACa := DAC_A.3; DACb := DAC_B.3; .... etc.... This code flips the BIT order in a BYTE, for COMMS protocol usage. TYPE hT = ARRAY [0..15] OF BYTE; (* 0 1 2 3 4 5 6 7 8 9 A B C D E F *) CONST MirrorTable = hT(0H,08H,04H,0CH,02H,0AH,6,0EH,1,9,5,0DH,3,0BH,7,0FH); PROCEDURE MirrorF(Par : SHORTCARD REGISTER_2) : SHORTCARD; (* 16 bytes,14uS *) BEGIN RETURN(ROTATE(MirrorTable[Par AND 0FH],4) OR MirrorTable[Par >> 4]); END MirrorF; And here is some C code, doing the same thing... This compiles, runs, and works - to a point, It has a BUG that appears ONLY SOMETIMES. Whilst the Modula-2 compiler would have caught this at compile time, this C user may have to wait until the customer calls : ' You know, sometimes.... ' const char Inv[] = {0x00, // 0000 --> 0000 0x08, // 0001 --> 1000 0x04, // 0010 --> 0100 0x0c, // 0011 --> 1100 0x0a, // 0101 --> 1010 0x06, // 0110 --> 0110 0x0e, // 0111 --> 1110 0x01, // 1000 --> 0001 0x09, // 1001 --> 1001 0x05, // 1010 --> 0101 0x0d, // 1011 --> 1101 0x03, // 1100 --> 0011 0x0b, // 1101 --> 1011 0x07, // 1110 --> 0111 0x0f}; // 1111 --> 1111 char Invert(char cByte) { return ((Inv[cByte & 0xf] << 4) | Inv[(cByte & 0xf0)>>4]); } - jim granville -- ======= Manufacturers of Serious Design Tools for uC and PLD ========= = Optimising Modula-2 Structured Text compilers for ALL 80X51 variants = Reusable object modules, for i2c, SPI and SPL bus interfaces = Safe, Readable & Fast code - Step up from Assembler and C = Emulators / Programmers for ATMEL 89C1051, 2051, 89C51 89S8252 89C55 = *NEW* Bondout ICE for 89C51/89C52/89C55 = for more info, Email : DesignTools@xtra.co.nz Subject : c51Tools