CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

adc help please

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
memoally



Joined: 25 Jan 2010
Posts: 35

View user's profile Send private message MSN Messenger

adc help please
PostPosted: Mon Jan 25, 2010 2:40 pm     Reply with quote

I am new on pics, and I have got a duty to make an analog to digital converter with a pic 18f4620 (or 18f4431) but I am really too new for this job, and I can't do it right now. Could anyone help me with codes and explanations sentences. Thank you...
_________________
compiler version: 4.105
pic: 16f876
clock frequency: 4MHz
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 25, 2010 3:02 pm     Reply with quote

See this example:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
memoally



Joined: 25 Jan 2010
Posts: 35

View user's profile Send private message MSN Messenger

PostPosted: Tue Jan 26, 2010 2:43 pm     Reply with quote

Yes you are right but I can't make it in 18f4620, today I test the code;
Code:

#include "C:\Documents and Settings\Administrator\My Documents\ccspic uygulamalar\1.h"
#include <16f877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#Define ADC=8

void main()
{
long deger;
set_tris_d(0x00);

while(1)
  {
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_port_a(ALL_ANALOG);
   set_adc_channel(0);
   delay_ms(10);
   deger=read_adc();
   output_d(deger);
  }

}

On 16f877, it is working, but I cannot implement it on 18f4620. I cannot resolve the problem. Maybe I use the wrong ports, of course I change the code for 18f4620 but I cannot take good result.
_________________
compiler version: 4.105
pic: 16f876
clock frequency: 4MHz
Guest








PostPosted: Tue Jan 26, 2010 3:38 pm     Reply with quote

memoally wrote:
Yes you are right but I can't make it in 18f4620, today I test the code;
Code:

#include "C:\Documents and Settings\Administrator\My Documents\ccspic uygulamalar\1.h"
#include <16f877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#Define ADC=8

void main()
{
long deger;
set_tris_d(0x00);

while(1)
  {
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_port_a(ALL_ANALOG);
   set_adc_channel(0);
   delay_ms(10);
   deger=read_adc();
   output_d(deger);
  }

}

On 16f877, it is working, but I cannot implement it on 18f4620. I cannot resolve the problem. Maybe I use the wrong ports, of course I change the code for 18f4620 but I cannot take good result.


Show your code for the 4620. On the 18F series I think to make the ADC eight bits the preprocessor directive is #DEVICE ADC = 8. You have #DEFINE ADC = 8 which doesn't look correct.
memoally



Joined: 25 Jan 2010
Posts: 35

View user's profile Send private message MSN Messenger

PostPosted: Wed Jan 27, 2010 11:05 am     Reply with quote

Actually, it is also 'device' for 16f877 but when changing 'define'
to 'device', CCS gives me some errors, but I can't understand them.
If I am wrong, correct me...
_________________
compiler version: 4.105
pic: 16f876
clock frequency: 4MHz
Guest








PostPosted: Wed Jan 27, 2010 2:12 pm     Reply with quote

The line
Code:

#device adc=8

should be placed immediately after your include <16F877> statement. If you put it later you will get an error something like "can't change device this far into the code".
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group