PDA

View Full Version : Servos not serving



queenidog
- 4th May 2015, 18:53
I have two servos running off a 16F887 with no issues. Both toggle back and forth at roughly a 90 degree angle, in about 2 seconds.

I changed commands for a 12F675, mounted same on a prototype board with hefty 5 volt power supply/converter. With one servo connected (to GP1), everything is fine. With TWO connected, it's as if the time period was extended by a factor of 100: each servo does a little "tick" in about 1 second: at that rate, it will take 10 minutes or more to swing 90 degrees. Not only that but there is chattering where they can suddenly move 10 degrees. If I swap servos, same thing occurs. There is NO voltage drop on the MCU or servos when #2 is added. There is no NOISE on the power lines. Different servos create the same problem.

On a scope I cannot see any change whatsoever. The pulses are there, varying 1.0 to about 1.5 mS, and the overall period is 20 mS. (It's a little lower, frequency is about 65 Hz instead of 50 Hz). The program is attached for the 12F675. Even when the servos are chattering, the waveforms look okay.

Am I missing something? Is this a software or a hardware (ie MCU) problem?

Demon
- 4th May 2015, 19:59
Did you make sure the combined current is not too much?

Robert

Tabsoft
- 4th May 2015, 20:12
Is your MCLR tied high?

See this link.
http://support.melabs.com/threads/1033-different-MCUs-different-results?highlight=servo

queenidog
- 4th May 2015, 21:20
When I was exercising I was thinking of my problem, checked the spec sheet but saw that GPIO can handle 25 mA each, total 125 mA for all I/O. I was way below that with two servos.

After more checking, I was shocked to see that NOW, neither of my servos worked, so programmed the chip again with (apparently) no problems, except servos no work. Checked power: 12 volts onto board, 7.3 volts coming off 5 volt regulator! Geez. Don't know why I blew a regulator. It's a heat-sunk T0-220, all my circuitry checks out as not having shorts or anything and my 5 volt regulator never got hot.

So I popped the 12F675 into my MikroElektronika Easy Pic V7, programmed the chip: didn't work. Threw the chip out, put in a new one and all is well: both servos work as specified.

Thanks Tabsoft for pointing out my earlier question, same problem, 6 months ago. I'm losing it. BTW, MCLR is tied high through a 10K resistor. I will investigate WHY my circuit doesn't work.



Obviously my prototype board - which I designed, built, and populated - is not...done right. Mea Culpa.

Thanks for those who responded.

Acetronics2
- 4th May 2015, 22:18
may be just try this one ...



' Name : ServosDumpTruck675X3.pbp
' Compiler : PICBASIC PRO Compiler 3.074
' Development PIC : 40-pin 16F887
' Target PIC : 12F675 8 pin
' Hardware : Mikro Elektronika EasyPic V7
' Oscillator : 4MHz internal clock
' Keywords : servo, dump truck, X3
' Description : PICBASIC PRO program for control of 3 (or more) servos

#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _BODEN_ON
#ENDCONFIG

DEFINE OSC 4
DEFINE OSCCAL_1K 1

'****Aliases*****
servo1 Var GPIO.1 ' Alias servo pin
servo2 var GPIO.2
servo3 var GPIO.4 ' can't use gp3...input only.


'***Constants and Variables ***
PWCCW con 120 'CCW Pulse Width: 100 mS * 4 Mhz period (10uS)=1.0mS def 100
PWCW con 240 'CW pulse width: 200 mS * 10uS=2.0 mS def 200
Refresh con 20 '20 mS refresh= 50 Hz
pulse var byte


'****Initialize****

ADCON0 = 0
ansel = 0 'all digital i/o
cmcon=%00000111 'turn off comparators
GPIO = 0
trisio = %00001000

' Low Servo1 ' Initialize servos
' Low Servo2
' low servo3

'****Main Program****
Start:

For Pulse= PWCW TO PWCCW STEP -1

Low Servo1
PulsOut servo1,pulse
Low Servo2
pulsout servo2,pulse
Low Servo3
pulsout servo3,pulse

Pause Refresh - pulse - pulse - pulse

next pulse


for Pulse= PWCCW TO PWCW step 1

Low Servo1
PulsOut servo1,Pulse
Low Servo2
pulsout servo2,pulse
Low Servo3
pulsout servo3,pulse

Pause Refresh - pulse - pulse - pulse

next pulse

goto Start


NOW ...

1) be sure your servos supply can hold ... 3 Amps short peaks ( not a typo !!! ) ... the EP7 7805 looks a bit weak for that !!!

2) see where the LOW commands have to be placed.

3) your " pause refresh " value looked a bit strange ...

Alain

Tabsoft
- 4th May 2015, 23:50
Alain,

I guess I'm missing something in your "Pause Refresh - Pulse - Pulse - Pulse" statement.
The "Pause" amount for loop # 1 will be "20 - 240 - 240 - 240 = 68ms"
For loop #2 it will be "20 - 239 - 239 - 239 = 71ms"

So to turn 90deg it will take 15.16 seconds?
Is this right?



Total Pause (ms): 15.16
Total Pause(Value): 15160

Pulse Pause
Value Value
----- -----
240 68
239 71
238 74
237 77
236 80
235 83
234 86
233 89
232 92
231 95
230 98
229 101
228 104
227 107
226 110
225 113
224 116
223 119
222 122
221 125
220 128
219 131
218 134
217 137
216 140
215 143
214 146
213 149
212 152
211 155
210 158
209 161
208 164
207 167
206 170
205 173
204 176
203 179
202 182
201 185
200 188
199 191
198 194
197 197
196 200
195 203
194 206
193 209
192 212
191 215
190 218
189 221
188 224
187 227
186 230
185 233
184 236
183 239
182 242
181 245
180 248
179 251
178 254
177 1
176 4
175 7
174 10
173 13
172 16
171 19
170 22
169 25
168 28
167 31
166 34
165 37
164 40
163 43
162 46
161 49
160 52
159 55
158 58
157 61
156 64
155 67
154 70
153 73
152 76
151 79
150 82
149 85
148 88
147 91
146 94
145 97
144 100
143 103
142 106
141 109
140 112
139 115
138 118
137 121
136 124
135 127
134 130
133 133
132 136
131 139
130 142
129 145
128 148
127 151
126 154
125 157
124 160
123 163
122 166
121 169
120 172

Acetronics2
- 5th May 2015, 13:31
Alain,

I guess I'm missing something in your "Pause Refresh - Pulse - Pulse - Pulse" statement.


you're right ! I missed time scaling :wink:

should be


Pause Refresh - ((pulse + pulse + pulse)/100)


note Refresh could simply be 15ms ( as precise 50 Hz repeating signal is not compulsory - only the 1.2 - 2.4 ms "1" level - )

your travel time will simply be ...

(240-120)* 20ms = 2.4 seconds ...

queenidog
- 5th May 2015, 20:36
Just wanted to say thanks to all for your insightful comments and programming hints. I printed off the stuff for later perusal and comparison to my program. I'm a "minimalist", I program with the least amount of code required (thus don't always initialize) and even build circuits with low parts counts. That's where I get into trouble...

Thanks again.

Tabsoft
- 6th May 2015, 03:12
If you want the duty cycle to be as close to 50Hz you can do this to account for the Pulsout statements, Low xx statements, For/next logic and the Pause statement.

Change the Refresh constant value to 20000 'microseconds

Then use this for the pause.

Pauseus Refresh - (((pulse + pulse) + (pulse / 3)) * 10)

This should keep the total duty cycle time to 20ms +/- (~100) microseconds.

Dave
- 6th May 2015, 11:48
Queenidog, Here is a program I wrote some time ago for a couple of kids to test some servos for there robot in the FIRST competition. It is a minimalist program I wrote during lunch one day. It might help. Oh I forgot, Also attached is a schematic I updated a couple of years ago. Enjoy...