View previous topic :: View next topic |
Author |
Message |
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
ADC problem on PIC10F222 |
Posted: Tue Jun 02, 2009 4:29 am |
|
|
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
|
|
|
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
|
Posted: Wed Jun 03, 2009 1:16 am |
|
|
changing the asm code
Code: |
#asm
bsf 0x7, 0x0
#endasm |
to
is solving the problem. Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 03, 2009 1:24 am |
|
|
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
|
|
Posted: Wed Jun 03, 2009 3:17 am |
|
|
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
or the other 2 options you have I get the Undefined identifier error. So our 10f222 files are different. |
|
|
Ttelmah Guest
|
|
Posted: Wed Jun 03, 2009 3:52 am |
|
|
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
|
|
Posted: Wed Jun 03, 2009 5:49 am |
|
|
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: 1934 Location: Norman, OK
|
|
Posted: Wed Jun 03, 2009 6:40 am |
|
|
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!!!! |
|
|
|