Presentation is loading. Please wait.

Presentation is loading. Please wait.

328eForth Workshop C. H. Ting February 16, 2012 SVFIG.

Similar presentations


Presentation on theme: "328eForth Workshop C. H. Ting February 16, 2012 SVFIG."— Presentation transcript:

1 328eForth Workshop C. H. Ting February 16, 2012 SVFIG

2 Summary Optimized FORTH for Arduino Uno ATmega328P Demonstrations
BLINK a LED TONE Generator SERVO Motors TRAFFIC Controller

3 Optimized Forth for Arduino
Subroutine Thread Model Fully optimized Uniform byte addressing Case insensitive Interpreter is in Bootloader section Optimized flash programming Visible words are reduced to 140 for ease of learning

4 ATmega328P 8 Bit microcontroller, 131 instructions 20 MIPS at 20 MHz
32KB Flash, 2 KB RAM, 1 KB EEPROM 3 Counter/Timers 6 Channels 10-bit ADC USART, SPI, I2C, ISP 23 Programmable I/O lines V

5 BLINK a LED Toggle LED HEX 20 24 C! \ make Line 13 an output pin
C! \ toggle Line 13 LED BLINK program : MS ( n -- ) FOR AFT $1CB FOR NEXT THEN NEXT ; : BLINK C! BEGIN C! 400 MS AGAIN ; FLUSH BLINK

6 TONE Generator Timer/Counter1 Setup HEX 2 24 C! \ set Line 9 as output
40 80 C! \ set CTC mode !\ init compare reg 9 81 C! \ prescaler=1, start

7 TONE Generator : /SO A000 88 ! ; : DO 77B1 88 ! ; : RE 6AAA 88 ! ;
: ME 5F07 88 ! ; : FA 59DB 88 ! ; : SO ! ; : LA ! ; : MS ( n -- ) FOR AFT $1CB FOR NEXT THEN NEXT ; : 1/4 100 MS ; : 1/2 200 MS ; : 1/8 400 MS ;

8 TONE Generator : PHRASE1 DO 1/4 RE 1/4 ME 1/4 DO 1/4 ;
: PHRASE2 ME 1/4 FA 1/4 ME 1/4 SO 1/2 ; : PHRASE3 SO 1/8 LA 1/8 SO 1/8 FA 1/8 ME 1/4 ME 1/4 DO 1/4 ; : PHRASE1 DO 1/4 /SO ¼ ME 1/4 DO 1/2 ; : SONG 2 24 C! C! C! PHRASE1 PHRASE1 PHRASE2 PHRASE2 PHRASE3 PHRASE3 PHRASE4 PHRASE4 0 81 C! ;

9 SERVO Motors Assembling by AVR Assembler 2
Simulating by AVR Simulator 2 In System Programming with AVRISP mkll Running 328eForth from HyperTerminal

10 SERVO Motors HEX : INIT-PORTS E 24 C! 68 2A C! \ OUTPUT PORTS
A3 44 C! C! \ TCCR0A, TCCR0B 18 47 C! C! \ OCR0A, OCR0B A1 80 C! D 81 C! \ TCCR1A, TCCR1B 18 88 C! 18 8A C! \ OCR1A, OCR1B A3 B0 C! 7 B1 C! \ TCCR2A, TCCR2B 18 B3 C! 18 B4 C! \ OCR2A, OCR2B ;

11 SERVO Motors : S1 ( N -- ) 88 C! ; : S2 ( N -- ) 8A C! ;
: S3 ( N -- ) B3 C! ; : S4 ( N -- ) B4 C! ; : S5 ( N -- ) 47 C! ; : S6 ( N -- ) 48 C! ; FLUSH

12 TRAFFIC Controller : init-ports fc 2a c! 3 24 c! \ output ports
3f 28 c! c 25 c! ; \ input ports, pullup : seconds for aft 100 for 400 for next next then next ; : lights ( n -- ) dup 2b c! \ PD outputs 100 / C or 25 c! ; \ PB outputs, maintain pullups : switches ( -- n ) * \ PB inputs 26 or \ PC inputs dup cr . ;

13 TRAFFIC Controller : N-S begin 104 lights 5 seconds switches c3a and
if 108 lights 2 seconds then switches a and if 130 lights 3 seconds then switches c30 and until ; : E-W begin 50 lights 5 seconds switches 82f and if 90 lights 2 seconds then switches 820 and if 310 lights 3 seconds then switches f and until ; : go init-ports begin N-S E-W ?key until drop ; flush

14 Turn Key Application Application Turn Key Burn Fuses
: go init-ports begin N-S E-W ?key until drop ; Turn Key ‘ go 100 ! 100 erase write Burn Fuses Lfuse=F2, Hfuse=D8, Efuse=FD

15 Tao of Arduino No external crystal No external reset
No current limiting resistors to drive LED’s No external pull up resistors to read sensors 2 AA batteries are sufficient for power

16 Conclusion Arduino is the best platform to teach FORTH.
ATmega328 is the simplest microcontroller for embedded applications. 328eForth is the easiest way to build applications on Arduino Uno.

17 為學日益,為道日損. 損之又損,以至於無. 為無為而無不為.
Ardunio之道 為學日益,為道日損. 損之又損,以至於無. 為無為而無不為.


Download ppt "328eForth Workshop C. H. Ting February 16, 2012 SVFIG."

Similar presentations


Ads by Google