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 function

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



Joined: 25 Jun 2010
Posts: 3

View user's profile Send private message

Help me!
PostPosted: Fri Jun 25, 2010 9:15 am     Reply with quote

I use 12f683 but I don't know how to use ADC function, turn off ADC and output signal to ports.
Could you please show me how to use I/O port orientation and repair my program as the following:
Code:

#include<12f683.h>
#DEVICE ADC=8
//#define sAN0
#fuses INTRC_IO, NOMCLR,NOWDT,NOPROTECT
#USE delay(internal=8M)

 int16 t,a ;

void main(){

set_tris_a(0b00000010)// all pin out except for Pin A1
setup_adc_ports(sAN1);
setup_adc(adc_clock_internal);

while (true) {
  set_adc_channel(1);
  delay_us(1);
  aq==0;  //       
  aq=read_adc();
                                 
  if (a<1500)  //if a<90 then alarm!
   {
    while(1)
      {
       output_high(PIN_A3);
       delay_ms(30);
       output_low(PIN_A3);
       delay_ms(30);
      }
   }

//////////////////////////////////////////////////////
  if (a>1500)  // neu a>1500
    {
     t==0;
     while(t<100)// loop 100 times
       {
        t++;
        output_high(PIN_A0);//pulse for A0
        delay_us(7000); //
        output_low(PIN_A0);//
        delay_us(7000);

///////////////another chanel/////////////////////////
        output_high(PIN_A2);// pulse for A2
        delay_us(7000); //
        output_low(PIN_A2);//
        delay_us(7000);
       }
    }
 }
}

I have tried to run this progam on demo Proteus and true board circuit. But there is no signal in pin A1 when a<150 and output signal in pin A0 is square is 5V, but signal in pin A0 is square is 2V when a>150.
Could you help me to find the cause of this problem?
Thanks
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Fri Jun 25, 2010 10:53 am     Reply with quote

There are a few bugs in your code. First you need to know the difference between:

a = 1 and a == 1.

That said, most devices you cannot choose AN1 as the only analog pin while leaving AN0 as digital. Check your device. Usually you have to choose AN0, or AN0 and AN1, or AN0 and AN1 and AN2, so on and so forth. In addition, a delay of 1us is insufficient in most cases to get an accurate A/D reading. Without doing the math I usually use 20us or so and that seems to work.
chungtn



Joined: 25 Jun 2010
Posts: 3

View user's profile Send private message

I don't know why AN0 coressponding to AN1?
PostPosted: Sat Jun 26, 2010 9:17 am     Reply with quote

mkuang wrote:
There are a few bugs in your code. First you need to know the difference between:

a = 1 and a == 1.

That said, most devices you cannot choose AN1 as the only analog pin while leaving AN0 as digital. Check your device. Usually you have to choose AN0, or AN0 and AN1, or AN0 and AN1 and AN2, so on and so forth. In addition, a delay of 1us is insufficient in most cases to get an accurate A/D reading. Without doing the math I usually use 20us or so and that seems to work.

I don't know why AN0 coressponding to AN1? but I repair my progam following your idea and my circuit works right.
Thankyou very much!
Yours sincerely
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