Wednesday, October 17, 2007

Ultrasonic Sensors and Servos: Tyler-Sergio-Chie

To start, we do not have a new prototype but rather a declaration on our future endevors. We felt it was time to look at output a little closer.

We though it might be a good idea to look a little more in detail as to how we would produce output. Servos are very versetile and strong. They have the ability to apply a decent amount of force. We were thinking of taking the ultrasonic input and using the readings, which we have tested before, to produce a pulse that would go out to the servo. Click for gif animation.

The benefit which we see in using servos is similar to the flexinol wire. That is taking a component which provides a small amount of movement and multiplying it's level of output. The servo is a bit stronger and more reliable. The diagram below begins to illustrate the way in which small amount of movement can have a large effect on the final movement.
We are thinking that this amplification of movement could be used to create an interactive surface condition or piece of artwork.

I was able to find someone who had written a code for the integration of a servo and ultrasonic sensor. They had a code posted which is as follows.


status equ 0x03 ; status equate
porta equ 0x05 ; port a equate
portb equ 0x06 ; port b equate
PWM equ 0x0c ; PWM signal length
count equ 0x0d ; general register
temp equ 0x0e ; general register
loop equ 0x0f ; general register

;---------------------------------------------------------------------

c equ 0 ; status bit to check after subtraction

;---------------------------------------------------------------------
; porta0 = input from sensor
; portb3 = command to sensor
; portb0 = command to servo

org 0x000

start movlw 0x00 ; load W with 0x00 make port B output
tris portb ; port B is outputs
movlw 0xFF ; load W with 0xFF make port A input
tris porta ; port A is inputs
movlw 0x00 ; load W with 0x00 to set intial value of B
movwf portb ; set port b outputs to low
main clrf count ; clear count
clrf PWM ; clear PWM
bsf portb,3 ; tell sensor to make reading
movlw d'4' ; 4*3=12 clock delay
movwf count
call delay ; delay
bcf portb,3 ; end sensor command signal
movlw d'5' ; set the delay for measuring the output
movwf count
A0LOW btfss porta,0 ; if the output has gone high, skip the next instruction
goto A0LOW ; else check again
A0HIGH incf PWM ; increment the length of the PWM signal
call delay ; delay for the count assigned above
nop
btfsc porta,0 ; check to see if the output is still high
goto A0HIGH ; if it is, repeat
movf PWM,w ; move PWM to w
sublw d'200' ; subtract PWM cycle from 200 (2 msec)
btfsc status,c ; if PWM is greater than 200 (2 msec), skip next instruction
goto skip1
movlw d'200' ; else set the max PWM length to 200
movwf PWM
skip1 movf PWM,w ; move PWM to w
sublw d'20' ; subtract PWM cycle from 200 (2 msec)
btfss status,c ; if PWM is greater than 200 (2 msec), skip next instruction
goto skip2
movlw d'20' ; else set the min PWM length to 20
movwf PWM
skip2 movlw d'1' ; set the delay for generating the PWM
movwf count
bsf portb,0 ; start the PWM pulse
LoopPWM call delay
nop
nop
nop
decfsz PWM ; decrement the PWM length
goto LoopPWM ; as long as PWM is greater than 0, loop
bcf portb,0 ; when done looping, stop the pulse
movlw d'15' ; set the counter for generating the rest of the PWM signal
movwf loop
del15 movlw d'255' ; set the delay counter
movwf count
call delay
decfsz loop
goto del15
goto main

;----------------------------------------------------------------------

delay movf count,w ; delay loop
movwf temp
del decfsz temp ; 3 clock cycles per delay loop
goto del
return

;----------------------------------------------------------------------

end


For further reference, the we address is http://www.pages.drexel.edu/~kws23/tutorials/ultrasonic/ultrasonic.html

Labels:


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?