CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

adc calibration

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MCUprogrammer



Joined: 08 Sep 2020
Posts: 221

View user's profile Send private message

adc calibration
PostPosted: Sat Mar 20, 2021 4:40 am     Reply with quote

Hello there
CCS C 5.103
dsPIC33EP512GM710
#use delay(clock = 120MHz, crystal = 16MHz)
I am using LM317L for Adc Vref voltage. My Vref voltage is 3 volts.


1- Why does not rounding %g in the PCD compiler? Should I round manually on this? and how should I do this?

2- Can you give information about 2-point ADC calibration. And if there is sample code, can you please share? I have no idea how to do it. How to do it? What should I pay attention to?

And what other ways are there for ADC calibration? And which one is the most effective? Which one should I use? I am reading adc from 24 channels in total from the processor.
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
temtronic



Joined: 01 Jul 2010
Posts: 9104
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 20, 2021 5:31 am     Reply with quote

While I don't use that PIC, I'll offer some general comments....

1st, the LM317 is NOT a good 'voltage reference' ! You say Vref is 3 volts. Ok.... is it 3.0000 or 3.0012 or 2.998 or 3.123 ? What is Vref over say 10-12 hours with Vdd varying say 5% AND with Idd changing say 10-20% ?
You really need to use a Voltage REFERENCE device, one that is a precise voltage and accurate. a 'chip' designed for the job.

2nd. what ADC resolution 8-10-12-16 bits ? I don't use that PIC but trying to reliably get more than 8 useful bits from any micro, requires you to design and build the PCB using a LOT of analog details. Layout, trace widths, bypass caps, shield cabling, EMI suppression, etc. Done correctly you can get repeatable readings down to +-1 bit from a 12 or 16 bit ADC once you understand that analog design is 1/2 engineering, 1/2 good luck, 1/2 bench testing for days.

3rd. 24 channels of analog. What are the sources of voltages? Are they 'slow' like temperature readings or 'fast' like an image sensor ? You ask about '2 point calibration'. That suggests to me a thermistor, or other nonlinear sensor. If so, then the manufacturer will have 'typical calibration' methods in the datasheet of the device, or an 'application note' on their website. There is no 'generic' code for this...so you're best to read what the manufacturer says for your device. If all 24 input devices are the same type, it makes design/build/code easier.

4th. ADC buffers. These are rail to rail, input and output, voltage follower op-amps that go between the sensor and the ADC input. They are used to prevent the ADC input from being 'loaded down'. A side benefit is they offer some protection.

5th .Forget about using floating point numbers ! Use 'scaled integers'. They are 10-50x FASTER, MORE accurate and create smaller code.

6th. Consider using 'Olympic averaging'. It's a simple algorithm. take 10 readings, toss out high and low, average the remaining 8. Super FAST to run. While there are 100s of 'adc filters', its a good one to start with.

7th. Post what the 24 'sensors' are. We can give you more help, if we know more about your project.
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Sat Mar 20, 2021 6:44 am     Reply with quote

CCS, does support %g. However I suspect you may well misunderstand
what this can do. It does not 'round' the number in the normal 4/5 rounding
sense.
Quote:

The double argument is converted in style f or e (or F or E for G conversions). The precision specifies the number of significant digits. If the precision is missing, 6 digits are given; if the precision is zero, it is treated as 1. Style e is used if the exponent from its conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional part of the result; a decimal point appears only if it is followed by at least one digit.


To actually 'round' uses the separate command 'round'. This is not
in the standard CCS library, simply because it is so massively heavy on
processor use. The #define to give 'round', is:

Code:

#define round(x,n) (floor(x*(10.0^n)+0.49)/(10.0^n)))


Where x is the number you want to round, and n is the number of digits.

Also if you are just printing a number and want it 'rounded' to two decimals
for example, you can just add (or subtract if it is less than zero), 0.0049,
and then let the standard %f truncation give the result.

Have to agree wholeheartedly with Jay, on using scaled integers instead
of floats.

Also have to agree massively about the buffer amplifiers. You will need
them. The faster PIC's like this have lower and lower input impedance
on the ADC. Your ADC has a maximum recommended source impedance
of just 200R. Every sensor will need buffering.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group