Presentation is loading. Please wait.

Presentation is loading. Please wait.

2012 FIG Taiwan Conference February 16, 2012 Chen-Hanson Ting

Similar presentations


Presentation on theme: "2012 FIG Taiwan Conference February 16, 2012 Chen-Hanson Ting"— Presentation transcript:

1 2012 FIG Taiwan Conference February 16, 2012 Chen-Hanson Ting
ceForth for Arduino 2012 FIG Taiwan Conference February 16, 2012 Chen-Hanson Ting

2 Summary A Native FORTH System for Arduino The Fundamental Problem
A Solution FORTH Virtual Machine FORTH Dictionary ceForth_328 Sketch ceForth Metacompiler Compiling to RAM Memory Demomonstrations

3 A Native FORTH for Arduino
A native FORTH system which can be loaded as a Arduino Sketch. Must be written in C (Arduino Process) and does not require separated AVR programmer. Attractive to beginning Arduino users.

4 Arduino Uno with AVRISP mkll

5 Arduino Uno Alone

6 The Fundamental Problem
ATmega328P is a microcontroller of Harvard Architecture with separated program and data space. C is a programming language of Harvard Architecture with hidden program space. FORTH is a programming language of Princeton Architecture, with unified program and data space. How to force a Princeton Architecture on a Harvard Architecture computer?

7 A Solution A FORTH Virtual Machine programmed in C.
A FORTH dictionary constructed by F# and imported into the C program as a data array. The dictionary can be extended into the RAM space so FORTH can grow.

8 FORTH Virtual Machine 33 Pseudo instructions as byte codes.
Pseudo instructions can be stored either in program or data memory. A Finite State Machine to execute pseudo instructions.

9 FORTH Virtual Machine A unified memory model spanning both program and data space. Program and data are mapped to different areas in the memory space. FORTH dictionary is initially loaded in program memory, but can be extended into data memory.

10 Finite State Machine void setup()
{ clock = 0; phase = 0; P = 0; IP = 0; S = stack; R = rack; top = 0; } void loop() { phase = clock & 3; switch(phase) { case 0: fetch_decode(); break; case 1: execute(I1); break; case 2: execute(I2); break; case 3: jump(); break; } clock += 1; }

11 FORTH Dictionary FORTH commands are records linked into a dictionary.
A command record has a link field, a name field and a code field. A primitive command has pseudo instructions in code field. A compound command has a token list in code field.

12 Primitive Commands void drop(void) { pop; }
void dup(void) { *++S = top; } void swap(void) { w = top; top = *S; *S = w; } void over(void) { push S[-1]; } void zless(void) { top = (top & 0X8000) LOGICAL ; } void andd(void) { top &= *S--; } void orr(void) { top |= *S--; } void xorr(void) { top ^= *S--; } void uplus(void) { *S += top; top = LOWER(*S, top) ; } void nop(void) { jump(); }

13 Compound Commands Compound commands are produced by ceForth_328 metacompiler as lists of execution addresses.

14 ceForth_328 Sketch Pseudo instructions coded in C.
Finite State Machine coded in C. A dictionary imported as a data array. The dictionary is produced by ceForth_328 metacompiler.

15 ceForth_328 Memory Space 0000-00FF ATmega328 registers
FF Data space assigned by C F FORTH variables F Free space for dictionary FF TIB/ATmega328 stack 0900-1FFF Dictionary in flash memory

16 cefMETA328 Metacompiler All files compiled by cefMETA328.fex under F#
cefMETA328.f Metacompiler cefASM328.f Assembler cefKERN328.f Kernel commands cEF328.f Compound commands cefSIM328.f Simulator

17 Compiling to RAM Memory
ATmega328 has only 2 KB of RAM memory. Only small applications can be compiled. The application code cannot be saved to the flash memory. It is still very useful with the PEEK and POKE capability. It is a very good tool to learn about the ATmega328 Microcontroller.

18 Demonstrations Compile ceForth328.pde under Arduino 0022 system.
Upload ceForth328 to Arduino HyperTerminal interaction Demonstrations Blink LED Tone generator Servo motors


Download ppt "2012 FIG Taiwan Conference February 16, 2012 Chen-Hanson Ting"

Similar presentations


Ads by Google