|
|
View previous topic :: View next topic |
Author |
Message |
Flavio58
Joined: 08 Sep 2003 Posts: 21
|
ADC |
Posted: Tue Jun 24, 2003 9:14 am |
|
|
Do you known where is possible to download some examples about the PIC18 ADC conversion ?
I must to controll a 2.5v and a 3.3V on a board.
Is possible execute this contrll using the ReadAdc() function ?
Thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515528 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: ADC |
Posted: Tue Jun 24, 2003 12:11 pm |
|
|
:=Do you known where is possible to download some examples about the PIC18 ADC conversion ?
:=I must to controll a 2.5v and a 3.3V on a board.
:=Is possible execute this contrll using the ReadAdc() function
----------------------------------------------------
If you have the CCS compiler, then look in this folder
for the example files:
c:\Program Files\Picc\Examples
Look at the EX_ADMM.C file, for an example of using the
read_adc() function with the PIC18.
Also look here for more examples:
c:\Program Files\Picc\Drivers
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515536 |
|
|
Flavio58
Joined: 08 Sep 2003 Posts: 21
|
Re: ADC |
Posted: Wed Jun 25, 2003 2:05 am |
|
|
:=c:\Program Files\Picc\Examples
:=Look at the EX_ADMM.C file, for an example of using the
:=read_adc() function with the PIC18.
:=
:=Also look here for more examples:
:=c:\Program Files\Picc\Drivers
:=
Yes...I saw this example ... but ReadAdc() set a integer value ...
int value;
value = read_adc();
How is possible to compare a float value as 2.5 or 3.3 v with the return value of this function ?
read_adc() return also a float value ?
Is possible to create a C construct as this ?
xxxx value; // where xxxx is a float ... number or...
value = read_adc();
if(value < 2.5)
......
Thank you.....
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515547 |
|
|
R.J.Hamlett Guest
|
Re: ADC |
Posted: Wed Jun 25, 2003 3:21 am |
|
|
:=:=c:\Program Files\Picc\Examples
:=:=Look at the EX_ADMM.C file, for an example of using the
:=:=read_adc() function with the PIC18.
:=:=
:=:=Also look here for more examples:
:=:=c:\Program Files\Picc\Drivers
:=:=
:=Yes...I saw this example ... but ReadAdc() set a integer value ...
:=
:=int value;
:=value = read_adc();
:=
:=How is possible to compare a float value as 2.5 or 3.3 v with the return value of this function ?
:=read_adc() return also a float value ?
:=Is possible to create a C construct as this ?
:=
:=xxxx value; // where xxxx is a float ... number or...
:=
:=value = read_adc();
:=
:=if(value < 2.5)
:= ......
:=
:=Thank you.....
You don't.
Testing a float, is relatively slow, and unnecessary.
The point is that the scaling of the ADC, is dependant on the reference voltage fed to it. If you have selected the main power supply (Vdd), and this is at 5v, then the ADC values, scale relative to this. So in the case of a 10bit ADC, reading 0-1023, with a 5v reference, normally, it would give an output of 512, for 2.5v (half it's range, for half the voltage). The 3.3v value would correspond to 676.
You can do this for whatever range you are using the ADC over (so if you used a precision 4v reference, each 'bit' step of the ADC, would then correspond to 0.0039v (4/1024).
Stop thinking about floating point voltages (these numbers are only representations chosen to suit human thinking). Instead think of percentages of the AD range.
The code throughout, will be much faster if you don't use floating point numbers at all, and for a reasonable regulator system, you want good response speed. The ratio of speeds involved is very significant (between perhaps 4:1, and 16:1).
If you feel you 'must have' floating point forms, then you can convert, by multiplying the AD value, by the step size (so with the 5v supply, float=AD * (5.0/1024.0).
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515553 |
|
|
Sherpa Doug Guest
|
Re: ADC |
Posted: Wed Jun 25, 2003 8:32 am |
|
|
:=:=c:\Program Files\Picc\Examples
:=:=Look at the EX_ADMM.C file, for an example of using the
:=:=read_adc() function with the PIC18.
:=:=
:=:=Also look here for more examples:
:=:=c:\Program Files\Picc\Drivers
:=:=
:=Yes...I saw this example ... but ReadAdc() set a integer value ...
:=
:=int value;
:=value = read_adc();
:=
:=How is possible to compare a float value as 2.5 or 3.3 v with the return value of this function ?
:=read_adc() return also a float value ?
:=Is possible to create a C construct as this ?
:=
:=xxxx value; // where xxxx is a float ... number or...
:=
:=value = read_adc();
:=
:=if(value < 2.5)
:= ......
:=
:=Thank you.....
I wholeheartedly agree with Mr Hamlett. Floats are painfull and waste huge amounts of resources. Don't use them unless you really really really need to (like a foolish edict from management). Instead work with AD counts or integer millivolts or the like.
I did a project measuring ship hulls looking for warps, dents etc. We started our measurements with clock ticks (@10MHz) and multiplied by the speed of sound in water to get millimeters. With 24 bit integer math we could measure a supertanker in integer millimeters. Only when we formatted our output for stinking humans did we insert decimal points using string functions to give an output in meters.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515560 |
|
|
|
|
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
|