[chbot] ADC on the DSPic
Andrew Errington
chchrobotics@lists.linuxnut.co.nz
Sun, 24 Sep 2006 22:39:46 +1200
On Sun, 24 Sep 2006 20:26, you wrote:
> So I've got one of my Sharp range sensors working with the dsPic's ADC.
> Now I'm trying to hook up all 4 and get the thing to cycle the ADC
> sampling through 4 of the pins but I cant work out how to set it up.
>
> Does anyone know how to do it?
It's tricky- but only because the ADC module is so versatile. I don't have
any code easily accessible at the moment, but I chose AN0, 1, 2, 3 and had
them all convert at the same time, with AVdd and AVss as my references.
Basically, if you trawl through the half-dozen or so configuration
registers and set them up how you *think* they should be, then it will
probably work. Later you can optimise the settings if necessary.
It's worth studying the pinout diagram of the dsPIC and the internal
circuit diagram of the ADC module, so you can choose the optimum
arrangements of which pin does what. For example, I need IC7 and IC8,
which means I cannot use AN4 and AN5 (they are on the same pins).
Originally I wanted to put three of my sensors on AN6, 7, and 8, but I
couldn't configure the ADC to do quite what I wanted with those three pins,
so I put them back onto 0, 1, and 2. This means that I can't use an
external Vref, but that's okay.
Do you have the dsPIC Family Reference Manual? It describes the ADC module
control words in detail. You can find it at
http://ww1.microchip.com/downloads/en/DeviceDoc/70046E.pdf
Section 17 is what you want, and section 17.3 shows all the bits of the
control registers. In fact, you really need this document. The
dsPIC30F3011 datasheet is a bit light in places.
You need to understand what all the control bits are doing, but I think the
key settings are:
ADCON1- SIMSAM and ASAM should be set
ADCON2- CHCS should be 1x
ADPCFG- Make sure you turn on the pins you are using for input
ADCSSL- Make sure the inputs are included in the scanning.
Actually, I'm not sure about the scanning. I think if you are using
AN0,1,2,3 you can convert them all at the same time, so you are not
scanning. Anyway, I have it working, so I'll dig some code out later.
If you can't get it going, tell us what ADC input pins you wish to use,
what the voltage ranges are, and what your references are. Include the
values you are writing to the six ADCON registers and we'll try and pick it
apart. Besides, with one ADC working you've done the hard part!
Good luck!
Andrew