I have been working on this for about 10 days. I am using a 16f684 and building and programming with MPLAB 8.76. I have successfully programmed the PIC to make an LED uselessly flash in whatever way that delights my fancy at that particular moment. The servo has been a different story. I have tried every piece of servo code in this forum and any other forum I could find. The servo just turns to the right(clockwise) and stops, mocking my apparent ineptitude. Please see the code below and help me fix it so that I can make this rogue servo do my bidding.
Here is a little servo test program i wrote a while back.
Maybe it would be helpful.
'Servo Test: rotates servo (in set motions) towards direction -- left or right (depending upon button press)
#chip 16F887, 4
#config INTOSC
'define the ports
DIR PORTB.3 OUT 'servo output pin
DIR PORTB.4 IN 'move left button
DIR PORTB.5 IN 'move right button
PAN = 150 '150 corresponds to 150 ms -- meaning servo will be in center position upon startup
'set all ports to be off
SET PORTB.3 OFF
SET PORTB.4 OFF
SET PORTB.5 OFF
OldPosX = 100
START:
ServoToPosition(125)
Wait 50 10ms
ServoToPosition(150)
Wait 100 10ms
ServoToPosition(180)
Wait 100 10ms
ServoToPosition(130)
Wait 100 10ms
ServoToPosition(100)
Wait 100 10ms
goto START
sub ServoToPosition(NewPosX) #NR
for i=OldPosX to NewPosX
Wait 20 ms
SET PORTB.3 ON
Wait i 10us
SET PORTB.3 OFF
next
OldPosX = NewPosX
end sub
As you will notice right away I didn't implement the idea of the buttons. so there is extra stuff in the defines.
GL
mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Mike and nobody you guys rock! My irritation has turned to joy and my joy to gratitude. Thank you. I can now continue my quest to dominate my living room with large mechanical bugs that turn when they run into something. Only my own lack of knowledge can stop me now! (Insert maniacal laugh here)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been working on this for about 10 days. I am using a 16f684 and building and programming with MPLAB 8.76. I have successfully programmed the PIC to make an LED uselessly flash in whatever way that delights my fancy at that particular moment. The servo has been a different story. I have tried every piece of servo code in this forum and any other forum I could find. The servo just turns to the right(clockwise) and stops, mocking my apparent ineptitude. Please see the code below and help me fix it so that I can make this rogue servo do my bidding.
'PIC 16F684 Servo cycler
#chip 16F684, 4
#config osc=int
#define ServoPin PORTC.4
#define ServoMin 100
#define ServoMax 200
Dir PORTC Out
Dir ServoPin Out
Do
For Temp = ServoMin to ServoMax
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
For Temp = ServoMax to ServoMin
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
Loop
From the Help file:
"If STEP is not specified, GCBASIC will increment counter by 1 each time the code is run."
Try changing "For Temp = ServoMax to ServoMin" to "For Temp = ServoMax to ServoMin Step -1"
Here is a little servo test program i wrote a while back.
Maybe it would be helpful.
As you will notice right away I didn't implement the idea of the buttons. so there is extra stuff in the defines.
GL
mike
Mike and nobody you guys rock! My irritation has turned to joy and my joy to gratitude. Thank you. I can now continue my quest to dominate my living room with large mechanical bugs that turn when they run into something. Only my own lack of knowledge can stop me now! (Insert maniacal laugh here)