Our resident expert on all things
robotic is merely an email away.
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?
Igot some questions this month that were so similar, I decided to handle them by starting with one project and building on it. This
month, we’ll be doing some mid-range PIC
microcontroller assembly language dealing with
analog-to-digital conversion (ADC), interrupts, and
controlling hobby servos. Yes, I said assembly!
You’ll see, it’ll be fun and won’t hurt at all! PIC
assembly is so simple that even you folks that
are afraid to venture from your PICBASIC PRO
compiler (which is a really good one, BTW) can
get your hands dirty with assembly and feel like
you’ve accomplished something!
There has been a lot of buzz within network
chat groups about the future of hobby robotics
lately. I’ve read quite a few opinions and
suggestions, and have submitted a couple
myself. I’d like to ask you: what keeps you
excited about hobby robotics? Conversely, what
is it that makes you hesitant about hobby
robotics? Write to SERVO with your comments. I
think this is a really good discussion topic for
the future of our hobby! Now, on with the
Q. A light level sensor project is of particular interest to me because I have been reading about ADC converters in
PICs. I would really like to see the code for a
PIC12F675 in assembly language. I want to have
a digital output from the light level sensor.
— Bill Polewarczyk
A. PICs are very easy to program in assembly and — best of all — assembly is free in MPLAB. The PIC12F675 is actually a 14-bit
core in the Microchip lineup; one of the mid-level
parts, not like the 12F509, for example. This
means that it has lots of power in that little eight-
pin package. To work with ADC converters in any
of the 14-bit PICs, you will be concerned with
three registers: ADCON0, ANSEL, and CMCON.
You will use CMCON to turn off the analog
comparitors; they will get in your way with
everything else that you want to do. Listing 1
shows you what to do with this register. The
ADCON0 register is used to turn on the ADC
hardware; select a sample channel and start an
ADC conversion. Finally, ANSEL is the register
you use to set up the ADC clock and pick the I/O
pins you’ll use for analog input. Listing 1 is the
initialization routine that gets the microcontroller
set up to do what you want it to do.
So that this project isn’t dry and
boring, I’ve added a simple output display to it;
we’ll use a 5K variable resistor to give us input.
The result of the ADC sampling will be displayed
using four LEDs that are set up to give us four-bit
binary numbers representing the relative value of
the analog input. Figure 1 has the schematic for
The first thing that you should note from the
Figure 1. Analog-to-digital PIC12F675 layout.
SERVO 12.2009 13