View previous topic :: View next topic |
Author |
Message |
Guest
|
ADCs on dsPIC33 |
Posted: Tue Dec 01, 2009 8:14 pm |
|
|
I'm using the dsPIC33FJ128MC804. It is capable of sampling four ADC inputs simultaneously, and I need to capture three. Also, I would like the sampling to run continuously and automatically in the background, so all I have to do is grab values out of the results register. DMA buffering is not required, but I could go that route if recommended for some reason.
I don't think the ADC setup options I need are supported by CCS C functions. Is this correct?
Has anyone written custom functions to handle this functionality? I would most appreciate borrowing code if possible -- I have a deadline fast approaching and would rather not waste two days figuring out how to get the ADCs configured.
On the other hand, if I must do it myself then I will. Thus, feel free to ask for help in the future.
Thanks,
Jim |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Wed Dec 02, 2009 1:46 am |
|
|
First,
Consider the dsPIC33FJ128MC804, it has *4* Sample and holds and a SINGLE ADC unit.
For clarification, this means it will sample 4 channels and then convert them one at a time. It looks like the choices are 1 sample, 2 samples and 4 samples. If that's ok, this will work fine for you although I think the 4th sample has to be done and would just be ignored or tossed.
With that, having worked with the PIC18F4431 which has a dual S/H and more #defines in the 18F4431.h, I don't see anything similar in dsPIC33FJ128MC804.h.
This means yes, you'll have to figure out your own values. But it's not as bad as you think. This is a complex topic that I don't think is fair to expect CCS to tackle for you. If you had to use one of the other compilers, your task would be equally if not more difficult.
Make sure to get the datasheet for Section.16 (70183a.pdf) from Microchip's website.
Look at Table 16-1: Sample/Conversion Control Options.
It sounds like you want the last item. And it has a bunch of figures to reference as well.
I usually set up structs to mimic the registers I want to utilize and then #locate them on top of the spot in memory.
Now I can use struct pointers to set my stuff.
Some of CCS's functions might work for you, but this is a pretty spiffy ADC unit that has cool stuff outside the needs of most hobbyist C coders.
Anyway - I don't have code to give out. I've never worked with this PIC. But it doesn't look that bad. I like the sounds of the DMA which might be the hardest thing to set up at first.. possibly not.
Sorry I can be of more help.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
thanks |
Posted: Wed Dec 02, 2009 9:51 am |
|
|
Thanks, Ben.
No surprises here, I completely agree with what you're saying. Funny you'd mention the 4431 -- that's the part I used in the predecessor to this same product.
It sure would be handy if all the register and bit names in the datasheet were already declared and could be used directly. Other C compilers for PICs appear to be setup that way. Am I correct that with CCS C I have to declare them myself? Since you mention setting up a struct to mimic registers, I'm guessing this is true. I'm posting a new topic to ask this question on it's own...
Thanks again.
Jim |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Wed Dec 02, 2009 7:07 pm |
|
|
If you're using on of the CCS IDE products, there's a utility to generate an include file for you.
It's in the Device editor - then when you select the device, there's a command in the window to "Make Include File".
That may save you some time.
The 4431 was a nice part. I wish they had one with more RAM and FLASH.
That project is done though (successfully) -- and that PIC went in a sensor up to 90,000ft MSL. Weeeee.. Hahaha.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
inayyer
Joined: 11 Aug 2008 Posts: 2 Location: pakistan
|
adc help needed |
Posted: Mon May 26, 2014 11:03 am |
|
|
Dear Ben, please help me how you solved that adv problem?
i am actually scanning four analog inputs. but the result is always oscillating. please share something you figured out
imran |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Mon May 26, 2014 4:56 pm |
|
|
hmm...
i am actually scanning four analog inputs. but the result is always oscillating
...
Reading analog voltages can be 'challenging'. WHAT is the source? How stable is it(use scope or DVM)? What is the deviation?(+-1-2 bits). What ADC(8 bit,10 bit,12 bit) ? What is Vref ? Vdd or a 4.096 +-.001 v ref chip? PCB,wirewrap,breadboard ? Cellphone nearby,PC,EMI sources?
Reading analog , especially to 10 or 12 bits requires VERY stable power feeds,great ground planes and ultra stable Vref. 16 bits is even more 'fun'.
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
inayyer
Joined: 11 Aug 2008 Posts: 2 Location: pakistan
|
|
Posted: Tue May 27, 2014 5:56 am |
|
|
Dear Jay,
Thank you very much for your quick reply. Your questions suggest that you have struggled a lot with analog inputs. And i am sure you will help me solve my issue.
Yes i am using 10 bit ADC chip is dsPic30F4011. There are four different sources. three of them are not stable so i never realized that analog input is not fine tuned. the fourth is a temperature sensor the input from sensor is stable as there is no change in temperature. i can see that on DVM. There will be interference from outside as the sensor is in engine compartment. But right now the engine is stopped and apparently there should be no interference from outside. Still the input is oscillating almost +- 4 lsb.
I am using 2.5v external voltage reference which is also stable on DVM.
The PCB is double sided copper poured.
I doubt that there is something wrong with my code. I am not expert in programming. I am just using built in functions like read_adc() setup_adc() etc.
I think for precise input i must configure the specialized input sample and hold etc.
Please help me.
Thanks in advance
Imran |
|
![](templates/subSilver/images/spacer.gif) |
|