Jump to content
oz1lqb

Problem With Adc On Pic18

Recommended Posts

Hi There..

first i am sorry my english is not the best..

i am having trouble wit this simple program.

with a pic 16f877a it works.

with a pic18f452 it compiles but returns only zero (adc_read) if i import it to oshonsoft simulator IT WORKS (maybe a problem with the simulator ?)

with pic18f4523 it will not compile (would be nice with the 12bit adc)

will not compile with pic16f886

will not compile with pic16f887

here is the program.

---------------------------------------------------------------------------

'

' commandas are:

' adc_init()

' adc_read()

'

'

 

 

 

'***************************initiating ADC port starts ************************

sub adc_init()

trisa = ( 00000001b )

trisa = ( 00000011b ) 'pin A0 is for analog input

adcon1 = ( 10001110b ) 'setting for only AN0 and ref of vss and vdd, Fosc/8

adcon0 = ( 01000001b ) 'setting for channel AN0 and Fosc/8 for 4Mhz, start AD

end sub

'***************************initiating ADC port ends **************************

 

 

 

'****************** getting the value from the ADC port starts ****************

function adc_read() as integer

adcon0.2 = 1

call delay_ms(1)

adcon0.2 = 0

call delay_ms(1)

adc_read = adresh*256

adc_read=adc_read+adresl

end function

'****************** getting the value from the ADC port ends ******************

------------------------------------------------------------------------------------------------------------------

all the best from

oz1lqb / Claus

Edited by oz1lqb

Share this post


Link to post
Share on other sites

Have you told the compiler your clock frequency ? #pragma CLOCK_FREQ so it can calculate the correct delays.

 

When you turn on the ADC module or change channel, you have to allow an aquisition time to allow the sampling capacitor to charge up to the input voltage before starting the conversion.

 

Do not do 'adcon0.2 = 0'. The flag will reset itself to zero when conversion is complete so poll for it to happen before reading the result register. Writing a 0 may abort the conversion.

 

Cheers

 

Reynard

Edited by Reynard

Share this post


Link to post
Share on other sites
Have you told the compiler your clock frequency ? #pragma CLOCK_FREQ so it can calculate the correct delays.

 

When you turn on the ADC module or change channel, you have to allow an aquisition time to allow the sampling capacitor to charge up to the input voltage before starting the conversion.

 

Do not do 'adcon0.2 = 0'. The flag will reset itself to zero when conversion is complete so poll for it to happen before reading the result register. Writing a 0 may abort the conversion.

 

Cheers

 

Reynard

----------------------------------------------------------------------------

Hi Again..

yes i use the #pragrma CLOCK_FREQ 4000000..

i just removed "adcon0.2=0"

still no change but with PIC16F452 it works in the real world but not ín the simulator

that i can live with but what realy bothers me are the pic's that simply dont want to compile at all

just spits out a long list of errors out..

Gretings from oz1lqb / Claus

Share this post


Link to post
Share on other sites

I see what you mean about do not compile.

 

It seems that the file "boostbasicpic16.bas" is missing a few chips. (Dave and Pavel take note!)

 

You can try editing the file to include the missing chips.

 

#ifdef _PIC16F887
	#include <basic\PIC16F887.bas>
#endif Rem _PIC16F887

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
I see what you mean about do not compile.

 

It seems that the file "boostbasicpic16.bas" is missing a few chips. (Dave and Pavel take note!)

 

You can try editing the file to include the missing chips.

 

#ifdef _PIC16F887
	#include <basic\PIC16F887.bas>
#endif Rem _PIC16F887

 

Cheers

 

Reynard

Hi Again..

thanks that fixed the problem with all the parts that did not compile.

both the PIC16 & PIC18 parts..

still the problem with not simulating PIC18 Parts..

i dont know if the problem is that i am using my "old" plugins with picbasic ?.

all the best oz1lqb / Claus

Share this post


Link to post
Share on other sites

oz1lqb,

still the problem with not simulating PIC18 Parts..

i dont know if the problem is that i am using my "old" plugins with picbasic ?.

all the best oz1lqb / Claus

Please check IDE user manual Appendix A: SourceBoost IDE Simulator features and limitations.

 

Regards

Dave

Share this post


Link to post
Share on other sites
oz1lqb,
still the problem with not simulating PIC18 Parts..

i dont know if the problem is that i am using my "old" plugins with picbasic ?.

all the best oz1lqb / Claus

Please check IDE user manual Appendix A: SourceBoost IDE Simulator features and limitations.

 

Regards

Dave

Hi ..

the problem with the plugins is ok i know i should buy a licence for the new plugins..

but what iretates me is the missing pic's..(those that will not compile)

i can "fix" the problem as described by another here but i think i am not the only one to have that problem..

all the best from oz1lqb / claus

Edited by oz1lqb

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×