Reputation: 1
I want to control the movement of a servo using Bascom 8051 continuously so that it could change positions.
I've tried using brute force by assigning the pulse length manually and changing it after a certain delay.
P1.2 = 1
Config Servos = 1 , Servo1 = P1.2 , Reload = 10
Enable Interrupts
Do
Servo1 = 15 '90 degrees to the left
Wait 10
Servo1 = 65 '90 degrees to the right
Wait 10
Loop
End
I expect the servo to switch positions back and forth but all it does is stuck in one place.
Upvotes: 0
Views: 270
Reputation: 12673
There are two different BASCOM variants, depending on your microcontroller. You have tagged both so it is not clear which one you mean. Also you didn't tell us which servo you are using.
Anyway, the inner workings are similar enough to try to answer your question.
First we need to understand which kind of signal a standard R/C servo expects. The servo position is coded in the width of a (positive) pulse. It ranges from 1 ms to 2 ms. This pulse has to be repeated every 20 ms that is a repetition frequency of 50 Hz.
With Config Servos
you set up a timer as an interrupt source and its service routine. That means that the pulses for the servo(s) are generated automatically without any further action by your main program. You just need to set the desired pulse width in the assigned variable; this actually depends on the BASCOM variant. For AVR its an array Servo(1) = #
and for 8051 there are individual variables Servo1 = #
.
According to the manual(s) the parameter Reload
sest the resolution in µs of the values for the pulse width. You chose 10.
So for the range of pulse widths you need to assign values between 100 and 200 to the servo variable:
Do
Servo1 = 100
Wait 10
Servo1 = 200
Wait 10
Loop
Additional note: The manual for BASCOM AVR mentions the port mode to set. The pin used for the pulse has to be made an output.
Upvotes: 0