Action
Configures how much servo’s will be controlled.
Syntax
CONFIG SERVOS = X , Servo1 = Portb.0 , Servo2 = Portb.1 , Reload = rl
Remarks
Servo’s need a variable pulse in order to operate. The CONFIG SERVOS directive will set up a byte array with the servo pulse width values and will initialize an ISR that uses TIMER0.
X |
The number of servo’s you want to control. Each used servo will use one byte of SRAM. |
PORT |
The port pin the servo is attached too. |
RL |
The reload value for the ISR in uS. |
When you use for example :
Config Servos = 2 , Servo1 = Portb.0 , Servo2 = Portb.1 , Reload = 10
The internal ISR will execute every 10 uS.
An arrays named SERVO() will be created and it can hold 2 bytes : servo(1) and servo(2).
By setting the value of the servo() array you control how long the positive pulse will last. After it has reached this value it will be reset to 0.
The reload value should be set to 10. After 20 mS, a new pulse will be generated.
You can use other reload values but it will also mean that the repeat value will change.
The PORT pins specified must be set to work as an output pin by the user.
CONFIG PINB.0 = OUTPUT
Will set a pin to output mode.
Resources used
TIMER0 is used to create the ISR.
ASM
NONE
Example
'-----------------------------------------------------------------------------------------
'name : servos.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : demonstrates the SERVO option
'micro : 90S2313
'suited for demo : yes
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
$regfile = "2313def.dat" ' specify the used micro
$crystal = 4000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
'Servo's need a pulse in order to operate
'with the config statement CONFIG SERVOS we can specify how many servo's we
'will use and which port pins are used
'A maximum of 14 servos might be used
'The SERVO statements use one byte for an interrupt counter and the TIMER0
'This means that you can not use TIMER0 anymore
'The reload value specifies the interval of the timer in uS
'Config Servos = 2 , Servo1 = Portb.0 , Servo2 = Portb.1 , Reload = 10
Config Servos = 1 , Servo1 = Portb.0 , Reload = 10
'as an option you can use TIMER1
'Config Servos = 2 , Servo1 = Portb.0 , Servo2 = Portb.1 , Reload = 10 , Timer = Timer1
'we use 2 servos with 10 uS resolution(steps)
'we must configure the port pins used to act as output
Config Portb = Output
'finally we must turn on the global interrupt
Enable Interrupts
'the servo() array is created automatic. You can used it to set the
'time the servo must be on
Servo(1) = 10 '10 times 10 = 100 uS on
'Servo(2) = 20 '20 times 10 = 200 uS on
Do
Loop
Dim I As Byte
Do
For I = 0 To 100
Servo(1) = I
Waitms 1000
Next
For I = 100 To 0 Step -1
' Servo(1) = I
Waitms 1000
Next
Loop
End