Is 18F452 Document Outdated ?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Is 18F452 Document Outdated ?

Yigit Turgut
Hi folks,

I have a piece-of-cake question for the most of you ;

For some test purposes I am trying to implement some stuff in a
18f452. By referring to datasheet (39564c.pdf ~ 5.7Mb) I think I am
not able to set the correct bits right. For the initial test I tried
to use the built-in function of the C18 compiler, my other routines
work perfectly well except the lousy internal ADC. For the test ;


#include <adc.h>
#include <stdlib.h>
#include <delays.h>

unsigned int result;

void main( void )
{
TRISA = 1 ;
TRISB = 0;
LATBbits.LATB6 = 0;

OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA & ADC_CH1 & ADC_INT_OFF );
Delay10TCYx( 5 );

ConvertADC();

while( BusyADC() ){
    result = ReadADC();
    if(result<=512){
        LATBbits.LATB6 = 1;
        Delay10TCYx( 5 );}
}
}

Internal ADC of this device is 10bits thus should provide a value
between 0-1023. Threshold is chosen exactly in the middle thus I can
check if the routine works by applying 0V and 5V to AN0. The problem
is ; it doesn't work (chinn chinn). I succeded following the same
methodology at other devices from Microchip but no luck with the
18f452. I think it's an older device thus the datasheet I mentioned
above might be incompatible at a point or more with latest versions of
C18 and MpLabX.

Exact error when compiling this unbelievable short code is ;

too few arguments in function call

in the OpenADC function.

When checked out the C18 documents, it is clearly stated that these
configurations for OpenADC should suffice.

I wanted to have opinions that can save me some time before I believe
this thing worth digging deeper.

Have a nice day.
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

RE: Is 18F452 Document Outdated ?

Alan Pearce - UKRI STFC
> I have a piece-of-cake question for the most of you ;
>
> For some test purposes I am trying to implement some stuff in a
> 18f452. By referring to datasheet (39564c.pdf ~ 5.7Mb) I think I am
> not able to set the correct bits right. For the initial test I tried
> to use the built-in function of the C18 compiler, my other routines
> work perfectly well except the lousy internal ADC. For the test ;

My usual answer is 'what does the errata sheet say' ??


--
Scanned by iCritical.

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Is 18F452 Document Outdated ?

Matt Callow
In reply to this post by Yigit Turgut
Shouldn't the call ave 2 args? Config and config2 are listed in the c18
libraries manual.

Matt
On 4 Oct 2012 19:43, "Yigit Turgut" <[hidden email]> wrote:

> Hi folks,
>
> I have a piece-of-cake question for the most of you ;
>
> For some test purposes I am trying to implement some stuff in a
> 18f452. By referring to datasheet (39564c.pdf ~ 5.7Mb) I think I am
> not able to set the correct bits right. For the initial test I tried
> to use the built-in function of the C18 compiler, my other routines
> work perfectly well except the lousy internal ADC. For the test ;
>
>
> #include <adc.h>
> #include <stdlib.h>
> #include <delays.h>
>
> unsigned int result;
>
> void main( void )
> {
> TRISA = 1 ;
> TRISB = 0;
> LATBbits.LATB6 = 0;
>
> OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA & ADC_CH1 & ADC_INT_OFF );
> Delay10TCYx( 5 );
>
> ConvertADC();
>
> while( BusyADC() ){
>     result = ReadADC();
>     if(result<=512){
>         LATBbits.LATB6 = 1;
>         Delay10TCYx( 5 );}
> }
> }
>
> Internal ADC of this device is 10bits thus should provide a value
> between 0-1023. Threshold is chosen exactly in the middle thus I can
> check if the routine works by applying 0V and 5V to AN0. The problem
> is ; it doesn't work (chinn chinn). I succeded following the same
> methodology at other devices from Microchip but no luck with the
> 18f452. I think it's an older device thus the datasheet I mentioned
> above might be incompatible at a point or more with latest versions of
> C18 and MpLabX.
>
> Exact error when compiling this unbelievable short code is ;
>
> too few arguments in function call
>
> in the OpenADC function.
>
> When checked out the C18 documents, it is clearly stated that these
> configurations for OpenADC should suffice.
>
> I wanted to have opinions that can save me some time before I believe
> this thing worth digging deeper.
>
> Have a nice day.
> --
> http://www.piclist.com PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
>
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Is 18F452 Document Outdated ?

peter green-2
In reply to this post by Yigit Turgut
Yigit Turgut wrote:

> Hi folks,
>
> I have a piece-of-cake question for the most of you ;
>
> For some test purposes I am trying to implement some stuff in a
> 18f452. By referring to datasheet (39564c.pdf ~ 5.7Mb) I think I am
> not able to set the correct bits right. For the initial test I tried
> to use the built-in function of the C18 compiler, my other routines
> work perfectly well except the lousy internal ADC. For the test ;
>
>
> #include <adc.h>
> #include <stdlib.h>
> #include <delays.h>
>
> unsigned int result;
>
> void main( void )
> {
> TRISA = 1 ;
>  
Ok so you are making bit0 of portA an input and all other bits outputs.
In particular you are making bit1 which you are about to go and try and
use as an analog input an output.

Setting pins to analog mode does NOT disable the output driver so if
you want to use a pin as an analog input you must have it set as an input
in the tris registers.
> TRISB = 0;
> LATBbits.LATB6 = 0;
>
> OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA & ADC_CH1 & ADC_INT_OFF );
>  
Lets take a look at the C18 libraries documentation.
http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en010014&lang=en&ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014#

According to that document openadc for the "PIC18CXX2, PIC18FXX2,
PIC18FXX8, PIC18FXX39" has two parameters, config and config2. Each of
which is a bitmask created by anding values from various categories. So
your OpenADC call should be.

OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA_0REF , ADC_CH1 & ADC_INT_OFF );

> Delay10TCYx( 5 );
>
> ConvertADC();
>
> while( BusyADC() ){
>     result = ReadADC();
>  
umm you should be waiting until the ADC stops being busy before reading it.

>     if(result<=512){
>         LATBbits.LATB6 = 1;
>         Delay10TCYx( 5 );}
> }
> }
>
> Internal ADC of this device is 10bits thus should provide a value
> between 0-1023. Threshold is chosen exactly in the middle thus I can
> check if the routine works by applying 0V and 5V to AN0. The problem
> is ; it doesn't work (chinn chinn). I succeded following the same
> methodology at other devices from Microchip but no luck with the
> 18f452. I think it's an older device thus the datasheet I mentioned
> above might be incompatible at a point or more with latest versions of
> C18 and MpLabX.
>
> Exact error when compiling this unbelievable short code is ;
>
> too few arguments in function call
>
> in the OpenADC function.
>
> When checked out the C18 documents, it is clearly stated that these
> configurations for OpenADC should suffice.
>
> I wanted to have opinions that can save me some time before I believe
> this thing worth digging deeper.
>
> Have a nice day.
>  

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Is 18F452 Document Outdated ?

Yigit Turgut
Thanks to all replies but I believe there is a more fundamental
problem because ;

ADC_8ANA_0REF

this config parameter is not recognized by C18/MPLABX thus is not
suitable to compile. Something is definitely wrong (:

On Thu, Oct 4, 2012 at 2:56 PM, peter green <[hidden email]> wrote:

> Yigit Turgut wrote:
>> Hi folks,
>>
>> I have a piece-of-cake question for the most of you ;
>>
>> For some test purposes I am trying to implement some stuff in a
>> 18f452. By referring to datasheet (39564c.pdf ~ 5.7Mb) I think I am
>> not able to set the correct bits right. For the initial test I tried
>> to use the built-in function of the C18 compiler, my other routines
>> work perfectly well except the lousy internal ADC. For the test ;
>>
>>
>> #include <adc.h>
>> #include <stdlib.h>
>> #include <delays.h>
>>
>> unsigned int result;
>>
>> void main( void )
>> {
>> TRISA = 1 ;
>>
> Ok so you are making bit0 of portA an input and all other bits outputs.
> In particular you are making bit1 which you are about to go and try and
> use as an analog input an output.
>
> Setting pins to analog mode does NOT disable the output driver so if
> you want to use a pin as an analog input you must have it set as an input
> in the tris registers.
>> TRISB = 0;
>> LATBbits.LATB6 = 0;
>>
>> OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA & ADC_CH1 & ADC_INT_OFF );
>>
> Lets take a look at the C18 libraries documentation.
> http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en010014&lang=en&ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014#
>
> According to that document openadc for the "PIC18CXX2, PIC18FXX2,
> PIC18FXX8, PIC18FXX39" has two parameters, config and config2. Each of
> which is a bitmask created by anding values from various categories. So
> your OpenADC call should be.
>
> OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA_0REF , ADC_CH1 & ADC_INT_OFF );
>
>> Delay10TCYx( 5 );
>>
>> ConvertADC();
>>
>> while( BusyADC() ){
>>     result = ReadADC();
>>
> umm you should be waiting until the ADC stops being busy before reading it.
>>     if(result<=512){
>>         LATBbits.LATB6 = 1;
>>         Delay10TCYx( 5 );}
>> }
>> }
>>
>> Internal ADC of this device is 10bits thus should provide a value
>> between 0-1023. Threshold is chosen exactly in the middle thus I can
>> check if the routine works by applying 0V and 5V to AN0. The problem
>> is ; it doesn't work (chinn chinn). I succeded following the same
>> methodology at other devices from Microchip but no luck with the
>> 18f452. I think it's an older device thus the datasheet I mentioned
>> above might be incompatible at a point or more with latest versions of
>> C18 and MpLabX.
>>
>> Exact error when compiling this unbelievable short code is ;
>>
>> too few arguments in function call
>>
>> in the OpenADC function.
>>
>> When checked out the C18 documents, it is clearly stated that these
>> configurations for OpenADC should suffice.
>>
>> I wanted to have opinions that can save me some time before I believe
>> this thing worth digging deeper.
>>
>> Have a nice day.
>>
>
> --
> http://www.piclist.com PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Is 18F452 Document Outdated ?

Joe Wronski
So why do you think the device or data sheet has a problem?
It sounds more like the problem is in your toolchain.

Joe W



On 10/4/2012 8:17 AM, Yigit Turgut wrote:

> Thanks to all replies but I believe there is a more fundamental
> problem because ;
>
> ADC_8ANA_0REF
>
> this config parameter is not recognized by C18/MPLABX thus is not
> suitable to compile. Something is definitely wrong (:
>
> On Thu, Oct 4, 2012 at 2:56 PM, peter green <[hidden email]> wrote:
>> Yigit Turgut wrote:
>>> Hi folks,
>>>
>>> I have a piece-of-cake question for the most of you ;
>>>
>>> For some test purposes I am trying to implement some stuff in a
>>> 18f452. By referring to datasheet (39564c.pdf ~ 5.7Mb) I think I am
>>> not able to set the correct bits right. For the initial test I tried
>>> to use the built-in function of the C18 compiler, my other routines
>>> work perfectly well except the lousy internal ADC. For the test ;
>>>
>>>
>>> #include <adc.h>
>>> #include <stdlib.h>
>>> #include <delays.h>
>>>
>>> unsigned int result;
>>>
>>> void main( void )
>>> {
>>> TRISA = 1 ;
>>>
>> Ok so you are making bit0 of portA an input and all other bits outputs.
>> In particular you are making bit1 which you are about to go and try and
>> use as an analog input an output.
>>
>> Setting pins to analog mode does NOT disable the output driver so if
>> you want to use a pin as an analog input you must have it set as an input
>> in the tris registers.
>>> TRISB = 0;
>>> LATBbits.LATB6 = 0;
>>>
>>> OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA & ADC_CH1 & ADC_INT_OFF );
>>>
>> Lets take a look at the C18 libraries documentation.
>> http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en010014&lang=en&ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014#
>>
>> According to that document openadc for the "PIC18CXX2, PIC18FXX2,
>> PIC18FXX8, PIC18FXX39" has two parameters, config and config2. Each of
>> which is a bitmask created by anding values from various categories. So
>> your OpenADC call should be.
>>
>> OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA_0REF , ADC_CH1 & ADC_INT_OFF );
>>
>>> Delay10TCYx( 5 );
>>>
>>> ConvertADC();
>>>
>>> while( BusyADC() ){
>>>      result = ReadADC();
>>>
>> umm you should be waiting until the ADC stops being busy before reading it.
>>>      if(result<=512){
>>>          LATBbits.LATB6 = 1;
>>>          Delay10TCYx( 5 );}
>>> }
>>> }
>>>
>>> Internal ADC of this device is 10bits thus should provide a value
>>> between 0-1023. Threshold is chosen exactly in the middle thus I can
>>> check if the routine works by applying 0V and 5V to AN0. The problem
>>> is ; it doesn't work (chinn chinn). I succeded following the same
>>> methodology at other devices from Microchip but no luck with the
>>> 18f452. I think it's an older device thus the datasheet I mentioned
>>> above might be incompatible at a point or more with latest versions of
>>> C18 and MpLabX.
>>>
>>> Exact error when compiling this unbelievable short code is ;
>>>
>>> too few arguments in function call
>>>
>>> in the OpenADC function.
>>>
>>> When checked out the C18 documents, it is clearly stated that these
>>> configurations for OpenADC should suffice.
>>>
>>> I wanted to have opinions that can save me some time before I believe
>>> this thing worth digging deeper.
>>>
>>> Have a nice day.
>>>
>> --
>> http://www.piclist.com PIC/SX FAQ & list archive
>> View/change your membership options at
>> http://mailman.mit.edu/mailman/listinfo/piclist

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Is 18F452 Document Outdated ?

Yigit Turgut
Toolchain works fine for most of the device families including 18F but
not for the 18f452 only. I will code  it from scratch, oldschool.

On Thu, Oct 4, 2012 at 9:22 PM, Joe Wronski <[hidden email]> wrote:

> So why do you think the device or data sheet has a problem?
> It sounds more like the problem is in your toolchain.
>
> Joe W
>
>
>
> On 10/4/2012 8:17 AM, Yigit Turgut wrote:
>> Thanks to all replies but I believe there is a more fundamental
>> problem because ;
>>
>> ADC_8ANA_0REF
>>
>> this config parameter is not recognized by C18/MPLABX thus is not
>> suitable to compile. Something is definitely wrong (:
>>
>> On Thu, Oct 4, 2012 at 2:56 PM, peter green <[hidden email]> wrote:
>>> Yigit Turgut wrote:
>>>> Hi folks,
>>>>
>>>> I have a piece-of-cake question for the most of you ;
>>>>
>>>> For some test purposes I am trying to implement some stuff in a
>>>> 18f452. By referring to datasheet (39564c.pdf ~ 5.7Mb) I think I am
>>>> not able to set the correct bits right. For the initial test I tried
>>>> to use the built-in function of the C18 compiler, my other routines
>>>> work perfectly well except the lousy internal ADC. For the test ;
>>>>
>>>>
>>>> #include <adc.h>
>>>> #include <stdlib.h>
>>>> #include <delays.h>
>>>>
>>>> unsigned int result;
>>>>
>>>> void main( void )
>>>> {
>>>> TRISA = 1 ;
>>>>
>>> Ok so you are making bit0 of portA an input and all other bits outputs.
>>> In particular you are making bit1 which you are about to go and try and
>>> use as an analog input an output.
>>>
>>> Setting pins to analog mode does NOT disable the output driver so if
>>> you want to use a pin as an analog input you must have it set as an input
>>> in the tris registers.
>>>> TRISB = 0;
>>>> LATBbits.LATB6 = 0;
>>>>
>>>> OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA & ADC_CH1 & ADC_INT_OFF );
>>>>
>>> Lets take a look at the C18 libraries documentation.
>>> http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownload.aspx?device=en010014&lang=en&ReturnURL=http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014#
>>>
>>> According to that document openadc for the "PIC18CXX2, PIC18FXX2,
>>> PIC18FXX8, PIC18FXX39" has two parameters, config and config2. Each of
>>> which is a bitmask created by anding values from various categories. So
>>> your OpenADC call should be.
>>>
>>> OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA_0REF , ADC_CH1 & ADC_INT_OFF );
>>>
>>>> Delay10TCYx( 5 );
>>>>
>>>> ConvertADC();
>>>>
>>>> while( BusyADC() ){
>>>>      result = ReadADC();
>>>>
>>> umm you should be waiting until the ADC stops being busy before reading it.
>>>>      if(result<=512){
>>>>          LATBbits.LATB6 = 1;
>>>>          Delay10TCYx( 5 );}
>>>> }
>>>> }
>>>>
>>>> Internal ADC of this device is 10bits thus should provide a value
>>>> between 0-1023. Threshold is chosen exactly in the middle thus I can
>>>> check if the routine works by applying 0V and 5V to AN0. The problem
>>>> is ; it doesn't work (chinn chinn). I succeded following the same
>>>> methodology at other devices from Microchip but no luck with the
>>>> 18f452. I think it's an older device thus the datasheet I mentioned
>>>> above might be incompatible at a point or more with latest versions of
>>>> C18 and MpLabX.
>>>>
>>>> Exact error when compiling this unbelievable short code is ;
>>>>
>>>> too few arguments in function call
>>>>
>>>> in the OpenADC function.
>>>>
>>>> When checked out the C18 documents, it is clearly stated that these
>>>> configurations for OpenADC should suffice.
>>>>
>>>> I wanted to have opinions that can save me some time before I believe
>>>> this thing worth digging deeper.
>>>>
>>>> Have a nice day.
>>>>
>>> --
>>> http://www.piclist.com PIC/SX FAQ & list archive
>>> View/change your membership options at
>>> http://mailman.mit.edu/mailman/listinfo/piclist
>
> --
> http://www.piclist.com PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: Is 18F452 Document Outdated ?

William Westfield
In reply to this post by peter green-2

On Oct 4, 2012, at 4:56 AM, peter green wrote:

> Lets take a look at the C18 libraries documentation.

>> A bitmask that is created by performing a bitwise AND operation (‘&’) with a value from each of the categories listed below. These values are defined in the file adc.h.

Bitwise AND??!!  Really?
Is there some inherent advantage of inverted bitmasks that I'm missing?  It seems very counter-intuitive if the registers themselves don't have active-low individual bits (like some fuse/config bytes.)

BillW


--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist