[chbot] ADC on the DSPic

Carl Ranson chchrobotics@lists.linuxnut.co.nz
Tue, 26 Sep 2006 20:10:37 +1200


Further info: I can read the values from the other pins if I enable one 
at a time with the ADCSSL register.
If I enable more than one of the pins, it only returns the value for the 
first one.

Ive been debugging this and can confirm that its only changing the 
ADCBuf0 register.

Carl Ranson wrote:

>
> 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
>>>   
>>
>>
>>  
>>
>
>
> _______________________________________________
> Chchrobotics mailing list
> Chchrobotics@lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
>
>