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 setup code is strange for 16F877 (PCM 3.202)

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

ADC setup code is strange for 16F877 (PCM 3.202)
PostPosted: Mon Jun 14, 2004 5:36 pm     Reply with quote

PCM vs. 3.202 is doing something weird with the ADC setup functions.
Instead of writing to ADCON0 and ADCON1 as a single byte operation,
the compiler is doing it one bit at a time. This must have something
to do with the major changes that CCS did for vs. 3.200.

What I dislike about this method is that it cycles the Port A pins
through several different modes before they reach the intended mode.
That's just wrong on a philosophical level. It could potentially
cause some problem with external circuits by switching a pin into
a mode that's not intended.

In addition to that, I noticed that the startup code for ADCON1 is
probably incorrect. Traditionally, CCS has initialized Port A as all
digitial. But look at the code right below main(). They're doing
a BSF on bits 0-3 of ADCON1. That sets it to 0x0F, which has AN0
as analog, and AN2 and AN3 as Vref pins. For years, they have
initialized ADCON1 to 0x07 (all digital). Why this change ?
I have to assume it's a mistake.

The code below was compiled for a 16F877 with PCM vs. 3.202:
Code:
0000                00293 .................... void main()   
0000                00294 .................... {   
0004 0184       00295 CLRF   04
0005 301F       00296 MOVLW  1F
0006 0583       00297 ANDWF  03,F
0007 1683       00298 BSF    03.5     // ADCON1
0008 141F       00299 BSF    1F.0
0009 149F       00300 BSF    1F.1
000A 151F       00301 BSF    1F.2
000B 159F       00302 BSF    1F.3     // This should likely be BCF.
0000                00303 .................... int16 result; 
0000                00304 ....................   
0000                00305 .................... setup_adc_ports(ALL_ANALOG); 
000C 101F       00306 BCF    1F.0
000D 109F       00307 BCF    1F.1
000E 111F       00308 BCF    1F.2
000F 119F       00309 BCF    1F.3
0000                00310 ....................   
0000                00311 .................... setup_adc(ADC_CLOCK_DIV_8); 
0010 1283       00312 BCF    03.5     // ADCON0
0011 171F       00313 BSF    1F.6     //     ADSC0 bit
0012 139F       00314 BCF    1F.7     //     ADSC1 bit
0013 1683       00315 BSF    03.5     // ADCON1
0014 139F       00316 BCF    1F.7     //      ADFM bit
0015 1283       00317 BCF    03.5     // ADCON0
0016 141F       00318 BSF    1F.0     //      ADON bit

The other ADC functions, set_channel() and read_adc(), don't appear
to be affected by these problems.
Guest








PostPosted: Tue Jun 15, 2004 1:17 am     Reply with quote

It must be a mistake, indeed. The ADC with 3.202 not works properly.
With a well-tested source code I got 0 for all channels. Downgrading to 3.191 and everything is fine.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 1:26 am     Reply with quote

Quote:
The ADC with 3.202 not works properly.
With a well-tested source code I got 0 for all channels

What PIC are you using ?
Guest








PostPosted: Tue Jun 15, 2004 1:46 am     Reply with quote

I have tested this with:
16F877
18F452
12F675
getting the same result. It must be something "orbital" about the new ADC handling style.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 4:20 am     Reply with quote

Thanks for sharing this, guys...Yesterday I was thinking about updating my compiler from 3.190 to 3.202 in a 16F877 based project with a lot of ADC code, but thanks to your warnings I'll hold off.
Had I changed it, I would've spent days trying to figure out what was wrong. A broken ADC code is the last thing you expect from the new version of the compiler, afterall.
Kieran



Joined: 28 Nov 2003
Posts: 39
Location: Essex UK

View user's profile Send private message

ADC setup and Vn3.202
PostPosted: Tue Jun 15, 2004 4:33 am     Reply with quote

I have just recompiled a project for a 16F876 using ADC and it works fine.

Code:

....................    setup_adc_ports(RA0_RA1_RA3_ANALOG);
085B:  BSF    03.5
085C:  BCF    1F.0
085D:  BCF    1F.1
085E:  BSF    1F.2
085F:  BCF    1F.3
....................    setup_adc(ADC_CLOCK_INTERNAL);
0860:  BCF    03.5
0861:  BSF    1F.6
0862:  BSF    1F.7
0863:  BSF    03.5
0864:  BSF    1F.7
0865:  BCF    03.5
0866:  BSF    1F.0



I agree that the code is messy.
Have you reported this to CCS?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 11:45 am     Reply with quote

Quote:
I agree that the code is messy. Have you reported this to CCS?

Yes, I sent them an email just now.
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