'Description : 3 x Switch operated servo driver 'Circuit : ServoDvr x 3 12F510.ckt 'Target PIC : 12F683 'Program : 2048 words 'SRAM : 128 'EEPROM : 256 'Compiler : OshonSoft '***************************************************************** 'Configuration 'Set in options menu of Pic10 Simulator Define CONFIG = 0x30d4 'Configuration Registers - Not relevant registers are not listed 'Option Register 'Enable PullUps bit 7 = 0 'Enable PullUps OPTION_REG.7 = 0 'Enable PullUps on pins 3-5 'Pin 3 automatically assigns PullUp when set to IO instat of MCLR WPU.4 = 1 WPU.5 = 1 'No Analog Inputs ANSEL.0 = 0 ANSEL.1 = 0 ANSEL.2 = 0 ANSEL.3 = 0 '---------------------------------------------------------------- 'Ports - 1 is INPUT TRISIO.0 = 0 TRISIO.1 = 0 TRISIO.2 = 0 'GP3 is INPUT TRISIO.4 = 1 TRISIO.5 = 1 '***************************************************************************** 'Program comments 'Simple servo operation, direction by debounced switch 'No setting - spring in the tortise style servo holder deals with variations 'From servo tester 70 - 230 range, 100 and 200 are the limits for servo end points 'ServoOut range is 100 - 200 'This makes the ServoOut travel end points 140 & 175 'Originally for Pic 12F510, but 510 does not have PullUp on all pins '12F683 has all pins programmable PullUp except GP3 which is input and 'automatically has PullUp allocated 'Instructions 202 'Loop Time 400 uSec '**************************************************************************** 'Configure Pins 'Symbols Symbol SwA = GP5 Symbol SwB = GP4 Symbol SwC = GP3 Symbol ServoA = GP0 Symbol ServoB = GP1 Symbol ServoC = GP2 'Variables 'Debounce Dim dbSwA As Byte Dim dbSwB As Byte Dim dbSwC As Byte 'Direction stuff Dim DirNowA As Bit Dim DirNowB As Bit Dim DirNowC As Bit Dim DirNewA As Bit Dim DirNewB As Bit Dim DirNewC As Bit Dim DirA As Bit Dim DirB As Bit Dim DirC As Bit 'Counters Dim i As Byte 'Constants 'Servo settings - in uSec 'Frame is 50Hz = 1,000,000/50 = 20,000 uSec Dim Frame As Word Frame = 20000 'Number of frames to move Dim MoveFrames As Byte MoveFrames = 30 'Thru is 1ms = 1,000uSec Dim ThruOn As Word ThruOn = 1000 Dim ThruOff As Word ThruOff = Frame - ThruOn 'Divert = 2ms = 2,000 uSec Dim DivertOn As Word DivertOn = 2000 Dim DivertOff As Word DivertOff = Frame - DivertOn Dim RevA As Bit Dim RevB As Bit Dim RevC As Bit '**************************************************************************** 'Startup RevA = 0 RevB = 0 RevC = 0 '**************************************************************************** 'Main Loop main_loop: 'Debounce switches & move servos 'Switch A/Servo A 'Debounce switch 'Set db_switch to 127 dbSwA = 127 While dbSwA <> 0 And dbSwA <> 255 'Shift db_switch left dbSwA = ShiftLeft(dbSwA, 1) 'Add current switch status dbSwA.0 = SwA Wend 'Set dir_cmd If dbSwA = 0 Then DirNewA = 0 Else DirNewA = 1 Endif 'Move Servo If DirNowA <> DirNewA Then 'Move servo THRU 'Set direction adjustment If RevA = 1 And DirNowA = 0 Then DirA = 1 Endif If RevA = 1 And DirNowA = 1 Then DirA = 0 Endif If DirA = 0 Then For i = 1 To MoveFrames 'Turn servo on ServoA = 1 'Wait for thru_on WaitUs ThruOn 'Servo OFF ServoA = 0 'Wait thru_off WaitUs ThruOff Next i Else 'Move servo divert For i = 1 To MoveFrames 'Turn servo on ServoA = 1 'Wait for divert_on WaitUs DivertOn 'Servo OFF ServoA = 0 'Wait divert_off WaitUs DivertOff Next i Endif 'Reset dir_now DirNowA = DirNewA Endif '--------------------------------------- 'Switch B/Servo B 'Debounce switch 'Set db_switch to 127 dbSwB = 127 While dbSwB <> 0 And dbSwB <> 255 'Shift db_switch left dbSwB = ShiftLeft(dbSwB, 1) 'Add current switch status dbSwB.0 = SwB Wend 'Set dir_cmd If dbSwB = 0 Then DirNewB = 0 Else DirNewB = 1 Endif 'Move Servo 'Set direction adjustment If RevB = 1 And DirNewB = 0 Then DirB = 1 Endif If RevB = 1 And DirNewB = 1 Then DirB = 0 Endif If DirNowB <> DirNewB Then 'Move servo THRU If DirB = 0 Then For i = 1 To MoveFrames 'Turn servo on ServoB = 1 'Wait for thru_on WaitUs ThruOn 'Servo OFF ServoB = 0 'Wait thru_off WaitUs ThruOff Next i Else 'Move servo divert For i = 1 To MoveFrames 'Turn servo on ServoB = 1 'Wait for divert_on WaitUs DivertOn 'Servo OFF ServoB = 0 'Wait divert_off WaitUs DivertOff Next i Endif 'Reset dir_now DirNowB = DirNewB Endif '--------------------------------------- 'Switch C/Servo C 'Debounce switch 'Set db_switch to 127 dbSwC = 127 While dbSwC <> 0 And dbSwC <> 255 'Shift db_switch left dbSwC = ShiftLeft(dbSwC, 1) 'Add current switch status dbSwC.0 = SwC Wend 'Set dir_cmd If dbSwC = 0 Then DirNewC = 0 Else DirNewC = 1 Endif 'Move Servo 'Set direction adjustment If RevC = 1 And DirNewC = 0 Then DirC = 1 Endif If RevC = 1 And DirNewC = 1 Then DirC = 0 Endif If DirNowC <> DirNewC Then 'Move servo THRU If DirC = 0 Then For i = 1 To MoveFrames 'Turn servo on ServoC = 1 'Wait for thru_on WaitUs ThruOn 'Servo OFF ServoC = 0 'Wait thru_off WaitUs ThruOff Next i Else 'Move servo divert For i = 1 To MoveFrames 'Turn servo on ServoC = 1 'Wait for divert_on WaitUs DivertOn 'Servo OFF ServoC = 0 'Wait divert_off WaitUs DivertOff Next i Endif 'Reset dir_now DirNowC = DirNewC Endif '--------------------------------------- 'Back to main loop Goto main_loop '**************************************************************************** End '**************************************************************************** 'Subroutines 'No subroutines '****************************************************************************