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

set_adc_channel, undocumented second parameter?

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



Joined: 04 Nov 2010
Posts: 3

View user's profile Send private message

set_adc_channel, undocumented second parameter?
PostPosted: Thu Nov 04, 2010 9:52 am     Reply with quote

Hi,

In general I measured the analog voltages by setting f.e. set_adc_channel(1), set_adc_channel(2) .....

Now I want to measure 5 channels this way and one analog input I want to measure differential voltage across two channels.
In PIC18F67K22.h (thats the actual device I'm using) I found:

// Constants used for second parameter of SET_ADC_CHANNEL() (first parameter is Analog Positive Channel)
Code:
#define VSS      0xFF //Analog Negative Channel connected to Vss

But in the ccs manual I found nothing about a second parameter. There I only found set_adc_channel (chan)

So here is my question:

Is it possible to call set_adc_channel (1,2) for differential measurement between channel 1 and 2 ?
If I don't misunderstand understand the device.h comment it must at least be possible to call set_adc_channel (1, VSS)

Any experience?

Thanks for any help

Norbert,
Bremerhaven,
Germany

PS: I know that it is also possible to measure each channel for itself and than subtract the result, but thats not I want, because there is a small time difference between the measurement.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Nov 04, 2010 10:53 am     Reply with quote

The reason that set_adc_channel, is only shown with one parameter, is simply that 99.9% of PICs only have a single input to the ADC selectable. Yours is one of a very few (new) chips that are appearing with the ability to setup differential inputs.

Now, first comment. 'Odds' of a new feature like this actually working for the next few compiler versions are low.....
What you have found, is a 'sign' that CCS are working on it.
New features like this are usually documented in the 'readme' with the compiler, when they first expect people to actually start using them, before they appear in the manual. At present nothing there....

Realistically, I'd simply make a #byte definition for ADCON1, and try setting the negative channel number myself.
I'd also try putting a value into the second parameter, and look at the assembler generated.

The value seems somewhat 'odd', since the Avss selection involves writing zeros to the low bits of the register. 0xFF, doesn't make a lot of sense here...

Best Wishes
nrieper



Joined: 04 Nov 2010
Posts: 3

View user's profile Send private message

PostPosted: Fri Nov 05, 2010 8:09 am     Reply with quote

Thank you Ttelmah,

I just tried to use the second parameter. The compiler didn't complain and when I checked the ADCON1 register, CHSN is set to 110, thats the value for AN5, the channel I was setting. So the function seems to work with the second parameter. Next I have to check the result with a signal to the inputs.
nrieper



Joined: 04 Nov 2010
Posts: 3

View user's profile Send private message

PostPosted: Wed Nov 10, 2010 2:38 am     Reply with quote

So I tried to set the adc to differential input by using the second parameter:
set_adc_channel(ANALOG_SHUNT_H, ANALOG_SHUNT_L), where ANALOG_SHUNT_H = 11 and ANALOG_SHUNT_L = 5.

Everything works fine, so the undocumented second parameter works for this pic.
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