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

12F683 ADC reading problem.

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







12F683 ADC reading problem.
PostPosted: Wed Jan 04, 2006 1:20 am     Reply with quote

i use this code but i cant read ADC,
My compiler version 3.227
i use this code at PIC16C712, and working before.

read_adc(); function is not give a result.


Code:

#include "C:\PROGRA~1\PICC\DEVICES\12F683.H"
#device ADC=8
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOPROTECT,NOCPD,NOMCLR, NOFCMEN
#use delay(clock=4000000,restart_wdt)

signed long int duty;     
unsigned long int adc_okunan;
unsigned int sonuc=0;       
unsigned int sonuc_pwm=0; 
unsigned int onceki_sonuc=0;
unsigned int mevcut_pwm=0;

void adc_sonuc()
{

   unsigned int x=0;
   unsigned int x_mod=0;
   unsigned int1 process=0;

   set_adc_channel(0);
   delay_us(100);
   adc_okunan=read_adc();

   while(adc_okunan>3)
   {
      adc_okunan-=4;
      x++;
   };

   x_mod=adc_okunan;

   if(x_mod==1 || x_mod==2) { sonuc = x;  process=1;  }
   if(x_mod==0 && onceki_sonuc==(x-1)) {sonuc = x-1;  process=1;}
   if(x_mod==3 && onceki_sonuc==(x+1)) {sonuc = x+1;  process=1;}
   if(process==0) sonuc=x;

   onceki_sonuc=sonuc;

   sonuc_pwm=sonuc*4;

}

void soft_lineer_pwm()
{
   if(sonuc_pwm>mevcut_pwm) { mevcut_pwm++;  delay_ms(7);   }
   if(sonuc_pwm<mevcut_pwm) { mevcut_pwm--;  delay_ms(5);   }
   set_pwm1_duty((unsigned long int)mevcut_pwm);
return;
}


void main()
{
   disable_interrupts(GLOBAL);
   setup_oscillator(OSC_4MHZ);
   setup_comparator(7);
 
   setup_port_a(sAN0 || sAN3 || VSS_VDD);
   setup_adc(adc_clock_internal);

   setup_ccp1(CCP_PWM);                   // CCP
   setup_timer_2(T2_DIV_BY_1, 49, 1);     // 20 kHz, 200 F.S.

   set_pwm1_duty((unsigned long int)25);
   delay_ms(2000);

while(TRUE)
{
   adc_sonuc();
   soft_lineer_pwm();
}

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 04, 2006 10:09 am     Reply with quote

Here is the comment from the 12F683.H file, which explains
how to use multiple constants in setup_adc_ports:
Quote:
// The following may be OR'ed in with the above using |


Here is how you are doing it:
Quote:
setup_port_a(sAN0 || sAN3 || VSS_VDD);


You should compile it both ways and look at the .LST file.
Notice the difference between Logical and Bitwise OR.
Guest








PostPosted: Thu Jan 05, 2006 4:01 am     Reply with quote

Thanks PCM programmer,

Thats different OR's.
I do mistake.
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