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 > #include > #include > > unsigned int result; > > void main( void ) > { > TRISA =3D 1 ; > =20 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 =3D 0; > LATBbits.LATB6 =3D 0; > > OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA & ADC_CH1 & ADC_INT_OFF = ); > =20 Lets take a look at the C18 libraries documentation. http://www.microchip.com/Microchip.WWW.SecureSoftwareList/secsoftwaredownlo= ad.aspx?device=3Den010014&lang=3Den&ReturnURL=3Dhttp://www.microchip.com/st= ellent/idcplg?IdcService=3DSS_GET_PAGE&nodeId=3D1406&dDocName=3Den010014# According to that document openadc for the "PIC18CXX2, PIC18FXX2,=20 PIC18FXX8, PIC18FXX39" has two parameters, config and config2. Each of=20 which is a bitmask created by anding values from various categories. So=20 your OpenADC call should be. OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA_0REF , ADC_CH1 & ADC_INT_O= FF ); > Delay10TCYx( 5 ); > > ConvertADC(); > > while( BusyADC() ){ > result =3D ReadADC(); > =20 umm you should be waiting until the ADC stops being busy before reading it. > if(result<=3D512){ > LATBbits.LATB6 =3D 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. > =20 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .