![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
opiette
Joined: 05 Mar 2007 Posts: 1
|
ADC problem with PIC12F683 |
Posted: Mon Mar 05, 2007 11:00 am |
|
|
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){
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 05, 2007 11:25 am |
|
|
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:
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|