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 support@ccsinfo.com

ADC problem with PIC12F683

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



Joined: 05 Mar 2007
Posts: 1

View user's profile Send private message

ADC problem with PIC12F683
PostPosted: Mon Mar 05, 2007 11:00 am     Reply with quote

I am reading incorrect values from two ADC pins on a PIC12F683. I've tried other 683s to no avail. I had this working in the cc5x compiler, but I just bought the CCS compiler for the floating point math.

AN0 = 2.3v (470)
AN3 = 0.128v (26)

Instead, I get delays of
value1 = 616 (3v)
value2 = 200 (0.98v)

What's up?

I am using version 4.024 of CCS

Here's my code:

Code:

#include "12F683.h"
#device ADC=10
#fuses INTRC, NOBROWNOUT, NOWDT, NOPROTECT, NOMCLR
#use delay(clock=8000000)

#include "math.h"

int32 get10T(int16 value1){
   float lnratio;
   float lnratio2;
   float T;

   lnratio = ( ((float)value1 *5)/(1023*0.0005*4) ) / 2000;
   lnratio = log(lnratio);
   lnratio2 = lnratio*lnratio;

   T = 3.3540154e-3;
   T += 2.5627725e-4 * lnratio;
   T += 2.0829210e-6 * lnratio2;
   T += 7.3003206e-8 * lnratio2*lnratio;
   T = 10/T;
   
   return T;
}


void main(void){
   int16 value1;
   int16 value2;
   
   int32 T1;
   int32 T2;

   //int16 oneOverDeltaT;

   delay_ms(1000);

   //----------------------------Configure ADCs
   setup_adc_ports(sAN0 | sAN3);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_comparator( NC_NC_NC_NC );

   
   while(1){

      set_adc_channel(0);
      delay_ms(100);
      value1 = read_adc();

      //T1 = get10T(value1);

      set_adc_channel(3);
      delay_ms(100);
      value2 = read_adc();

      //T2 = get10T(value2);


      //oneOverDeltaT = 1;
      //if (T2 < T1){
      //   oneOverDeltaT = (T1-T2);
      //}
      //oneOverDeltaT = 100000/oneOverDeltaT;

      output_bit(PIN_A2, 1);
      delay_ms(value1);
      output_bit(PIN_A2, 0);
      
      delay_ms(40);
      

      output_bit(PIN_A2, 1);
      delay_ms(value2);
      output_bit(PIN_A2, 0);
      
      delay_ms(80);
      
   }//while(1){
}




PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 05, 2007 11:25 am     Reply with quote

Quote:
#include "12F683.h"
#device ADC=10
#fuses INTRC, NOBROWNOUT, NOWDT, NOPROTECT, NOMCLR
#use delay(clock=8000000)

I can see one problem immediately. You're using AN3, which is also
the CLKOUT pin for the oscillator. You need to disable the CLKOUT
function. Change the oscillator fuse to this:

Code:
INTRC_IO
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