Jump to content


Photo

Problem With Adc On Pic18


6 replies to this topic

#1 oz1lqb

oz1lqb

    Newbrie

  • EstablishedMember
  • 6 posts

Posted 25 September 2008 - 11:42 AM

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, 25 September 2008 - 03:39 PM.


#2 Reynard

Reynard

    Maniac

  • EstablishedMember
  • PipPipPipPip
  • 592 posts
  • Gender:Male
  • Location:Scotland
  • Interests:Archery - target and field

Posted 25 September 2008 - 07:36 PM

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, 25 September 2008 - 07:37 PM.


#3 oz1lqb

oz1lqb

    Newbrie

  • EstablishedMember
  • 6 posts

Posted 25 September 2008 - 07:46 PM

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

#4 Reynard

Reynard

    Maniac

  • EstablishedMember
  • PipPipPipPip
  • 592 posts
  • Gender:Male
  • Location:Scotland
  • Interests:Archery - target and field

Posted 26 September 2008 - 07:52 AM

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

#5 oz1lqb

oz1lqb

    Newbrie

  • EstablishedMember
  • 6 posts

Posted 26 September 2008 - 10:45 AM

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

#6 Dave

Dave

    Super Maniac

  • Administrators
  • PipPipPipPipPip
  • 2,067 posts
  • Gender:Male
  • Location:UK
  • Interests:How things work, Electronics, Software, Cycling.

Posted 09 November 2008 - 07:44 PM

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

#7 oz1lqb

oz1lqb

    Newbrie

  • EstablishedMember
  • 6 posts

Posted 09 November 2008 - 07:49 PM

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, 09 November 2008 - 07:54 PM.




Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users