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 problem on PIC10F222

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



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

ADC problem on PIC10F222
PostPosted: Tue Jun 02, 2009 4:29 am     Reply with quote

I´m trying to monitor an input and when this input is below a value it makes a output low. Very simple I thought.

It seems that the compiler doesn´t make bit 0 high in the ADCON register, which is the ADON bit (checked in MPLAB SIM). Is it a programming fault or a compiler bug? When I make this ADON bit high with a assembly command it works fine.

Compiler version: 4.093

Code:

#include <10F222.H>
#FUSES NOMCLR, NOWDT, NOPROTECT, IOSC4, NOMCPU                                  //4MHZ
#Device ADC=8                                                                 //8 bit
#use delay(clock=4000000)

#define IN             PIN_B0                                                       
#define AUX_ON    PIN_B2 
#define REMOTE    PIN_B3


void main()
{
int I_meet = 0;


SETUP_ADC_PORTS(sAN1);

while(1)
{

set_ADC_channel(1);
delay_us(10);

#asm
bsf   0x7, 0x0
#endasm


delay_us(10);

I_meet = read_ADC();

if(I_meet < 128)
{
output_low(AUX_ON);
}
else
output_high(AUX_ON);



}
}

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 02, 2009 11:24 am     Reply with quote

You're missing the setup_adc() function. See this post for an example
of how to use the ADC:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 1:16 am     Reply with quote

changing the asm code

Code:

#asm
bsf   0x7, 0x0
#endasm



to


Code:

setup_ADC(sAN1);


is solving the problem. Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 1:24 am     Reply with quote

Quote:
setup_ADC(sAN1);

That's not the correct parameter for the setup_adc() function.
Look in the 10F222.h file, to see the list of allowable parameters.
Here they are:
Code:

// Constants used in SETUP_ADC() are:
#define ADC_OFF               0    // ADC Off
#define ADC_CLOCK_DIV_4       1
#define ADC_ON                1


Here's the file location:
Quote:
c:\Program Files\picc\Devices\10f222.h
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 3:17 am     Reply with quote

When I look in my 10F222.h file I only have these functions for the ADC:

Code:
////////////////////////////////////////////////////////////////// ADC
// ADC Functions: SETUP_ADC(), SETUP_ADC_PORTS() (aka SETUP_PORT_A),
//                SET_ADC_CHANNEL(), READ_ADC()
// Constants used in SETUP_ADC_PORTS() are:
#define sAN0            0x40       //| A0
#define sAN1            0x80       //| A1
#define NO_ANALOGS      0          // None
#define ALL_ANALOG      0xc0       // A0 A1


// Constants used in READ_ADC() are:
#define ADC_START_AND_READ     7   // This is the default if nothing is specified
#define ADC_START_ONLY         1
#define ADC_READ_ONLY          6


When I try to compile
Code:

Setup_ADC(ADC_ON);


or the other 2 options you have I get the Undefined identifier error. So our 10f222 files are different.
Ttelmah
Guest







PostPosted: Wed Jun 03, 2009 3:52 am     Reply with quote

4.093, should have the version PCM programmer posted.
The values you are posting, come from an older 10F222.h. Triple check your installation.
However (fortunately), it doesn't matter. The setup_adc function on these PICs, seems to only use the value given to it, as a 'true/false' value, for ADC on/off, so you can use:

setup_adc(TRUE);

or as you have already found, any other existing define, that is 'non zero', should work.

Best Wishes
mvanvliet



Joined: 02 Jun 2009
Posts: 123
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 5:49 am     Reply with quote

That's strange. I have bought the 4.092 cd (updated to the 4.093 version) because my old version 4.060 wasn't working well with some code.

Renaming the devices map and installing the compiler again doesn't solve the problem (the .h files are the same). Also downloading the 4.093 version and installing it doesn't solve it. Is it possible to download the newest 10f222.h file (or only in a istallation package)?
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 6:40 am     Reply with quote

Here is what mine looks like in 4.081, it matches hat he has.

Code:

//////////////////////////////////////////////////////////////////
// ADC Functions: SETUP_ADC(), SETUP_ADC_PORTS() (aka SETUP_PORT_A),
//                SET_ADC_CHANNEL(), READ_ADC()
// Constants used in SETUP_ADC_PORTS() are:
#define sAN0            0x40       //| A0
#define sAN1            0x80       //| A1
#define NO_ANALOGS      0          // None
#define ALL_ANALOG      0xc0       // A0 A1

_________________
Google and Forum Search are some of your best tools!!!!
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