Download presentation
Published byWilliam Pearson Modified over 9 years ago
1
328eForth for Arduino Uno C. H. Ting February 16, 2012 SVFIG
2
Summary Optimized FORTH for Arduino Uno ATmega328P
Assembly Code of 328eForth AVR Studio 4 Tool Suite Assembling 328eForth HyperTerminal Demo of 328eForth Optimized Flash Programming Conclusion
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
Assembly Code of 328eForth
Reset and interrupt vectors Assembly macros Kernel of primitive commands Compound commands Common utilities Interpreter Compiler Programming tools RAM memory CPU and IO registers System Variable Buffers and stacks
6
AVR Studio 4 Tool Suite AVR Assembler 2 AVR Simulator 2
In System Programming with AVRISP mkll Configuration of Atmega328 chip
7
Assembling 328eForth Assembling by AVR Assembler 2
Simulating by AVR Simulator 2 In System Programming with AVRISP mkll Running 328eForth from HyperTerminal
8
HyperTerminal Arduino 0022 supplies USB to UART driver
19,200 Baud, 8 data bits, 1 stop bit, no parity, no flow control 900 ms delay after sending each line of text Send Text File option to download file to Uno
9
Demo of 328eForth Turn LED on and off HEX
20 24 C! ;set Pin 13 as output 20 23 C! ;toggle Pin 13 Turn beeper on and off 40 2A C! ;set Pin 6 as output 42 44 C! ;set Timer0 CTC mode FF 47 C! ;maximum count for Timer0 3 45 C! ;prescaler=3, start beeper 0 45 C! ;prescaler=0, stop beeper
10
Demo of 328eForth HEX : TEST1 1 2 3 4 5 ; : TEST2 IF 1 ELSE 2 THEN . ;
: TEST3 10 FOR . NEXT ; : TEST4 CR .” HELLO, WORLD!” ; : TEST5 FOR FFFF FOR NEXT NEXT ;
11
Optimized Flash Programming
Flash memory in ATmega328 can endure 10,000 programming cycles. Flash programming must be optimized. Two 128 byte buffers are allocated to store data before writing into flash memory. Ping-Pong algorithm minimizes flash programming.
12
Ping-Pong Algorithm for Read
If data is in New Buffer, go to 6. If data is in Old Buffer, go to 5. If Old Buffer was modified, write data to flash Fill Old Buffer with new data from flash Switch New and Old Buffers. Read data from New Buffer.
13
Ping-Pong Algorithm for Write
If address is in New Buffer, go to 6. If address is in Old Buffer, go to 5. If Old Buffer was modified, write data to flash Fill Old Buffer with new data from flash Switch New and Old Buffers. Write data to New Buffer and mark it as modified.
14
Conclusion ISP is very pleasing.
Ping-pong flash buffers optimize flash programming. 2.1 us per empty FOR-NEXT loop at 16 MHz. ATmega328P is forced to be compatible with eForth.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.