![]() |
|
|
|
|
1
20th October 14:10
External User
Posts: 1
|
If you read my introductory episode (#837, and arbitrarily chosen number
that reflects that the search for Microchip PIC 16F forths have been asked for a while) I think I need to implement NEXT, ENTER, and EXIT in order to run Forth words under Frank Sergeant's 3 instruction Forth microkernel. Threading is the core of this issue. So let's examine the possibilities. As I said in the last missive, the PIC is quirky. It rears its ugly little head right off the bat in several ways: 1. Ram is so precious that there's no way to run code in it. 2. Program and data flash are both available, but reading them programmatically is very costly. In addition only 14 bits is available from each word of program memory. 3. The hardware stack is both limited in size (8 levels deep) and visibility (as in invisible). Confined in this environment we need to figure out a threading model to implement. Brad Rodriguez outlines several techniques in his moving forth article: http://www.zetetics.com/bj/papers/moving1.htm Here's a brief recap: 1. Indirect threading (ITC): code is a list of addresses that point to addresses of the target code to execute. 2. Direct threading (DTC): code is a list of addresses that points to code that jumps/calls the target code to execute. It's about the same as ITC but removes one level of indirection. 3. Subroutine threading (STC): code is a set of subroutine calls. Uses the hardware stack to manage movement. 4. Token Threading (TTC): code is a token. The token is then used to look up the address of the code to execute. Let's evaluate the efficacy of each relative to the pic's constraints. Ordered from worst to first: worst: STC. The pic simply doesn't have the hardware stack to support it. ok: ITC. extracting address from the pic's program memory is costly. Having to do it on two levels of indirection is even more so. better: DTC. Halves the cost of fetching the address. Jump instruction is one cell and executes quickly. best: TTC. Facilitates fast fetching of tokens. PIC has support for fast jump tables. Far more efficient than ITC or DTC. It's interesting that Brad calls TTC the slowest of the bunch. But in the case of a PIC where fetching program memory programmatically is close to 20 instruction cycles, TTC runs rings around both DTC and ITC. I already have a similar scheme implemented for fetching bytecodes in my NPCI virtual machine interpreter. Fundamentally each byte is encoded into a pic RETLW instruction. By using the PCLATCH/PCL it's possible to do a computed goto to any instruction in the address space. So it looks like TTC with jump tables is the winner. BAJ |
|
|
|
|
2
20th October 14:10
External User
Posts: 1
|
As you have seen, so much depends on the specific machine architecture.
We implemented a TTC Forth on some low-end AVR processors with very limited code space, and it ran faster than a native-code 8051 at comparable clock speed. Indeed. Although your extremely limited RAM is still going to be a headache. Tell us again why you love the PIC16? ;-) Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310-491-3356 5155 W. Rosecrans Ave. #1018 Fax: +1 310-978-9454 Hawthorne, CA 90250 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ================================================== |
|
|
3
20th October 14:10
External User
Posts: 1
|
There's also bit threading, where a bit in the execution token
determines whether it is a primitive or a compiled word. ENTER is then built into the token fetch process launched by NEXT when the next token is a compiled word, while EXIT is one of the primitives. When I started out on Forth on a C64, 16Kbytes (8Kwords with 16-bit addressing) was ample for a full Forth interpreter/compiler including dictionary, so with headerless code in the PIC, 13 bits available to contain compiled word addresses should be sufficient. A project that looks at the Minimal Forth question is MAF, which is defined in Forth. http://www.figuk.plus.com/fame.htm "Chris Jakeman The editor of Forthwrite has published two applications: FoSM ... MAF MAF is a minimal ANS Forth. It is written as an educational tool for anyone planning to implement a Forth and includes extensive documentation. MAF builds itself from a small kernel of 48 words and provides all the words from the Core word set together with 25 from extension word sets which are used in the building process. MAF is also portable in confining the key decisions, such as dictionary mechanism, cell size etc., to the kernel, which is detachable. The kernel supplied is implemented in ANS Forth (so that MAF is ready to run) and intended to be replaced by an equivalent kernel in Assembler or C. Download MAF" ftp://ftp.taygeta.com/pub/Forth/Appl...NS/maf1v02.zip |
|
|
6
20th October 14:10
External User
Posts: 1
|
Hmmm. I'll have to think on that one.
That's good to know. I downloaded it a couple of days ago during my research. I still didn't get the feeling that it factored out the primatives as effectively as I would like. What I'm really looking for is a specification for a set of primative words without a implementation attached. Since all of these forths are real, they necessarily bind to a particular architecture. I'm kind of looking for the C++ equivalent of an abstract class that has the specification without implmentation. On a second read just now, the primatives make more sense. It's still a bit conflicting to me because the primatives are in fact implemented in Forth. Also I still don't get the feel of a minimally implemented kernel. I guess Jim Lewis set kind of a standard in my mind with his nanoforth site: http://www.quirkle.com/misc/forth.htm I know it's incomplete. I also know that a critical subset of words haven't been implemented in it. But I'd be real happy to find something that has a complete description in the same flavor as his page. I would in fact prefer something that wasn't implemented because it actually clutters the concept. 48 words. Ouch! When bootstrapping the primitives are critical. You know what maybe I should try a different approach. I'll start another episode with it. Thanks for the pointer. BAJ |
|
|
8
20th October 14:11
External User
Posts: 1
|
Interesting. We've done some commercial work on vending machines (for a
company in Tennessee), including an MDB protocol implementation and support for payment by cash or smart cards. 8051's are the most common part used for this. Well, I'd squeeze stacks down to 32 cells, allow a little for variables and use the rest for testing definitions. Or use a part with more ram during development and a smaller one for the production units. Actually, I'd use a different MCU ;-) And a good goal, too, but I really don't see getting a really good development environment on such a limited chip. Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310-491-3356 5155 W. Rosecrans Ave. #1018 Fax: +1 310-978-9454 Hawthorne, CA 90250 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ================================================== |
|
|
10
20th October 14:11
External User
Posts: 1
|
MPE did a vending machine project as a rescue job for a client.
The previous consultancy failed in 2.5 years. MPE delivered a much more comprehensive embedded system and ... and ... in under nine months. The previous consultancy was using PICs. If the volumes are less than (say) 10k per annum, the cost of writing software vastly exceeds the cost of the MCU. A slightly more capable and expensive MCU can save time and money. Stephen -- Stephen Pelc, stephenXXX@mpeforth.com MicroProcessor Engineering Ltd - More Real, Less Time 133 Hill Lane, Southampton SO15 5AF, England tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 web: http://www.mpeforth.com - free VFX Forth downloads |
|