Our resident expert on all things
robotic is merely an email away.
roboto@servomagazine.com
Tap into the sum of allhumanknowledge and get your questions answered here!
From software algorithms to material selection, Mr. Roboto strives to meet you
where you are — and what more would you expect from a complex service droid?
by
Dennis Clark
Q. I am building a robot to destroy tanks and take over the world. My largest problem is getting the solder to stick to the wires. If I could just solve
that, I’d be all set. Do you have any suggestions?
— Anonymous
A. While I’m not a big fan of military robots, even I can see the utility of a robot that can take over the world. Soldering is your first step into the world of
electronics and can be frustrating. I suggest that you get a
Weller pistol-grip soldering iron, plug it in and then open
your hand and place the glowing tip …
April Fool! Okay, that lame example is about as much
as you’ll get from me on the traditional April Fool’s jokes.
Now on to the fun stuff. I have a good variety of
questions this month; folks must be getting ready for
exams or perhaps the summer spate of robot
competitions. Let’s get started.
Q. I am embarrassed to ask, but I need your help. I do a little programming with the PIC16F84A and PIC16F877A. I am having a big problem to come
up with the code for my project which uses two servos.
I’m using a 4 MHz crystal which is divided by four to give
me 1 MHZ, then I’m using the TMR0 counter to divide by
256 which gives me 3906 Hz. What I need to do is come
up with three delays (1) 1 ms, ( 2) 1.5 ms, and ( 3) 2 ms at
a rate of 20 ms period. I have spent a lot of time trying to
accomplish this to no avail. I am using assembly code for
this project. I have looked on the Internet and all I get is
code in C or PICBasic. If you can help, I sure would
appreciate it. I am a tech not a programmer, even though
I have done a few things using this code, just not with
timing pulses. Thanks,
— Frank G.
14 SERVO 04.2011
A. It sounds like you only need to have three distinct servo pulses for your project. It really isn’t that much more difficult to have every possible servo pulse with
an eight- bit resolution in your project. I’ve done very
similar assembler code in a PIC12F508 part. Let’s look at
some code to show you some of the tools you’ll want to
know for timing pulse widths.
1mS/256 = 3.9uS
This means that with a 3. 9 µS timer clock, a full count
on (TMR0, for instance) will yield exactly 1 mS time
elapsed. Different PICs have different ways to set timer
prescales and counts though; so I’ll pick your 16F84 part
(you should step up to newer PICs though; they are easier
to work with). We never will get an exact divider from this
PIC, however. This type of PIC processor has a four stage
pipeline which means that the actual clock that the TMR0
will get is 1 MHz. This is a 1 µS clock, so we will have to
prescale our clock as a divide-by- 4 to get a 4 µS clock to
the timer. This will yield a 1.024 mS full range. Close
enough. The following code will set TMR0 up to give us
this useful timer range.
movlw 0x01
movwf OPTION_REG
; Set clock prescale Timer0
; to divide by 4
; On your part this may
; just be “OPTION”