[ | smalltalk dot org ].
Community and industry meet inventing the future.
MicroSeeker PIC/Smalltalk by Hylands Underwater Vehicles

PIC/Smalltalk allows one to write code for the PIC microcontroller in Smalltalk (or at least something that looks like Smalltalk), and then translate it to assembler.

This is an embedded version of Smalltalk that allows you to create Smalltalk based software for devices with tiny computing resources. The development environment is the Squeak Smalltalk! Essentially MicroSeeker PIC/Smalltalk is a cross platform development environment for embedded applications. The clairity of the system is remarkable for what it accomplishes. Leaveraging a full Smalltalk as it's development environment is a move that enabled fast development without the need to build an entire Smalltalk, yet there are a number of nice extensions to Squeak that support and ease the cross platform aspects.

Why bother? Well, the real project I'm working on is to build a fairly complex autonomous underwater vehicle (AUV), called Micro Seeker. This sub will use PIC microcontrollers for brains, and the language used to program a PIC is pretty annoying to use, given that I've been using Smalltalk for over twelve years now. I've kind of gotten used to Smalltalk...

So, I decided to see if I could do something similar to what Squeak does for its VM, and write code in a Smalltalk-like syntax that is translated into assembler source code, and then assembled and run on the end platform.

Here's a nice picture of the sub sitting on the surface after a run. It is slightly unbalanced, listing in the back and being too buoyant in the front, but not too bad overall. You can see the new 6" two-bladed propeller I am using, which has twice the pitch (4" versus 2") of my old three-bladed propeller. With this new propeller, the sub goes twice as fast, clocking about two feet per second.

Resources
MicroSeeker PIC/Smalltalk home
MicroSeeker Pool Test 20040901

MicroSeeker PIC/Smalltalk Example

First, here's the Smalltalk code, the method processServo in class PICServoInterface:


processServos
"Process the servo. Basically, servos work using pulse-width modulation, where the frequency is about 50 Hz, and the duty cycle determines the servo position. The duty cycle should be between approximately 1000 and 2000 micro-seconds, although different servos may require different duty cylces. These ones in particular have a duty cycle between about 690 and 1690 us."

     "Turn on the port to start with, and wait the initial 1 ms."

     ServoPort setBit: Servo1Pin.
     self servoDelay: 195.

     "Now count down, doing a comparison on each interation.
     When the count is equal to the servo's position, turn off the port."

     servoCounter := 250.
     [
           self clearWatchdogTimer.
           servoCounter = servoOnePosition ifTrue: [
               ServoPort clearBit: Servo1Pin
          ]
     ] repeatWhile: [
          servoCounter decrementSkipIfZero
     ].

     ServoPort clearBit: Servo1Pin

And now, the PIC assembler produced:

; ==========================================
; = processServos
; ==========================================
processServos	equ	*
	bsf	ServoPort, Servo1Pin
; Generating call to 'servoDelay:'
	movlw	195
; Pushing WReg (next two instructions)...
	decf	indirectAddressLatch
	movwf	indirect
	call	servoDelay
; Popping (and ignoring) 1 variable from the stack...
	incf	indirectAddressLatch
	movlw	250
	movwf	servoCounter
Label_00	equ	*
	clrwdt
	movfw	servoOnePosition, w
	xorwf	servoCounter, w
	btfsc	status, Zero
	bcf	ServoPort, Servo1Pin
	decfsz	servoCounter
	goto	Label_00
	bcf	ServoPort, Servo1Pin
	return

Copyright 1999-2010 by Smalltalk.org™, All Rights Reserved.
Sunday
May 19 2013
Travel Adventure

Costa Rica

El Salvador

Guatemala

Honduras

Panama

Enjoy a tropical vacation in the sun, surf, in the jungle for adventure, yoga and massage for relaxation or learn the culture, history and langauge. Visit, live, work, play, retire. Enjoy.

Central America
Interoperate.org, the place to find out how to interoperate.
Google
Web
Smalltalk.org

64bits.net AMD64, Intel Pentium EM64T, Intel Itanium
Meet other Smalltalk people, contribute, learn, earn.
lingoize.me
On speaking languages
naturally with ease
aiming for fluid fluency.