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

PIC18F66K22 and ADC strange problem

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



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PIC18F66K22 and ADC strange problem
PostPosted: Fri Mar 28, 2014 10:14 am     Reply with quote

Hi to all,

I have problem with PIC18F66K22 and ADC. I use An0 and with higher voltage of 3Vdc I read incorrect value.
For example:
AN0 = 1 Vdc read 819 dec.
AN0 = 2 Vdc read 1630 dec. (819 x 2)
AN0 = 3 Vdc read 2445 dec. (819 x 3)
AN0 = 4 Vdc read 2273 dec. instead of 3276 !.

Voltage is on AN0 pin !

This happen in my application and also in this test program.

This is code:
Code:

   #include "18F66K22.h"

   #if defined(debug)
   #fuses HSM,DEBUG,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOCPD,BORV18,NODEBUG,NOCPB,STVREN,NOPLLEN,NOFCMEN,SOSC_DIG
   #device ADC=12 icd=true

   #else
   #fuses HSM,NODEBUG,WDT,PROTECT,PUT,CPD,BORV18,CPB,STVREN,NOPLLEN,NOFCMEN,SOSC_DIG
   #device  ADC=12
   #endif

//#device *=16

#BYTE   PORTA   = 0x0F80
#BYTE   PORTB   = 0x0F81
#BYTE   PORTC   = 0x0F82
#BYTE   PORTD   = 0x0F83
#BYTE   PORTE   = 0x0F84
#BYTE   PORTF   = 0x0F85
#BYTE   PORTG   = 0x0F86

#byte   ODCON1= 0xF29
#byte   ODCON2= 0xF28
#byte   ODCON3= 0xF27

#byte   LATC = 0xF8B

#fill_rom 0x00

#use delay(clock=64000000,RESTART_WDT)

long ad_var;

void main() {
int mm;

//Definisci I/0 in base allo schema
restart_wdt();

set_tris_a(0b00000001);
set_tris_b(0x00);
set_tris_c(0x00);
set_tris_d(0x00);
set_tris_e(0x00);
set_tris_e(0x00);
set_tris_f(0x00);

PORTA = (0x00);
PORTB = (0x00);
PORTC = (0x00);
PORTD = (0x00);
PORTE = (0x00);
PORTF = (0x00);
PORTG = (0x00);

setup_oscillator(OSC_PLL_ON);

SETUP_ADC_PORTS(sAN0||VSS_VDD);
setup_adc (ADC_CLOCK_DIV_64);
set_adc_channel(0);
delay_ms(30);


   while(true) {
      ad_var=read_adc(ADC_START_AND_READ);
      delay_ms(100);
   }
}


Somebody can help me ?

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 10:30 am     Reply with quote

Unfortunately the ADC on this chip has problems.
Quote from the errata sheet:
"The ADC will not meet the Microchip standard
ADC specification. ADC may be usable if tested
at the user end. The possible issues are high offset
error, high DNL error and multiple missing
codes. The ADC can be tested and used for
relative measurements."

Try running at 16MHz and see if things improve. I'd suspect the 'missing codes' problem....
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 11:02 am     Reply with quote

Ok Ttelmah, but the problem occurs when input voltage is higher than 3V. With 4V I read a smaller value than 3V.

In your opinion is chip problem ? can be configuration ?

I can try at 16Mhz but I need to use PLL in future.

I call microchip support because someone suggest me this chip.

Regards,
Fabri
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 11:19 am     Reply with quote

At 16Mhz work better, at 4V I read 3260. In any case it isn't linear.

I'm waiting help from microchip support.
temtronic



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

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 11:30 am     Reply with quote

I know, you've probably thought of this but...

Perhaps you can choose another PIC? I'd ask Microchip for their help on a
substitute.

hth
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 11:45 am     Reply with quote

Agreed.

I suggested going slower, because I have seen the missing codes problem (individual bits that just don't set in some parts of the range), disappear at slower speeds.

Are you sure it is not linear at the lower rate?.

3260
2445
1630
819
4

Is linear, but with a four offset at the bottom - another part of the erratum...

I'm afraid these chips are currently ones I'd avoid if at all possible.

Best Wishes
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 12:00 pm     Reply with quote

Linear and offset is not a really problem.... I'm afraid about use of PLL because I need it to use a graphic display as I told you in other post.

I'm testing also PIC18F67K22 but it's of same family so probably has same problem.

I need another pic with same pinout because I developed PCB and I haven't time to change.

Well, thanks for your support.

Regards,
Fabri
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Mar 28, 2014 1:57 pm     Reply with quote

What smoothing have you got on the Vcore pin. This is much more fussy than it should be. I've tended to stick with the 67J94, which is 90% the same on pinout, but has a few things that are rather different (USB etc.).
Could you get away with running the ADC in 10bit mode?. Many of the problems disappear when you do, but I know I've seen quite a few other problems at 64MHz.

Best Wishes
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Sat Mar 29, 2014 1:36 am     Reply with quote

I don't use USB, just PWM for buzzer, AD, RS232 and standard I/O.
With 16Mhz and PIC18F66K22 application work fine but I need speed only to work with GLCD as I told you in other post some times ago. I already used PIC18F46K22 with PLL and 10 bit AD without problem. I'm not interest to have 12 bit resolution and I can downgrade to 10 bit.
Can I switch PIC to work wih 10 bit resolution from 0 to 5 Vdc or must I reduce input voltage in pin and use first 10 bits ?
What kind of problem you found at 64 Mhz ?

Regards,
Fabri
temtronic



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

View user's profile Send private message

PostPosted: Sat Mar 29, 2014 5:29 am     Reply with quote

Fabri
I'm curious as to why you went from a working PIC18F46K22 to the '66'? Does it have some peripheral you now must use ?

jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Mar 29, 2014 5:57 am     Reply with quote

Agreed with Temtronic's comments.

On these chips at 64Mhz, I found the serial, and the ADC both stopped working reliably.

Best Wishes
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Sat Mar 29, 2014 10:45 am     Reply with quote

I changed to PIC18F66K22 just to have more I/O and, in second time, with PIC67K22 more flash. Actually I'm 95% with PIC18F66K22. There's no space to use GLCD so I must have more flash.
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Sat Mar 29, 2014 10:47 am     Reply with quote

I forgot to tell you it was a suggestion from microchip !!!
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Fri Apr 04, 2014 10:07 am     Reply with quote

I solved Very Happy

with PLL I must set TAD with:

Quote:

setup_adc (ADC_CLOCK_DIV_64|ADC_TAD_MUL_20);


In this way ad conversion is steady.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Apr 04, 2014 1:04 pm     Reply with quote

With your long delay, you shouldn't need any Tad time.

However there are some other chips, that won't work properly with Tad set to zero. Sounds as if this is another.
You should report this to MicroChip, since it needs adding to the errata....
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