uni_student
Joined: 01 Aug 2007 Posts: 38 Location: AUckland, NEW ZEALAND
|
Simple ADC- First timer |
Posted: Tue Feb 17, 2009 3:13 am |
|
|
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
|
|
Posted: Tue Feb 17, 2009 11:43 am |
|
|
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. |
|