[chbot] ADC on the DSPic
Carl Ranson
chchrobotics@lists.linuxnut.co.nz
Sun, 24 Sep 2006 22:58:10 +1200
I'm tying to use AN4-AN7 as the analog input pins. I don't need fast
sampling so I though i'd set it up to cycle through those pins for
channel 0 rather than try to set up all 4 ADC channels.
paraphrasing what the VDI generated...
; B15:0=CSSL15:0
ADCSSL = 0x00F0
; B15:14=CH123NB1:0 B13=CH123SB B12=CH0NB B11:8=CH0SB3:0
; B7:6=CH123NA1:0 B5=CH123SA B4=CH0NA B3:0=CH0SA3:0
ADCHS = 0x0004
; B15:0=PCFG15:0
ADPCFG = 0x010F
; B12:8=SAMC4:0 B7=ADRC B5:0=ADCS5:0
ADCON3 = 0x0001
; B15:13=VCFG2:0 B12=OFFCAL B10=CSCNA B9:8=CHPS1:0
; B7=BUFS B5:2=SMPI B1=BUFM B0=ALTS
ADCON2 = 0x0400
; B15=ADON B13=ADSIDL B12=ADSTBY B9:8=FORM
; B7:5=SSRC B3=SIMSAM B2=ASAM B1=SAMP B0=CONV
ADCON1 = 0x8000
My understanding from the documents is that this will scan the pins
specified by ADCSSL (An4-An7) on sucessive samples using CH0.
To sample I'm using the simplest technique I can find which is
// start sampling ...
ADCON1bits.SAMP = 1;
// wait for a bit...should be well over 100ms (i think)
K_Task_Wait(50);
// start Converting
ADCON1bits.SAMP = 0;
// conversion done?
while (!ADCON1bits.DONE);
value = ADCBUF0; // yes then get ADC value
I probably just need to come back to it tomorrow and re-read the specs
Cheers,
CR
Michael Pearce wrote:
>What 4 ADC channels are you using? RA0 to RA3 ?
>
>Are you using external reference or just Vdd?
>
>I will have a look tommorrow when I get some time.
>
>Mike
>
>On Sunday 24 September 2006 20:26, Carl Ranson 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?
>>Ta.
>>C
>>
>>_______________________________________________
>>Chchrobotics mailing list
>>Chchrobotics@lists.linuxnut.co.nz
>>http://lists.ourshack.com/mailman/listinfo/chchrobotics
>>
>>
>
>
>