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 CCS Technical Support

ADC *** Locked. 2004 thread.
Goto page Previous  1, 2
 
Post new topic   This topic is locked: you cannot edit posts or make replies.    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








PostPosted: Tue May 25, 2004 10:02 am     Reply with quote

The problem is:

int var = 10;
float resul;

resul = (float)var;

and i get resul =.166e-41

either ice2000 and icd2.
Why?

I always have the problems with ice2000 about the return of read _adc() that is wrong.
Guest








PostPosted: Tue May 25, 2004 10:09 am     Reply with quote

Haplo wrote:
Did you try the setup_adc(ADC_CLOCK_DIV_32); ?
As others have pointed to you, according to the datasheet, the ADC clock should be set so it would guarantee a minimum of 19.2us for the conversion to complete. Your current setting is giving it less than 4us.

And also, what is the impedance on your analog pin? According to the datasheet, The maximum recommended impedance for analog sources is 10 kΩ.


Hi Haplo,
1. I tried the setup_adc(ADC_CLOCK_DIV_32) already.
2. I input the analog value from a DC power supply directly, it's variable.

Thanks and Best Regards.
xinyh



Joined: 23 Mar 2004
Posts: 11

View user's profile Send private message

PostPosted: Tue May 25, 2004 9:46 pm     Reply with quote

Hi Ttelmah, Haplo and all,

It's working now. What I did is as below:

1. Rebuilt the project by PIC wizard;
2. Define value as "Long int value";
3. float = (float)value*(5.0/1024.0); don't use value*(5/1024).

Thanks for your valuable guidance.
Best Regards,
Xinyh
Tony
Guest







adc
PostPosted: Wed May 26, 2004 2:39 am     Reply with quote

Hi,
i'm following the suggestion but it doesn't work.
The code is :

#include <18F452.h>
#DEVICE ICD=TRUE
#DEVICE ADC=10
#include <MATH.H>
#USE FAST_IO(A)
#FUSES HS, NOPROTECT, NOPUT, NOBROWNOUT, NOWDT, NOCPD #USE DELAY (CLOCK=8000000)
#ZERO_RAM

void main()
{
long int value;
float result;

/* Configuration for A/D */
setup_port_a(ALL_ANALOG);
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
/* Port A.0 in input */
set_tris_A(0x01);

while(TRUE)
{
set_adc_channel(0);
delay_us(10);
/* Read the value by A/D internal of PIC18F452 */
value = read_adc();
/* Calculate result in floating point */
result = (float)value*(5.0/1024.0);
}
}

I'm working by MPLAB 6.40 & CCS 3.177.

Vdd = 3V; VinA/D = 0.756V;
ICE2000 : value = 156 (W R O N G!!!!!)
ICD2 : value = 263 (C O R R E C T)
Why this difference?

Either ICE2000 and ICD2 i get result = .599969e-41 instead of 1.284.

Anyone can i help me???
It's IMPORTANT & URGENT!!!!!

Thanks
Tony








}
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

Re: adc
PostPosted: Wed May 26, 2004 7:35 am     Reply with quote

Tony wrote:

result = (float)value*(5.0/1024.0);


Change this line and try:

result = (float)value * 0.0048828125;

What you are getting looks like it might be an underflow or a bug in 3.177's floating point routines. The above line pre-calculates the 5/1024 and uses just a multiply.

As for your ICE2000 giving a different results from the ADC, I'm not suprised at that. I've seen other ICE's give wrong values back from perpherals like ADCs and pulse-capture.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
tony
Guest







adc
PostPosted: Wed May 26, 2004 8:20 am     Reply with quote

Thanks, so what do you suggest?

I have to buy CCS 3.190?
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed May 26, 2004 12:37 pm     Reply with quote

Did the 0.0488 multiply work for you?

As a mater of personal preference, I avoid the division operator no mater what processor or compiler I'm using.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
ingemilo



Joined: 19 Apr 2016
Posts: 6

View user's profile Send private message

PostPosted: Tue Apr 19, 2016 7:44 pm     Reply with quote

printf("\n\r ADC-value: %4X \r\n", value);

Here you will get an hexadecimal number

Why don't change as below

printf("\n\r ADC-value: %4Ld \r\n", value);
ingemilo



Joined: 19 Apr 2016
Posts: 6

View user's profile Send private message

Re: adc
PostPosted: Tue Apr 19, 2016 8:00 pm     Reply with quote

Tony wrote:
Hi,
i'm following the suggestion but it doesn't work.
The code is :

#include <18F452.h>
#DEVICE ICD=TRUE
#DEVICE ADC=10
#include <MATH.H>
#USE FAST_IO(A)
#FUSES HS, NOPROTECT, NOPUT, NOBROWNOUT, NOWDT, NOCPD #USE DELAY (CLOCK=8000000)
#ZERO_RAM

void main()
{
long int value;
float result;

/* Configuration for A/D */
setup_port_a(ALL_ANALOG);
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
/* Port A.0 in input */
set_tris_A(0x01);

while(TRUE)
{
set_adc_channel(0);
delay_us(10);
/* Read the value by A/D internal of PIC18F452 */
value = read_adc();
/* Calculate result in floating point */
result = (float)value*(5.0/1024.0);
}
}

I'm working by MPLAB 6.40 & CCS 3.177.

Vdd = 3V; VinA/D = 0.756V;
ICE2000 : value = 156 (W R O N G!!!!!)
ICD2 : value = 263 (C O R R E C T)
Why this difference?

Either ICE2000 and ICD2 i get result = .599969e-41 instead of 1.284.

Anyone can i help me???
It's IMPORTANT & URGENT!!!!!

Thanks
Tony








}


Because Vdd = 3V you must use
result = (float)value*(3.0/1024.0);
instead
result = (float)value*(5.0/1024.0);
temtronic



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

View user's profile Send private message

PostPosted: Wed Apr 20, 2016 5:19 am     Reply with quote

Hang on... you've got a worse problem !!
According to your program....PIC is 18F452, VDD is 3 volts...

The PIC18F452 is NOT rated to have a VDD of 3 volts!! Check out figure 22-1 of the datasheet. Yes, some individual PICs seem to work OK with an out of spec VDD but they will give random or odd results, quirky performance or just 'die' for some unknown reason.

Check the electrical specs, figure 22-1 in the datasheet. This is important!

You have 2 options
1) buy the 'L' version of the PIC. it IS rated for 3 volt operation,but read the datasheet-do the math, it will NOT run at 40MHz at 3V, more like 12MHz.

2) Use a VDD of 5 volts. The 18F452 WILL work fine then,at full speed of 40 MHz !!


Jay
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Apr 20, 2016 7:12 am     Reply with quote

Hi,

You guys (ingemilo & temtronic) do realize that you are posting on a twelve year old "zombie" thread, right???????
_________________
John

If it's worth doing, it's worth doing in real hardware!
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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