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 not working in 16f676

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ndineshbabuece@gmail.com
Guest







ADC not working in 16f676
PostPosted: Sun Sep 14, 2008 11:40 am     Reply with quote

The ADC is not working properly in PIC16F6776.
The following is the code I have tried:
Code:
#include <16F688.h>
#fuses HS, MCLR
#DEVICE ADC=10
#use delay(clock=20000000)

int16 ch_result=0;

void main() {

SETUP_COMPARATOR(NC_NC_NC_NC);
setup_vref(FALSE);
SET_TRIS_A( 0x00 );
set_TRIS_C(0x0f);
setup_adc_ports( sAN1 | VSS_VDD);
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel(1);
delay_ms(10);

while(1)
{
ch_result=0;
ch_result=read_adc();
delay_ms(100);
ch_result&=0xfff8;

if(ch_result>=3)
{

output_high(PIN_A0);

delay_ms(100);
if(input(PIN_C0))
{
   delay_ms(1);
   if(!input(PIN_C3))
   {  delay_ms(1);
      output_high(PIN_C4);
   }
   else if(input(PIN_C3))
   {
      output_low(PIN_C4);
      output_low(PIN_C5);
      output_low(PIN_A2);
   }
}
else if(!input(PIN_C0))
{
   output_low(PIN_C4);
   output_low(PIN_C5);
   output_low(PIN_A2);
}
if(!input(PIN_C1))
{
   delay_ms(1);
   if(!input(PIN_C3))
   {
      delay_ms(1);
      output_high(PIN_C4);
      output_high(PIN_A2);
   }
   else if(input(PIN_C3))
   {
       output_low(PIN_C4);
       output_low(PIN_C5);
       output_low(PIN_A2);
   }
}
else if(input(PIN_C1))
{
   output_low(PIN_A2);
}
if(!input(PIN_C2))
{
   delay_ms(1);
   if(!input(PIN_C3))
   {
      delay_ms(1);
      output_high(PIN_C4);
      output_high(PIN_C5);
      output_high(PIN_A2);
   }
   else if(input(PIN_C3))
   {
      output_low(PIN_C4);
      output_low(PIN_C5);
      output_low(PIN_A2);
   }
}
else if(input(PIN_C2))
{
   output_low(PIN_C5);
}
}
else
{
output_low(PIN_A0);
output_low(PIN_C4);
output_low(PIN_C5);
output_low(PIN_A2);

}

 }
}

The input channel gets loaded i.e., when I apply 0.4V as input, and testing in the pin at channel, the input current draws. I don't know the reason. Can any body help ?
Ttelmah
Guest







PostPosted: Sun Sep 14, 2008 1:25 pm     Reply with quote

What chip are you actually using?.
You say '16F6776' - no such chip. If you mean 16F676, the code is being compiled for a 16F688. Needs to be corrected...
The pin you use as an ADC input, needs to be set as an input, not an output. Either set it correctly, or remove the TRIS statements (the compiler will set TRIS for you).
As a 'comment', (not causing the problem, but will cause inaccuracy problems), look in the data sheet, for what ADC clocks are legal. If this is the 676, Note 4, under table 7-1.

Best Wishes
ndineshbabuece@gmail.com
Guest







regarding PC16F676
PostPosted: Sun Sep 14, 2008 10:49 pm     Reply with quote

Ttelmah wrote:
What chip are you actually using?.
You say '16F6776' - no such chip. If you mean 16F676, the code is being compiled for a 16F688. Needs to be corrected...
The pin you use as an ADC input, needs to be set as an input, not an output. Either set it correctly, or remove the TRIS statements (the compiler will set TRIS for you).
As a 'comment', (not causing the problem, but will cause inaccuracy problems), look in the data sheet, for what ADC clocks are legal. If this is the 676, Note 4, under table 7-1.

Best Wishes


thank you sir i got the result
ndineshbabuece@gmail.com
Guest







flicker problem
PostPosted: Mon Sep 15, 2008 1:50 am     Reply with quote

Using PIC 16f676 I activate an output if the input occurs. Now I have problem when I switch on my circuit power unnecessarily the o/p goes high.
ie it flickers each time when I switch on my power.

But it does not happen when I am using PIC16F677A.

Can I know the reason ?
How can I rectify this problem ?
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