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

Simple ADC- First timer

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



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

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

Simple ADC- First timer
PostPosted: Tue Feb 17, 2009 3:13 am     Reply with quote

I have an existing PCB board layout with an ASK receiver which has a very crude filtering system on it. While no information is sent through to the pic analogue pin AN1, the voltage tends to stay under 1V 90% of the time under under 2V for the other 10%. When information is sent through voltages are between 3V and 5V. I am new to programming an analogue pin and wish to get an integer range to represent the 0V to 5V range. With the below code i have written, i am receiving 0xff on the rs232 line while no information is sent through. Would appreciate any guidance on how to find these values !! Cheers

Code:
#include <16F716.h>
#device adc=8 //must be after #include
#include <string.h>
#fuses HS,NOWDT,NOPROTECT

#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B3, parity=N, bits=8, INVERT, ERRORS, FORCE_SW)



//#define LED PIN_B5

void main(){

   int8 value, temp, max;

   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(1);
   setup_adc_ports(ALL_ANALOG);
   max=1;
   while (TRUE){
      temp= read_adc();
      if(temp>max){
         max=temp;
      }
      putc(max);
      delay_ms(1);
   }
}
yerpa



Joined: 19 Feb 2004
Posts: 58
Location: Wisconsin

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

PostPosted: Tue Feb 17, 2009 11:43 am     Reply with quote

It looks like your code will latch up on the first 0xff byte it sees from the ADC, which would likely be noise. Since the variable "max" is never reset, the highest value stays latched in, you will never display a lower value.
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