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

NO OUTPUT

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



Joined: 21 Mar 2010
Posts: 37

View user's profile Send private message Yahoo Messenger

NO OUTPUT
PostPosted: Wed May 26, 2010 9:47 pm     Reply with quote

When I use a voltage reference for the PIC16F877A adc, there is no output. what's wrong? where's the problem. I use a 100 ms delay.
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed May 26, 2010 10:30 pm     Reply with quote

More info needed.

What exactly do you mean by 'no output'? Is there no ADC conversion? Does the processor hang? And how have you come to the conclusion that there is a problem (ie, how are you tracing the problem)?

Rohit
feitanx



Joined: 21 Mar 2010
Posts: 37

View user's profile Send private message Yahoo Messenger

PostPosted: Thu May 27, 2010 12:32 am     Reply with quote

I mean I try to output the result on portd through LED but there is no output
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Thu May 27, 2010 12:35 am     Reply with quote

Do you get an output without using the reference (ie, if you do a simple ADC conversion and dump out an 8bit value to PORTD)?

Post your code.

Rohit
feitanx



Joined: 21 Mar 2010
Posts: 37

View user's profile Send private message Yahoo Messenger

PostPosted: Thu May 27, 2010 1:41 am     Reply with quote

#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOCPD,NOBROWNOUT
#device *=16 ADC=8
#use delay(clock=4000000)
#use rs232(uart1,baud=9600,xmit=PIN_C6,rcv=PIN_C7,PARITY=N,BITS=8,STOP=1)
#use STANDARD_IO(D)
#use STANDARD_IO(A)
#use STANDARD_IO(C)
#bit ADFM_BIT = 0x9F.7

void main(void){
int8 V,V1;
V=0;
setup_adc_ports(A_ANALOG_RA3_REF);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
for(V=1;V<=20;V++)
{
V+=read_adc();
delay_ms(500);
}
V1=V/20;
output_d(V1);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Thu May 27, 2010 1:57 am     Reply with quote

You do realise that you need to have a reference voltage fed 'in' to RA3?.

You then have 'V', which is your loop counter, and you add the value from the ADC to this. If the ADC value is over 20, you will drop out on the very first loop...

Then there is a problem with the addition. The adc, returns a value from 0 to 255. If this was being summed correctly, you woulod be adding these 20 values (0 to 5100 for the total), in a variable than can store 255 _max_....

You need something like:
Code:

void main(void){ //Note the use of the 'code' buttons....
   int8 ctr,V1;
   int16 total; //variable big enough to hold the total
   setup_adc_ports(A_ANALOG_RA3_REF);
   setup_adc(ADC_CLOCK_DIV_32);
   set_adc_channel(0);
   while (TRUE) {
      total=0;
      for(ctr=1;ctr<=20;ctr++) {//use variable names that reflect use...
         total+=read_adc();
         delay_ms(500);
      }
      V1=total/20;
      output_d(V1);
   } //Loop otherwise the code will only run once
}


Best Wishes
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