Please, if you like the site visit our sponsors. Thanks.
PIC/Smalltalk
| Last Updated (Sunday, 14 February 2010 19:18) | | | Written by Administrator | | | Monday, 24 March 2008 22:46 |
FAQs - Frameworks, Platforms & Tools
More ...
PIC/Smalltalk allows to write code for the PIC microcontroller in Smalltalk and then translate it to assembler.
The real project behind this tool 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. So, the decision was to 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.
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
For more information and source please go to the official site.
| < Prev | Next > |
|---|




