Hi, Glenn
I Think I've found what looks "strange" to you ...
This is not the "perfect movement" ... but the maximum to get from this coding style.Code:@ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_ON,PROTECT_OFF DEFINE OSC 4 CMCON = 7 ' Disable comparators PORTA = %00000011 PORTB = 0 TRISA = %00000011 TRISB = 0 'Use b1 to hold pulse width variable for servo 1 b1 var WORD 'initialize variables b1 = 150 << 4 low portb.0 ' put the servoport low. main: low portb.0 pulsout portb.0, ( b1 >> 4 ) 'send current servo 1 position out if porta.0 = 0 then left1 'check for pressed switch 0 if porta.1 = 0 then right1 'check for pressed switch 1 bugtrap: if b1 > ( 150 << 4 ) then b1 = b1 - 1 else if b1 < ( 150 << 4 ) then b1 = b1 + 1 endif pause 18 : goto main left1: IF porta.1 = 0 Then bugtrap b1 = b1 + 1 if b1 > ( 3199 ) then max1 Pause 8 : goto main right1: IF Porta.0 = 0 Then bugtrap b1 = b1 - 1 if b1 < ( 1601 ) then min1 Pause 8 : goto main max1: b1 = ( 100 << 4 ) : goto main ; jump to other side min1: b1 = ( 200 << 4 ) : goto main ; jump to other side END
Alain
PS : Question : Why multiply b1 per 16 ( << 4 ) and divide it per 16 ( >> 4 ) when outputting the pulse.
The answer to last trouble is here !!!




Bookmarks